// Task.h #ifndef dial_Task_H #define dial_Task_H // A DIAL task holds a collection of text files to be used by an application // to fill the result. The text files are carried as named Text objects. // // XML format: // // Task // id = 123-246 // owner = bill // create_time = 1234567890 // Text // name = config.dat // ... // Text // name = code.cxx // ... // ... #include #include #include #include "dataset_util/XmlElement.h" #include "dataset_util/Text.h" #include "dial_task/TaskId.h" class XmlElement; namespace dial { class Task { public: // typedefs typedef Text::Name Name; typedef time_t Time; // List of file names. typedef std::vector NameList; // List of text objects. typedef std::vector TextList; private: // data // Error status. // 0 for no error. int m_status; // Identifier. TaskId m_id; // Owner. Name m_owner; // Create time. Time m_create_time; // Files. NameList m_names; // Text objects. TextList m_texts; // Error message. mutable std::string m_emsg; // Directory. mutable std::string m_odir; public: // static functions // XML name. static const char* xml_name() { return "Task"; } // Context for UniqueId generator. static const char* id_context() { return "Task"; } // DTD. static const Text& dtd(); // ID generator. static UniqueIdGenerator& generator(); // Construct a test task. // Valid if the generator is defined. // Managed here. static const Task& test_instance(); public: // constructors, assignment and destructor // Default constructor. // Leaves object in an invalid state. Task(); // Constructor from a list of (local) file names and the // directory in which those file may be found. // Use "" or "." to reference the current working directory. // Identifier is generated automatically. // Text objects are extracted from the files. // All files must be readable. // This can be invoked with Task(Text.split("file1 file2")). Task(const NameList& names, Name dir =""); // Same a previous except the list of file names is a // space-separated string. // If names is "*", then all regular files in the directory // tree will be included. The list is sorted. Task(std::string names, Name dir =""); // Constructor from a list of named text objects. // Identifier is generated automatically. Task(const TextList& code); // Constructor from an existing task. Task(const XmlElement& ele); // Copy constructor. Task(const Task& rhs); // Assignment. Task& operator=(const Task& rhs); // Destructor. ~Task(); public: // old constructors, assignment and destructor // These will be dropped public: // other functions // Is this a valid task? bool is_valid() const; // Return the error status. // Nonzero for error. int status() const { return m_status; } // Return the identifier. TaskId id() const; // Owner. Name owner() const; // Return the create time. Time create_time() const; // Return the file names. const NameList& files() const { return m_names; } // Return the file names in a space-delimited string. std::string file_string() const; // Return if the task has a particular name. bool has(Name name) const; // Return the text objects. const TextList& texts() const { return m_texts; } // Return the text for a file. const Text& text(Name name) const; // Write the files. // dir - directory where files are to be written // "" - use the name task_abc-ijk where abc-ijk is the // task ID // create - flag indicating that the directory may not already // exist and should be created // overwrite - flag indicating that existing files may be // overwritten // Returns 0 for success. int write_files(Name dir ="", bool create =true, bool overwrite =false) const; // Show help. // Writes readme.txt to stdout. // Return 0 for success. int help() const; // Write the task to XML. // Caller is responsible for managing the returned object. // If global_id is true, then the XML is only written if the // task ID is global. const XmlElement* xml(bool global_id =true) const; // Display to cout. void display() const; // Return error message from last operation std::string error_message() const; // Return the directory where they were last written. std::string output_directory() const; // Web page. // entry: // blank to show entire task // file=xxx to show file xxx Text web_page(std::string baseurl, std::string entry) const; }; } // end namespace dial // Output stream. std::ostream& operator<<(std::ostream& lhs, const dial::Task& rhs); #endif