X-Git-Url: http://pilppa.org/gitweb/?a=blobdiff_plain;f=src%2FData.cc;h=ac7ed2d38c877416844e822030a0f0c0f649c923;hb=d7ead1c059ca51e1d71e0f3928f41733d4c7f29c;hp=d9c6e1a70eb59dc00a93f009e057e15c4fc10fd1;hpb=e3fe75505f606622b3a21cf1c4b71b7144639e06;p=lib1wire.git diff --git a/src/Data.cc b/src/Data.cc index d9c6e1a..ac7ed2d 100644 --- a/src/Data.cc +++ b/src/Data.cc @@ -5,19 +5,32 @@ * Author: lamikr */ +#include #include +#include #include #include #include -#include "Data.hh" #include +#include "Data.hh" +#include "W1Util.hh" + using namespace std; using namespace plp; using namespace w1; +template +bool string_to_number(NumberDataType& result, + const std::string& string_param, + std::ios_base& (*format)(std::ios_base&)) +{ + std::istringstream iss(string_param); + return !(iss >> format >> result).fail(); +} + Data::Data(int size) { value_arr.resize(size); } @@ -64,6 +77,37 @@ void Data::printout() { } } +Data *Data::parse_data_string(const string& dataline) { + stringstream ss(dataline); + string item; + double val; + Data *ret_val; + int ii; + bool suc_flg; + vector v; + Date date; + + ii = 0; + while(getline(ss, item, '|')) { + if (ii == 0) { + // parse date + date = W1Util::parse_date_str(item); + } + // skip the device type and device id fields + // TODO: store device type and id to own file + else if (ii >= 3) { + suc_flg = string_to_number(val, item, dec); + if (suc_flg) { + //log_debug("adding number: %f\n", val); + v.push_back(val); + } + } + ii++; + } + ret_val = new Data(v, &date); + return ret_val; +} + DataRange::DataRange(int value_count_per_data_item) { val_matrix = NULL; column_count = value_count_per_data_item;