/* * TimeTable.h * * Created on: 5 août 2013 * Author: CS */ #ifndef TIMETABLE_H_ #define TIMETABLE_H_ #include #include #include #include "TimeInterval.hh" #include "ParameterDescription.hh" #include "log4cxx/logger.h" namespace TimeTableCatalog { /** * TimeTable(TT) definition. */ class TimeTable { public: /** * ISO Time format for creation date and interval dates. */ enum TIME_FORMAT { UNKNOWN = 0, YYYYMMDDThhmmssmsk = 1, YYYYMMDDThhmmss = 2 }; static const size_t YYYYMMDDThhmmssmsk_LENGTH; static const size_t YYYYMMDDThhmmss_LENGTH; TimeTable(); TimeTable(TIME_FORMAT pFormat); ~TimeTable(); /** * Creates a new time table as a union of all given time table. */ static std::unique_ptr merge( const std::vector& pTimeTableList); /** * Creates a new time table as an intersection of all given time tables. */ static std::unique_ptr intersect( const std::vector& pTimeTableList); /** * Complementary to intersect operation. */ static std::unique_ptr antiintersect( const std::vector& pTimeTableList); /** * Sorts time intervals according to their start date. */ void sort(); /** * Copies all intervals of a list of time tables into a unique time table. */ void group(const std::vector& pTimeTableList); /** * Reads a TT. */ void read(const std::string& pPath, const std::string& ptype); /** * Writes a TT. */ std::string write(const std::string& pPath, const std::string& ptype, const std::string& pName="") const; /** * Reads a time table and writes it into another format. */ void convert(const std::string& pInPath, const std::string& pInType, const std::string& pOutPath, const std::string& pName, const std::string& pOutType); /** * Unset current TT. */ void clear(); /** * Adds an interval to the TT interval list. */ void addInterval(const TimeInterval& pInterval); /** * Gets intervals from TT. */ const std::vector& getIntervals() const { return _intervals; } /** * Gets last intervals from TT. */ TimeInterval * getLastInterval() { return &_intervals.back(); } /** * Gets number of intervals in TT. */ int getIntervalNumber() const; /** * Downloads distant timetable file in tmp directory. */ static std::string download(const std::string& pPath); /** * Retrieve parameter descriptions list */ const ParameterDescriptionList& getParameterDescritptions() const { return _parameterDescritptions; } /** * Retrieve last parameter descriptions */ ParameterDescription * getLastParameterDescritption() { return &_parameterDescritptions.back(); } /** * TT metadata name. */ std::string _name; /** * TT metadata creation date. */ double _creationDate; /** * TT metadata description */ std::vector _description; /** * TT metadata history */ std::string _history; /** * TT creation date and interval dates ISO format (with or without msk) */ TIME_FORMAT _timeFormat; protected: /** * Additional parameters descriptions used by Catalog class * these descriptions are not accessible through the Time table class */ ParameterDescriptionList _parameterDescritptions; private: /** * Logger */ static log4cxx::LoggerPtr _logger; /** * Returns a merged interval list. */ static std::unique_ptr> merge( const std::vector& pTimeIntervalsList); /** * Fills an interval list with all non intersections between the two given time tables. */ static void antiintersect(const TimeTable& ptt1, const TimeTable& ptt2, std::vector& pIntersetedIntervals); /** * Fills an interval list with all intersections between the two given time tables. */ static void intersect(const TimeTable& ptt1, const TimeTable& ptt2, std::vector& pIntersetedIntervals); /** * Sorts a list of interval according to their start date. */ static void sort(std::vector& pIntervals); /** * TT intervals */ std::vector _intervals; }; std::string join(const std::vector& pvalues, const std::string& pseparator); size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream); } /* namespace TimeTableCatalog */ #endif /* TIMETABLE_H_ */