Fledge
An open source edge computing platform for industrial users
returns.h
1 #ifndef _RETURNS_H
2 #define _RETURNS_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 Returns {
21  public:
22  Returns(const std::string& column) :
23  m_column(column) {};
24  Returns(const std::string& column, const std::string& alias) :
25  m_column(column), m_alias(alias) {};
26  Returns(const std::string& column, const std::string& alias, const std::string& format) :
27  m_column(column), m_alias(alias), m_format(format) {};
28  ~Returns() {};
29  void format(const std::string format)
30  {
31  m_format = format;
32  }
33  void timezone(const std::string timezone)
34  {
35  m_timezone = timezone;
36  }
37  std::string toJSON()
38  {
39  std::ostringstream json;
40 
41  if ((! m_alias.empty()) || (! m_format.empty()) || (! m_timezone.empty()))
42  {
43  json << "{ ";
44  json << "\"column\" : \"" << m_column << "\"";
45  if (! m_alias.empty())
46  json << ", \"alias\" : \"" << m_alias << "\"";
47  if (! m_format.empty())
48  json << ", \"format\" : \"" << m_format << "\"";
49  if (! m_timezone.empty())
50  json << ", \"timezone\" : \"" << m_timezone << "\"";
51  json << " }";
52  }
53  else
54  {
55  json << "\"" << m_column << "\"";
56  }
57  return json.str();
58  }
59  private:
60  const std::string m_column;
61  const std::string m_alias;
62  std::string m_format;
63  std::string m_timezone;
64 };
65 #endif
Control a returned column.
Definition: returns.h:20