From c4d8504b99fa1e354d15b2b91e4e2797f54ba028 Mon Sep 17 00:00:00 2001 From: Mika Laitio Date: Mon, 27 Dec 2010 19:21:07 +0200 Subject: [PATCH] cleanups, renamed get_*_values functions to get_*_data Signed-off-by: Mika Laitio --- src/DeviceData.cc | 69 ++++++++++++++++--------------- src/W1CounterDevice.cc | 2 +- src/W1CounterDevice.hh | 2 +- src/W1Device.cc | 12 +++--- src/W1Device.hh | 6 +-- src/W1Store.cc | 4 +- src/W1TemperatureSensor.cc | 2 +- src/W1TemperatureSensor.hh | 2 +- src_test/test_w1_datalog_write.cc | 17 ++++---- 9 files changed, 59 insertions(+), 57 deletions(-) diff --git a/src/DeviceData.cc b/src/DeviceData.cc index 13c28aa..59327ba 100644 --- a/src/DeviceData.cc +++ b/src/DeviceData.cc @@ -39,10 +39,10 @@ DeviceData::~DeviceData() { Data *DeviceData::find_oldest_data(vector year_vector) { unsigned int ii; - string year_dir; - string month_dir; - vector month_vector; - vector data_vector; + string year_dr; + string mon_dr; + vector mon_vcr; + vector d_vcr; string f_name; W1Store *store; Data *ret_val; @@ -50,17 +50,17 @@ Data *DeviceData::find_oldest_data(vector year_vector) { ret_val = NULL; if (year_vector.size() > 0) { // dirs are alphabetically sorted - year_dir = year_vector.at(0); - year_dir = W1Util::concat_paths(device_dir, year_dir); - month_vector = W1Util::get_subdirectories(year_dir); - for (ii = 0; ii < month_vector.size(); ii++) { - month_dir = month_vector.at(ii); - month_dir = W1Util::concat_paths(year_dir, month_dir); + year_dr = year_vector.at(0); + year_dr = W1Util::concat_paths(device_dir, year_dr); + mon_vcr = W1Util::get_subdirectories(year_dr); + for (ii = 0; ii < mon_vcr.size(); ii++) { + mon_dr = mon_vcr.at(ii); + mon_dr = W1Util::concat_paths(year_dr, mon_dr); // scan data files from month dir - data_vector = W1Util::get_data_files(month_dir); - if (data_vector.size() > 0) { - f_name = data_vector.at(0); - f_name = W1Util::concat_paths(month_dir, f_name); + d_vcr = W1Util::get_data_files(mon_dr); + if (d_vcr.size() > 0) { + f_name = d_vcr.at(0); + f_name = W1Util::concat_paths(mon_dr, f_name); store = new W1Store(f_name); ret_val = store->get_oldest_data(); delete(store); @@ -73,10 +73,10 @@ Data *DeviceData::find_oldest_data(vector year_vector) { Data *DeviceData::find_newest_data(vector year_vector) { int ii; - string year_dir; - string month_dir; - vector month_vector; - vector data_vector; + string year_dr; + string mon_dr; + vector mon_vcr; + vector d_vcr; string f_name; Data *ret_val; int size; @@ -86,18 +86,18 @@ Data *DeviceData::find_newest_data(vector year_vector) { size = year_vector.size(); if (size > 0) { // dirs are alphabetically sorted - year_dir = year_vector.at(size - 1); - year_dir = W1Util::concat_paths(device_dir, year_dir); - month_vector = W1Util::get_subdirectories(year_dir); - for (ii = month_vector.size() - 1; ii >= 0; ii--) { - month_dir = month_vector.at(ii); - month_dir = W1Util::concat_paths(year_dir, month_dir); + year_dr = year_vector.at(size - 1); + year_dr = W1Util::concat_paths(device_dir, year_dr); + mon_vcr = W1Util::get_subdirectories(year_dr); + for (ii = mon_vcr.size() - 1; ii >= 0; ii--) { + mon_dr = mon_vcr.at(ii); + mon_dr = W1Util::concat_paths(year_dr, mon_dr); // scan data files from month dir - data_vector = W1Util::get_data_files(month_dir); - size = data_vector.size(); + d_vcr = W1Util::get_data_files(mon_dr); + size = d_vcr.size(); if (size > 0) { - f_name = data_vector.at(size - 1); - f_name = W1Util::concat_paths(month_dir, f_name); + f_name = d_vcr.at(size - 1); + f_name = W1Util::concat_paths(mon_dr, f_name); store = new W1Store(f_name); ret_val = store->get_newest_data(); delete(store); @@ -274,17 +274,18 @@ vector DeviceData::get_hourly_summary(Date *date) { DataRange *DeviceData::get_hourly_summary(Date *start_date, Date *end_date) { - DataRange *ret_val; - vector dta_list; - Data *data; - Date *date; + DataRange *ret_val; + vector dta_list; + Data *data; + Date *date; + vector::iterator iter; ret_val = NULL; date = start_date->clone(); while(date->before(*end_date)) { dta_list = get_hourly_summary(date); - for(vector::iterator list_iter = dta_list.begin(); list_iter != dta_list.end(); list_iter++) { - data = (Data *)*list_iter; + for(iter = dta_list.begin(); iter != dta_list.end(); iter++) { + data = (Data *)*iter; if (data != NULL) { if (ret_val == NULL) { ret_val = new DataRange(*data); diff --git a/src/W1CounterDevice.cc b/src/W1CounterDevice.cc index 53c95f9..d4a20f6 100644 --- a/src/W1CounterDevice.cc +++ b/src/W1CounterDevice.cc @@ -43,7 +43,7 @@ bool W1CounterDevice::is_supported_family_code(int family_code) { return ret_val; } -string W1CounterDevice::get_raw_value() { +string W1CounterDevice::get_raw_data() { string ret_val; string value_line; int pos; diff --git a/src/W1CounterDevice.hh b/src/W1CounterDevice.hh index 837488c..c5198bd 100644 --- a/src/W1CounterDevice.hh +++ b/src/W1CounterDevice.hh @@ -17,7 +17,7 @@ namespace w1 { std::string device_id_param, dirent *direntry_param); virtual ~W1CounterDevice(); - std::string get_raw_value(); + std::string get_raw_data(); std::string get_unit(); std::string get_device_type(); protected: diff --git a/src/W1Device.cc b/src/W1Device.cc index 46e5b70..6719be7 100644 --- a/src/W1Device.cc +++ b/src/W1Device.cc @@ -68,23 +68,23 @@ string W1Device::get_time() { void W1Device::printout() { string text; - text = get_formatted_value(); + text = get_formatted_data(); cout << text << endl; } -string W1Device::get_formatted_value() { +string W1Device::get_formatted_data() { string ret_val; string val; - val = get_raw_value(); - ret_val = get_formatted_value(val); + val = get_raw_data(); + ret_val = get_formatted_data(val); return ret_val; } -string W1Device::get_formatted_value(string value) { +string W1Device::get_formatted_data(string raw_data) { string ret_val; - ret_val = get_time() + "|" + value + " " + get_unit(); + ret_val = get_time() + "|" + raw_data + " " + get_unit(); add_to_memory_cache(ret_val); return ret_val; } diff --git a/src/W1Device.hh b/src/W1Device.hh index a6902f7..73cd8f5 100644 --- a/src/W1Device.hh +++ b/src/W1Device.hh @@ -33,8 +33,8 @@ namespace w1 { std::string get_id(); std::string get_name(); void set_name(std::string name_param); - virtual std::string get_raw_value() = 0; - std::string get_formatted_value(); + virtual std::string get_raw_data() = 0; + std::string get_formatted_data(); virtual std::string get_unit() = 0; virtual std::string get_device_type() = 0; std::string get_time(); @@ -42,7 +42,7 @@ namespace w1 { virtual void store(); protected: void add_to_memory_cache(std::string formatted_data); - std::string get_formatted_value(std::string value); + std::string get_formatted_data(std::string raw_data); virtual bool is_supported_family_code(int family_code) = 0; int family_code; std::string id; diff --git a/src/W1Store.cc b/src/W1Store.cc index 9913d0d..09ff706 100644 --- a/src/W1Store.cc +++ b/src/W1Store.cc @@ -74,8 +74,8 @@ string W1Store::get_file_name(string device_id, Date *date_time) { return ret_val; } -void W1Store::store(std::string device_id, - std::list *string_list) { +void W1Store::store(string device_id, + list *string_list) { string f_path; string line; ofstream *ostream; diff --git a/src/W1TemperatureSensor.cc b/src/W1TemperatureSensor.cc index b02bb29..9c282b3 100644 --- a/src/W1TemperatureSensor.cc +++ b/src/W1TemperatureSensor.cc @@ -75,7 +75,7 @@ bool W1TemperatureSensor::is_supported_family_code(int family_code) { return ret_val; } -string W1TemperatureSensor::get_raw_value() { +string W1TemperatureSensor::get_raw_data() { string temp; string ret_val; string last_line; diff --git a/src/W1TemperatureSensor.hh b/src/W1TemperatureSensor.hh index 6946c5c..a637222 100644 --- a/src/W1TemperatureSensor.hh +++ b/src/W1TemperatureSensor.hh @@ -17,7 +17,7 @@ namespace w1 { std::string device_id_param, dirent *direntry_param); virtual ~W1TemperatureSensor(); - std::string get_raw_value(); + std::string get_raw_data(); std::string get_unit(); std::string get_device_type(); protected: diff --git a/src_test/test_w1_datalog_write.cc b/src_test/test_w1_datalog_write.cc index d0cd8e9..88d4c5f 100644 --- a/src_test/test_w1_datalog_write.cc +++ b/src_test/test_w1_datalog_write.cc @@ -43,12 +43,13 @@ bool try_parse_long(const char *str, long *result) { } int main(int argc, char** argv) { - list device_list; - int round; - long scan_interval; - long store_interval; - string loc; - W1Device *device; + list device_list; + int round; + long scan_interval; + long store_interval; + string loc; + W1Device *device; + list::iterator iter; // default values than can be overwritten with parameters loc = "/tmp/w1data"; @@ -74,8 +75,8 @@ int main(int argc, char** argv) { if (device_list.size() > 0) { while(1) { round++; - for(list::iterator list_iter = device_list.begin(); list_iter != device_list.end(); list_iter++) { - device = (W1Device *)*list_iter; + for(iter = device_list.begin(); iter != device_list.end(); iter++) { + device = (W1Device *)*iter; device->printout(); sleep(1); if (round >= store_interval) { -- 2.41.1