]> pilppa.com Git - lib1wire.git/commitdiff
Use pointers in date comparison functions.
authorMika Laitio <lamikr@pilppa.org>
Thu, 6 Jan 2011 10:12:56 +0000 (12:12 +0200)
committerMika Laitio <lamikr@pilppa.org>
Thu, 6 Jan 2011 10:12:56 +0000 (12:12 +0200)
Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src/Date.cc
src/Date.hh
src/DeviceConfig.hh
src/DeviceData.cc
src/W1Store.cc

index 6e8fdb6250b3d7e101a2e760cf176349a7cc52eb..d13d6d4798443fb9fd2c93875feb531289972e7e 100644 (file)
@@ -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;
 }
index f51f28f652bce501e9859b3653e0971627141f9f..3c019995683b3f61be43b1925aa74f5a42bcd9ba 100644 (file)
@@ -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;
index cd86954dfb02826085c49cab390153ea51fccc68..0c83811457afd332b06d63917096edb355d80ef8 100644 (file)
@@ -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:
index cfb29a7b8576cc4559c13e437fe1a492bea69fbf..6b75301a4c67b609683ea4cad92bcae75a9d62af 100644 (file)
@@ -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;
index effea2e27e47df37adcb3ecd8da623444542ca59..fddf015ea2795dee3c5399b866bc5dcd27b11a3e 100644 (file)
@@ -401,7 +401,7 @@ vector<Data *> *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<Data *> *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<Data *> *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<Data *> *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]) {