Fledge
An open source edge computing platform for industrial users
value.h
1 #ifndef _VALUE_H
2 #define _VALUE_H
3 /*
4  * Fledge storage client.
5  *
6  * Copyright (c) 2018 OSisoft, LLC
7  *
8  * Released under the Apache 2.0 Licence
9  *
10  * Author: Mark Riddoch
11  */
12 #include <string>
13 #include <sstream>
14 #include <iostream>
15 
16 
20 class UpdateValue {
21  public:
22  enum UpdateType {
23  StringType,
24  IntType,
25  DoubleType,
26  JSONType };
27  UpdateValue(const std::string& column, const std::string& value) :
28  m_column(column), m_value.str(value), m_type(UpdateValue::StringType) {};
29  UpdateValue(const std::string& column, const int value) :
30  m_column(column), m_value.ival(value), m_type(UpdateValue::IntType) {};
31  UpdateValue(const std::string& column, const double value) :
32  m_column(column), m_value.fval(value), m_type(UpdateValue::DoubleType) {};
33  ~UpdateValue() {};
34  std::string toJSON()
35  {
36  std::ostringstream json;
37 
38  json << "\"" << m_column << "\" : ";
39  switch (m_type)
40  {
41  case UpdateValue::StringType:
42  json << "\"" << m_value.str << "\"";
43  break;
44  case UpdateValue::IntType:
45  json << m_value.ival;
46  break;
47  case UpdateValue::DoubleType:
48  json << m_value.fval;
49  break;
50  case UpdateValue::JSONType:
51  json << m_value.str;
52  break;
53  }
54  return json.str();
55  }
56  private:
57  const std::string m_column;
58  enum UpdateType m_type;
59  union {
60  std::string str;
61  int ival;
62  double fval;
63  } m_value;
64 };
65 #endif
66 
A value in an update statement.
Definition: value.h:20