manage_json.h
1 /*
2 * <one line to give the program's name and a brief idea of what it does.>
3 * Copyright (C) 2021 <copyright holder> <email>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef NAF_TOOLS_MANAGEJSON
20 #define NAF_TOOLS_MANAGEJSON
21 
22 
23 #include <istream>
24 #include <string>
25 
26 #include <Poco/JSON/JSON.h>
27 #include <Poco/JSON/JSONException.h>
28 #include <Poco/JSON/Array.h>
29 #include <Poco/JSON/Object.h>
30 #include <Poco/JSON/Parser.h>
31 #include <Poco/Dynamic/Var.h>
32 #include <Poco/Dynamic/Struct.h>
33 #include <Poco/StreamCopier.h>
34 
35 using namespace Poco;
36 
37 
38 namespace NAF
39 {
40  namespace Tools
41  {
42  class ManageJSON;
43  }
44 }
45 
46 
48 {
49  public:
50  ManageJSON();
51  ~ManageJSON();
52 
53  JSON::Array::Ptr get_json_array() const { return json_array_; }
54  JSON::Object::Ptr get_json_object() const { return json_object_; }
55  JSON::Array::Ptr& get_json_array()
56  {
57  auto& var = json_array_;
58  return var;
59  }
60  JSON::Object::Ptr& get_json_object()
61  {
62  auto& var = json_object_;
63  return var;
64  }
65 
66  void set_json_array(JSON::Array::Ptr json_array) { json_array_ = json_array; }
67  void set_json_object(JSON::Object::Ptr json_object) { json_object_ = json_object; }
68 
69  void Parse_(std::string& string_to_parse);
70  JSON::Object::Ptr ExtractObject_(Dynamic::Var& object);
71  JSON::Array::Ptr ExtractArray_(Dynamic::Var& object);
72 
73  private:
74  JSON::Array::Ptr json_array_;
75  JSON::Object::Ptr json_object_;
76 };
77 
78 #endif // NAF_TOOLS_MANAGEJSON
Definition: manage_json.h:48