From 9a61860296f39594c2ae43b30f174281b7e5cb35 Mon Sep 17 00:00:00 2001 From: Mika Laitio Date: Thu, 6 Jan 2011 12:12:56 +0200 Subject: [PATCH] Use pointers in date comparison functions. Signed-off-by: Mika Laitio --- src/Date.cc | 32 +++++++++++++++++++------------- src/Date.hh | 4 ++-- src/DeviceConfig.hh | 2 +- src/DeviceData.cc | 12 ++++++------ src/W1Store.cc | 8 ++++---- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/Date.cc b/src/Date.cc index 6e8fdb6..d13d6d4 100644 --- a/src/Date.cc +++ b/src/Date.cc @@ -88,29 +88,35 @@ void Date::copy(Date *date) { sec = date->sec; } -bool Date::before(Date date2) { +bool Date::before(Date *date2) { bool ret_val; + string s1; + string s2; - string s1 = this->to_sortable_string(); - string s2 = date2.to_sortable_string(); ret_val = false; - if (s1.compare(s2) < 0) { - ret_val = true; + if (date2 != NULL) { + s1 = this->to_sortable_string(); + s2 = date2->to_sortable_string(); + if (s1.compare(s2) < 0) { + ret_val = true; + } } return ret_val; } -bool Date::equals(Date date2) { +bool Date::equals(Date *date2) { bool ret_val; ret_val = false; - if ((this->sec == date2.sec) && - (this->min == date2.min) && - (this->hour == date2.hour) && - (this->day == date2.day) && - (this->month == date2.month) && - (this->year == date2.year)) { - ret_val = true; + if (date2 != NULL) { + if ((this->sec == date2->sec) && + (this->min == date2->min) && + (this->hour == date2->hour) && + (this->day == date2->day) && + (this->month == date2->month) && + (this->year == date2->year)) { + ret_val = true; + } } return ret_val; } diff --git a/src/Date.hh b/src/Date.hh index f51f28f..3c01999 100644 --- a/src/Date.hh +++ b/src/Date.hh @@ -29,8 +29,8 @@ namespace plp { void inc_seconds(int seconds); Date *clone(); void copy(Date *date); - bool before(Date date2); - bool equals(Date date2); + bool before(Date *date2); + bool equals(Date *date2); int year; int month; int day; diff --git a/src/DeviceConfig.hh b/src/DeviceConfig.hh index cd86954..0c83811 100644 --- a/src/DeviceConfig.hh +++ b/src/DeviceConfig.hh @@ -23,7 +23,7 @@ extern "C" { #define DEVICE_CONFIG_VALUE_KEY__NAME "name" namespace w1 { - enum enum_summary_calculation {SUM, DELTA, MEAN, MAX, MIN}; + enum enum_summary_calculation {SUM, DELTA, MIN, MAX, MEAN}; struct ConfigHandle { public: diff --git a/src/DeviceData.cc b/src/DeviceData.cc index cfb29a7..6b75301 100644 --- a/src/DeviceData.cc +++ b/src/DeviceData.cc @@ -187,16 +187,16 @@ Data *DeviceData::get_daily_summary(Date *date, case DELTA: ret_val = store->get_delta(); break; - case MEAN: - default: - ret_val = store->get_mean(); - break; case MAX: ret_val = store->get_max(); break; case MIN: ret_val = store->get_min(); break; + case MEAN: + default: + ret_val = store->get_mean(); + break; } if (ret_val != NULL) { ret_val->printout(); @@ -231,7 +231,7 @@ DataRange *DeviceData::get_daily_summary(Date *start_date, ret_val = NULL; date = start_date->clone(); - while(date->before(*end_date)) { + while(date->before(end_date)) { data = get_daily_summary(date); if (data != NULL) { if (ret_val == NULL) { @@ -295,7 +295,7 @@ DataRange *DeviceData::get_hourly_summary(Date *start_date, ret_val = NULL; date = start_date->clone(); - while(date->before(*end_date)) { + while(date->before(end_date)) { dta_lst = get_hourly_summary(date); for(iter = dta_lst->begin(); iter != dta_lst->end(); iter++) { data = (Data *)*iter; diff --git a/src/W1Store.cc b/src/W1Store.cc index effea2e..fddf015 100644 --- a/src/W1Store.cc +++ b/src/W1Store.cc @@ -401,7 +401,7 @@ vector *W1Store::get_sum(int freq_sec) { } else { date = data->get_date(); - if (date.before(*limit_d)) { + if (date.before(limit_d)) { for (jj = 0; jj < col_count; jj++) { calc->value_arr[jj] = calc->value_arr[jj] + data->value_arr[jj]; } @@ -471,7 +471,7 @@ vector *W1Store::get_mean(int freq_sec) { } else { date = data->get_date(); - if (date.before(*limit_d)) { + if (date.before(limit_d)) { for (jj = 0; jj < col_count; jj++) { calc->value_arr[jj] = calc->value_arr[jj] + data->value_arr[jj]; } @@ -549,7 +549,7 @@ vector *W1Store::get_delta(int freq_sec) { } else { date = data->get_date(); - if (date.before(*limit_d)) { + if (date.before(limit_d)) { if (calc2 != NULL) { delete(calc2); } @@ -629,7 +629,7 @@ vector *W1Store::get_max_or_min(int freq_sec, bool max) { } else { date = data->get_date(); - if (date.before(*limit_d)) { + if (date.before(limit_d)) { if (max == true) { for (jj = 0; jj < col_count; jj++) { if (calc->value_arr[jj] < data->value_arr[jj]) { -- 2.41.1