// DatasetSelectionCatalog.h #ifndef dset__DatasetSelectionCatalog_H #define dset__DatasetSelectionCatalog_H // David Adams // November 2004 // // A dataset selection catalog associates named attributes with dataset // names. Each entry in the catalog has a unique name. The attributes // include those used to record a dataset ID. // // This class is built on a generic selection catalog. #include #include #include "dataset_sql/SqlQuery.h" #include "dataset_id/DatasetId.h" #include "dataset_id/DatasetIdList.h" #include "dataset_catalog/GenericSelectionCatalog.h" namespace dset { class DatasetSelectionCatalog { public: // typedefs typedef std::string Connection; typedef GenericSelectionCatalog::Name Name; typedef GenericSelectionCatalog::NameList NameList; typedef GenericSelectionCatalog::size_type size_type; typedef GenericSelectionCatalog::Attributes Attributes; typedef DatasetIdList IdList; private: // Data GenericSelectionCatalog* m_pcat; private: // No copying allowed. DatasetSelectionCatalog(const DatasetSelectionCatalog&); // No assignment allowed. DatasetSelectionCatalog& operator=(const DatasetSelectionCatalog&); 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 DatasetSelectionCatalog& default_instance(); // Set the default instance of this class. // The class takes ownership of the argument and deletes it the // next time the default instance is changed. // Returns 0 for success. static int set_default_instance(DatasetSelectionCatalog* pdsc); // Set the default instance of this class. // The connection is used with the connection resolver to construct // a and new default catalog. // Returns 0 for success. static int set_default_instance(Connection conn =""); // Assign an empty DSC 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: // methods // Default constructor. // Produces an invalid catalog. DatasetSelectionCatalog(); // Constructor from a generic selection catalog. // Argument must have catalog type DatasetSelectionCatalog. // This class takes ownership (deletes) the input catalog. explicit DatasetSelectionCatalog(GenericSelectionCatalog* pcat); // Constructor from a catalog connection. explicit DatasetSelectionCatalog(Connection conn); // Destructor. virtual ~DatasetSelectionCatalog(); public: // const methods // Is this a valid catalog? virtual bool is_valid() const; // Catalog type: DatasetSelectionCatalog. virtual Name catalog_type() const; // Return the ID encoding. virtual Name id_encoding() const; // Return the attribute names. virtual NameList schema() const; // Does a dataset name appear in the catalog? virtual bool has_name(Name name) const; // Retrieve the attributes associated with a name. virtual Attributes attributes(Name name) const; // Return the ID associated with a dataset name. virtual DatasetId id(Name name) const; // Return the number of entries in the catalog. virtual size_type size() const; // Return the namess for the first maxent datasets that match a query. virtual NameList query(SqlQuery qry, size_type maxent =20) const; // Retrieve the number of entries that match a query. virtual size_type query_count(SqlQuery qry) const; // Return a web page. // See GenericSelectionCatalog. Text web_page(std::string baseurl, std::string entry, std::string uidurl) const; public: // non-const methods // Insert a new entry with attributes. // Error if name is already present or catalog cannot be updated. // Value for name in attribute list is overwritten. // Error if name is already present. // Returns 0 for success. virtual 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 dataset. // Error if this attribute name is already present. // Returns 0 for success. virtual 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. virtual int remove(Name name); }; } // end dset namespace // Output stream. std::ostream& operator<<(std::ostream& lhs, const dset::DatasetSelectionCatalog& rhs); #endif