3 ==================================================================================
5 Copyright (c) 2018-2019 AT&T Intellectual Property.
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 ==================================================================================
21 Author : Ashwin Sridharan
30 #include <rapidjson/document.h>
31 #include <rapidjson/writer.h>
32 #include <rapidjson/stringbuffer.h>
33 #include <rapidjson/schema.h>
35 #include <unordered_map>
40 #include <mdclog/mdclog.h>
44 #define MAX_QUEUE_SIZE 100
46 using namespace rapidjson;
49 struct DataContainer {
50 enum Types {boolean, integer, uinteger, big_integer, ubig_integer, real, str} tag ;
70 TrieNode( std::string );
72 void set_type(DataContainer::Types);
73 int get_type(void) const {return _val.tag;} ;
75 void set_value(bool val);
76 void set_value(int val);
77 void set_value(unsigned int val);
79 void set_value(long int );
80 void set_value(unsigned long int );
81 void set_value(double val);
82 void set_value(const char *);
83 void set_value(std::string val);
84 void set_value(const char * , size_t );
87 void print_value(void);
88 void add_child(TrieNode *);
90 DataContainer const * get_value(void) const { return & _val; };
91 DataContainer const * get_id(void) const { return & _id;};
93 std::vector<TrieNode *> & get_children(void){ return _children;} ;
94 std::string & name(void) {return _name; };
95 bool is_child(void){ return _children.size() ? false : true; };
98 std::vector<TrieNode *> _children;
111 void load_schema(std::string);
112 void load_schema(std::string, TrieNode *root);
113 void load_schema(std::string , std::vector<std::string> & );
115 void load_buffer(std::string);
116 void load_buffer(std::string, TrieNode * );
117 std::string get_buffer(void);
119 int get_values(const char *, int , std::string & , TrieNode *, std::vector<TrieNode *> & );
120 int get_values( std::string & , TrieNode *, std::vector<TrieNode *> & );
122 int set_values (const char *, int, std::string & , std::vector<TrieNode *>);
123 int set_values (std::string & , std::vector<TrieNode *>);
125 bool is_valid(const char *, int, std::string &);
129 void load_file(std::string, std::string &);
131 bool traverse_doc(Value &, TrieNode *, bool, std::string &, std::vector<TrieNode *> & );
133 bool find_member(const std::string, std::string &, std::vector<std::string> &, Value & );
135 bool find_member(const std::string, std::string &, TrieNode *, Value &);
136 bool find_member(Value &, std::string &, TrieNode *, Value &);
138 bool add_array_objects(std::queue<Value> &, Value &);
140 bool _is_root, _is_schema, _is_buffer;
142 std::unique_ptr<SchemaDocument> _ref_schema_doc;
143 std::map <std::string, DataContainer> _key_value_pairs;
144 std::string _contents;