// FileGenericRepository.h #ifndef FileGenericRepository_H #define FileGenericRepository_H // Vinay Sambamurthy // July 2004 // // Simple implementation of a GenericRepository which uses simple // XML files as the persistence mechanism for dataset objects. // // The connection string for a FileGenericRepository is // FILE: // GenericRepository::create(...) can be used to access an existing // file repository. // // There is no commiting or possibility of rescinding changes. // Objects are written to disk when a write command is received. // // The DatasetRepository class does the caching. // Errors 9 to 16 signify that the repository is invalid. #include "dataset_catalog/GenericRepository.h" #include "dataset_util/Text.h" #include #include #include namespace dset { class FileGenericRepository : public dset::GenericRepository { public: // typedefs // Name for a repository type. typedef std::string Type; // List of type names. typedef std::vector TypeList; private: // data // Type of repository Type m_rtype; // Directory where the files reside. std::string m_dir; // Flag indicating filename. Type m_type; // Dataset DTD. Text m_dtd; // Error code. mutable int m_error; public: // static functions // Return the list of known repository types. static const TypeList& types(); // Return if a type is valid. static bool is_valid_type(Type type); public: // member functions // Constructor. // rtype = type of repository, e.g. DatasetRepository // dir = directory where the repository is located // create = flag indicating that repository should be created if it does // not exist // type = type of database: // "flat" for files stored directly in directory // "id_path" for files stored at path from UniqueId // "default" for default: existing value or id_path FileGenericRepository(Type rtype, std::string dir, bool create = false, Type type = "default"); // Destructor. ~FileGenericRepository(); public: // Const member functions. // Is this a valid repository? bool is_valid() const; // Error. int error() const; // Error string. std::string error_string(int ecode) const; // Return the type of repository. // Returns an empty string on error. Type repository_type() const; // Return the repository type. Type type() const; // Is the object stored in repository? // Returns true if object is present. bool has(std::string id) const; // Retrieve an object from repository. // Returns an empty string if invalid object. std::string get(std::string id) const; // Retrieve the time an entry was made. time_t time(std::string sid) const; // Get all the number of entries in the repository. size_type size() const; // Return the number of entries made since a given time (inclusive). size_type size_since(time_t time) const; // Get all the IDs in the repository. IdList get_ids(size_type maxent =100) const; // Get all the IDs in the repository since a given time. IdList get_ids_since(time_t time, size_t =100) const; // Output stream. std::ostream& ostr(std::ostream& str) const; public: // Non-const member functions. // Write a new object to repository. // Returns 0 on success. int insert(std::string id, std::string element) const; // Delete an object from repository. // Returns 0 on success. int remove(std::string id) const; }; } // end namespace dset // Output stream. std::ostream& operator<<(std::ostream& lhs, const dset::FileGenericRepository& rhs); #endif