Fledge
An open source edge computing platform for industrial users
json_properties.h
1 #ifndef _JSON_PROPERTIES_H
2 #define _JSON_PROPERTIES_H
3 /*
4  * Fledge storage client.
5  *
6  * Copyright (c) 2018 Dianomic Systems
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 
17 class JSONProperty {
18  public:
19  JSONProperty(const std::string& column, std::vector<std::string> path, const std::string& value) :
20  m_column(column), m_value(value)
21  {
22  for (std::vector<std::string>::const_iterator it = path.cbegin();
23  it != path.cend(); ++it)
24  m_path.push_back(*it);
25  }
26 
27  const std::string toJSON() const
28  {
29  std::ostringstream json;
30 
31  json << "{ \"column\" : \"" << m_column << "\",";
32  json << " \"path\" : [";
33  for (std::vector<std::string>::const_iterator it = m_path.cbegin();
34  it != m_path.cend(); ++it)
35  {
36  json << "\"" << *it << "\"";
37  if ((it + 1) != m_path.cend())
38  json << ",";
39  }
40  json << "],";
41  json << "\"value\" : \"" << m_value << "\" }";
42  return json.str();
43  }
44  private:
45  const std::string m_column;
46  const std::string m_value;
47  std::vector<std::string> m_path;
48 };
49 
53 class JSONProperties : public std::vector<JSONProperty>
54 {
55  public:
56  const std::string toJSON() const
57  {
58  std::ostringstream json;
59 
60  json << "\"json_properties\" : [ ";
61  for (std::vector<JSONProperty>::const_iterator it = this->cbegin();
62  it != this->cend(); ++it)
63 
64  {
65  json << it->toJSON();
66  if (it + 1 != this->cend())
67  json << ", ";
68  else
69  json << " ";
70  }
71  json << "]";
72  return json.str();
73  };
74 };
75 #endif
76 
Class that defines JSON properties for update.
Definition: json_properties.h:53
Definition: json_properties.h:17