Fledge
An open source edge computing platform for industrial users
expression.h
1 #ifndef _EXPRESSION_H
2 #define _EXPRESSION_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 #include <vector>
16 #include <resultset.h>
17 
18 
22 class Expression {
23  public:
24  Expression(const std::string& column, const std::string& op, int value) :
25  m_column(column), m_op(op), m_type(INT_COLUMN)
26  {
27  m_value.ival = value;
28  };
29  Expression(const std::string& column, const std::string& op, double value) :
30  m_column(column), m_op(op), m_type(NUMBER_COLUMN)
31  {
32  m_value.fval = value;
33  };
34  const std::string toJSON() const
35  {
36  std::ostringstream json;
37 
38  json << "{ \"column\" : \"" << m_column << "\", ";
39  json << "\"operator\" : \"" << m_op << "\", ";
40  json << "\"value\" : ";
41  switch (m_type)
42  {
43  case JSON_COLUMN:
44  case BOOL_COLUMN:
45  case STRING_COLUMN:
46  case NULL_COLUMN:
47  break;
48  case INT_COLUMN:
49  json << m_value.ival;
50  break;
51  case NUMBER_COLUMN:
52  json << m_value.fval;
53  break;
54  }
55  json << "}";
56  return json.str();
57  }
58  private:
59  const std::string m_column;
60  const std::string m_op;
61  ColumnType m_type;
62  union {
63  long ival;
64  double fval;
65  } m_value;
66 };
67 
68 class ExpressionValues : public std::vector<Expression>
69 {
70  public:
71  const std::string toJSON() const
72  {
73  std::ostringstream json;
74 
75  json << "[ ";
76  for (std::vector<Expression>::const_iterator it = this->cbegin();
77  it != this->cend(); ++it)
78 
79  {
80  json << it->toJSON();
81  if (it + 1 != this->cend())
82  json << ", ";
83  else
84  json << " ";
85  }
86  json << "]";
87  return json.str();
88  };
89 };
90 #endif
Class that defines data to be inserted or updated in a column within the table.
Definition: expression.h:22
Definition: expression.h:68