// ApplicationSelectionCatalog.h #ifndef dset__ApplicationSelectionCatalog_H #define dset__ApplicationSelectionCatalog_H // David Adams // November 2004 // // An application selection catalog associates named attributes with // application names. Each entry in the catalog has a unique name. // The attributes include those required to record an application ID. // // This class is built on a generic selection catalog. #include #include #include #include "dataset_sql/SqlQuery.h" #include "dataset_id/UniqueId.h" #include "dataset_catalog/GenericSelectionCatalog.h" #include "dial_app/ApplicationId.h" namespace dial { class ApplicationSelectionCatalog { public: // typedefs typedef std::string Connection; typedef dset::GenericSelectionCatalog::Name Name; typedef dset::GenericSelectionCatalog::NameList NameList; typedef dset::GenericSelectionCatalog::size_type size_type; typedef dset::GenericSelectionCatalog::Attributes Attributes; typedef std::set IdList; private: // Data dset::GenericSelectionCatalog *m_pcat; private: // No copying allowed. ApplicationSelectionCatalog(const ApplicationSelectionCatalog&); // No assignment allowed. ApplicationSelectionCatalog& operator=(const ApplicationSelectionCatalog&); public: // static methods // Return the default concrete instance of this class. // First pass, use set_default_instance or // define an invalid catalog if this fails. static ApplicationSelectionCatalog& default_instance(); // Set the the default instance of this class. // Returns 0 for success. static int set_default_instance(ApplicationSelectionCatalog* pasc); // Set the the default instance of this class. // Returns 0 for success. static int set_default_instance(Connection conn = ""); // Assign an empty ASC as the default by // 1. creating an empty SQLRESULT DSC dsc.dat, // 2. appending a clause to resolver.dat and // 3. setting the latter as the connection configuration file. // This should only be used for testing. // The connection resolver is shared by all catalogs. // Returns 0 for success. static int create_default_instance(); public: // constructors and destructor // Default constructor. ApplicationSelectionCatalog(); // Constructor from a generic selectioncatalog. ApplicationSelectionCatalog(dset::GenericSelectionCatalog* pcat); // Constructor from a connection string. ApplicationSelectionCatalog(Connection conn); // Destructor. ~ApplicationSelectionCatalog(); public: // const methods // Is this a valid catalog? bool is_valid() const; // Catalog type. Name catalog_type() const { return "ApplicationSelectionCatalog"; } // Return the ID encoding. Name id_encoding() const; // Return the attribute names. NameList schema() const; // Does an application name appear in the catalog? bool has_name(Name dsname) const; // Retrieve the attributes associated with a name. Attributes attributes(Name name) const; // Return the virtual ID associated with an application name. ApplicationId id(Name name) const; // Return the number of entries in the catalog. size_type size() const; // Return the namess of the first maxent applications that match // a query. NameList query(dset::SqlQuery qry, size_type maxent =20) const; // Retrieve the number of entries that match a select query. size_type query_count(dset::SqlQuery qry) const; // Return a web page. // See GenericSelectionCatalog. Text web_page(std::string baseurl, std::string entry, std::string uidurl) const; public: // const methods // Insert a new entry in the catalog. // Error if name is already present or catalog cannot be updated. // Value for name in attribute list is overwritten. // Returns 0 for success. int insert(Name name, const Attributes& att); // Update the attributes for an existing entry. // Error if name is not present or catalog cannot be updated. // Attributes may be used to rename the application. // Error if this attributes name is already present. // Returns 0 for success. int update(Name name, const Attributes& att); // Remove an entry // Error if name is not present or entry cannot be removed. // Returns 0 for success. int remove(Name name); }; } // end dset namespace // Output stream. std::ostream& operator<<(std::ostream& lhs, const dial::ApplicationSelectionCatalog& rhs); #endif