/* * Store.hh * * Created on: Oct 31, 2010 * Author: lamikr */ #ifndef W1STORE_HH_ #define W1STORE_HH_ #include #include #include #include #include "Data.hh" #include "Date.hh" #include "Store.hh" namespace plp { class StoreDay: public plp::Store { public: StoreDay(std::string device_id_param, plp::Date *date_time_param); StoreDay(std::string file_name_param); virtual ~StoreDay(); static void save(std::string device_id, std::list *data_list, int dec_precision); plp::DataRange *get_sum(EnumSummaryPeriod period_type_param); plp::DataRange *get_mean(EnumSummaryPeriod period_type_param); plp::DataRange *get_delta(EnumSummaryPeriod period_type_param); plp::DataRange *get_max(EnumSummaryPeriod period_type_param); plp::DataRange *get_min(EnumSummaryPeriod period_type_param); plp::Data *get_oldest_data(); plp::Data *get_latest_data(); plp::DataRange *get_oldest_and_latest_data(); /* * Checks whether store file exist. */ bool exist(bool writable); static bool exist(std::string dev_id, plp::Date *date, bool writable); static bool exist_in_month(string device_id, Date *date, bool writable); static bool exist_in_year(string device_id, Date *date, bool writable); static bool get_next_date_with_data(std::string device_id, plp::Date *next_date, plp::Date *max_date); protected: std::string store_fname; bool load(); plp::DataRange *get_max_or_min(EnumSummaryPeriod period_type_param, bool max); static std::string get_dir_name(std::string device_id, plp::Date *date_time_param); static std::string get_year_dir_name(std::string device_id, plp::Date *date_time_param); static std::string get_file_name(std::string device_id, plp::Date *date_time_param); plp::DataRange *get_oldest_and_latest_data(std::string fname_param); /** * Check whether the given file exist and has either read or write permissions. */ static bool exist(std::string fname_param, bool writable); /** * Go through days in month to find out whether daily data file exist. * * If data is not found, false is returned and last scanned date is set to next_date. * If data is found true is returned and date is set to next_date. */ static bool data_day_scan_days_in_month(string dev_id_param, Date *next_date, Date *max_date); /** * Go through month dir in year to find out first date with data * after the given date. * * If data is not found, false is returned and last scanned date is set to next_date. * If data is found true is returned and date is set to next_date. */ static bool data_day_scan_month_in_year(string dev_id_param, Date *next_date, Date *max_date); /** * Go through year and month directories to find out first date with data * after the given date. * * If data is not found, false is returned and last scanned date is set to next_date. * If data is found true is returned and date is set to next_date. */ static bool data_day_scan_years(string dev_id_param, Date *next_date, Date *max_date); }; } #endif /* W1STORE_HH_ */