FACT++  1.0
State.cc
Go to the documentation of this file.
1 // **************************************************************************
18 // **************************************************************************
19 #include "State.h"
20 
21 #include <sstream>
22 #include <algorithm>
23 
24 #include "tools.h"
25 
26 using namespace std;
27 using namespace Tools;
28 
29 // --------------------------------------------------------------------------
30 //
41 //
42 State::State(int i, const std::string &n, const std::string &c, const Time &t)
43  : index(i), name(Trim(n)), comment(Trim(c)), time(t)
44 {
45 }
46 
47 // --------------------------------------------------------------------------
48 //
57 //
58 vector<State> State::SplitStates(const string &buffer)
59 {
60  vector<State> vec;
61 
62  string buf;
63  stringstream stream(buffer);
64  while (getline(stream, buf, '\n'))
65  {
66  if (buf.empty())
67  continue;
68 
69  const size_t p1 = buf.find_first_of(':');
70  const size_t p2 = buf.find_first_of('=');
71 
72  stringstream s(buf.substr(0, p1));
73 
74  int index;
75  s >> index;
76 
77  const string name = buf.substr(p1+1, p2-p1-1);
78  const string comment = p2==string::npos ? "" : buf.substr(p2+1);
79 
80  vec.emplace_back(index, name, comment);
81  }
82 
83  sort(vec.begin(), vec.end(), State::Compare);
84 
85  return vec;
86 }
std::string comment
Name (e.g. &#39;Connected&#39;)
Definition: State.h:13
int i
Definition: db_dim_client.c:21
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
STL namespace.
int index
Definition: State.h:11
static bool Compare(const State &i, const State &j)
Definition: State.h:18
Definition: tools.h:8
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
Definition: smartfact.txt:92
State(int i=-256, const std::string &n="", const std::string &c="", const Time &t=Time(Time::none))
Definition: State.cc:42
int buffer[BUFFSIZE]
Definition: db_dim_client.c:14
TT t
Definition: test_client.c:26
std::string name
Index (e.g. 1)
Definition: State.h:12
std::string Trim(const std::string &str)
Definition: tools.cc:68
static std::vector< State > SplitStates(const std::string &buffer)
Time of state change.
Definition: State.cc:58