/* * TimeTableCatalogFactory.hh * * Created on: 8 août 2013 * Author: CS */ #ifndef TIMETABLECATALOGFACTORY_HH_ #define TIMETABLECATALOGFACTORY_HH_ #include "AbstractReader.hh" #include "AbstractWriter.hh" #include #include #include #include namespace TimeTableCatalog { class TimeTableCatalogFactory { public: virtual ~TimeTableCatalogFactory(); /** * Gets singleton instance. */ static TimeTableCatalogFactory& getInstance() { std::call_once(_onceFlag, [] { _instance.reset(new TimeTableCatalogFactory); }); return *_instance.get(); } /** * Adds a possible tt reader. */ static void registerReader(const std::string& pKey, AbstractReader* pReader); /** * Adds a possible tt writer. */ static void registerWriter(const std::string& pKey, AbstractWriter* pWriter); /** * Automatically detects a tt type. */ std::string getReaderType(const std::string& pPath); /** * Checks a reader exists for this type. */ bool canRead(const std::string& pType) const; /** * Creates a reader of a given type. */ std::unique_ptr createReader(const std::string& pKey, const std::string& pPath) const; /** * Creates a writer of a given type. */ std::unique_ptr createWriter(const std::string& pKey, const std::string& pPath, const std::string& pName = "") const; /** * Map of registered tt readers. */ static std::map _readers; /** * Map of registered tt writers. */ static std::map _writers; private: TimeTableCatalogFactory(); /** * Singleton unique instance */ static std::unique_ptr _instance; /** * Flag to guarantee singleton unicity. */ static std::once_flag _onceFlag; }; } /* namespace TimeTableCatalog */ #endif /* TIMETABLECATALOGFACTORY_HH_ */