// Application.h #ifndef dial_Application_H #define dial_Application_H // David Adams // August 2002 // Updated 2003 for new application definition. // Updated 2005 for new application definition. // // A DIAL application holds a list of text files holding the // scripts used in processing. // // XML representation: // // Application // id = "123-456" // owner = "bill" // create_time = 1234567890 // Text // name = build_task // ... // Text // name = run // ... #include #include #include #include #include "dataset_util/Text.h" #include "dial_app/ApplicationId.h" class XmlElement; namespace dial { class Application { public: // typedefs typedef std::string Name; typedef std::vector NameList; typedef std::vector TextList; typedef time_t Time; public: // static functions // XML name. static const char* xml_name() { return "Application"; } // Context for UniqueId generator. static const char* id_context() { return "Application"; } // Return the DTD. static const Text& dtd(); // ID generator. static UniqueIdGenerator& generator(); // Construct a test application. // Valid if the generator is defined. // Managed here. static const Application& test_instance(); private: // data // Error status. // 0 for no error. int m_status; // Identifier. ApplicationId m_id; // Owner. Name m_owner; // Create time. Time m_create_time; // Files. NameList m_names; // Text objects. // For now require build_task and run. TextList m_texts; // Error message. mutable std::string m_emsg; // Directory. mutable std::string m_odir; public: // Constructors and destructors. // Default constructor. // Application is invalid. Application(); // Constructor from a list of (local) file names and the name of the // directory in which those files may be found. // Directory name "" or "." refers to current directory. // Identifier is generated automatically. // Text objects are extracted from the files. // All files must be readable. // This can be invoked with Application(Text.split("file1 file2")). Application(const NameList& names, Name dir =""); // Same as previous except names are provide in a space-separated // string. // If names is "*", then all regular files in the directory // tree will be included. The list is sorted. Application(std::string snames, Name dir =""); // Constructor from a list of named text objects. // Identifier is generated automatically. Application(const TextList& scrs); // XML constructor. explicit Application(const XmlElement& ele); public: // const functions // Validity. bool is_valid() const; // Return the error status. // Nonzero for error. int status() const { return m_status; } // Return the identifier. ApplicationId 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 application has a file 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 app_abc-ijk where abc-ijk is the // application ID // "." for the current directory // 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 to XML. // If argument is true, ID must be global. const XmlElement* xml(bool global_id =true) const; // Display. 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 application // 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::Application& rhs); #endif