X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fjson%2Fjson_handler.hpp;fp=src%2Fjson%2Fjson_handler.hpp;h=95765ef820b9017f668490e76bb650c2a1fafce5;hb=b9d7e9c232a4371ddfed51c58e5a57f87b057229;hp=0000000000000000000000000000000000000000;hpb=59f84608ec15c016958a6e0e0ddd813f376c0925;p=ric-app%2Fadmin.git diff --git a/src/json/json_handler.hpp b/src/json/json_handler.hpp new file mode 100644 index 0000000..95765ef --- /dev/null +++ b/src/json/json_handler.hpp @@ -0,0 +1,150 @@ + +/* +================================================================================== + + Copyright (c) 2018-2019 AT&T Intellectual Property. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +================================================================================== +*/ +/* + Author : Ashwin Sridharan + + +*/ + +#pragma once +#ifndef JSON_HANDLER +#define JSON_HANDLER + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define MAX_QUEUE_SIZE 100 + +using namespace rapidjson; + + +struct DataContainer { + enum Types {boolean, integer, uinteger, big_integer, ubig_integer, real, str} tag ; + struct { + union { + bool b; + int i; + unsigned int ui; + long int l; + unsigned long int ul; + double f; + } ; + std::string s; + } value; +}; + +class TrieNode; + +class TrieNode{ +public: + + TrieNode (int); + TrieNode( std::string ); + + void set_type(DataContainer::Types); + int get_type(void) const {return _val.tag;} ; + + void set_value(bool val); + void set_value(int val); + void set_value(unsigned int val); + + void set_value(long int ); + void set_value(unsigned long int ); + void set_value(double val); + void set_value(const char *); + void set_value(std::string val); + void set_value(const char * , size_t ); + + void print_id(void); + void print_value(void); + void add_child(TrieNode *); + + DataContainer const * get_value(void) const { return & _val; }; + DataContainer const * get_id(void) const { return & _id;}; + + std::vector & get_children(void){ return _children;} ; + std::string & name(void) {return _name; }; + bool is_child(void){ return _children.size() ? false : true; }; + +private: + std::vector _children; + int val_type; + std::string _name; + DataContainer _id; + DataContainer _val; +}; + +class jsonHandler { + +public: + jsonHandler(void); + + + void load_schema(std::string); + void load_schema(std::string, TrieNode *root); + void load_schema(std::string , std::vector & ); + + void load_buffer(std::string); + void load_buffer(std::string, TrieNode * ); + std::string get_buffer(void); + + int get_values(const char *, int , std::string & , TrieNode *, std::vector & ); + int get_values( std::string & , TrieNode *, std::vector & ); + + int set_values (const char *, int, std::string & , std::vector); + int set_values (std::string & , std::vector); + + bool is_valid(const char *, int, std::string &); + +private: + + void load_file(std::string, std::string &); + + bool traverse_doc(Value &, TrieNode *, bool, std::string &, std::vector & ); + + bool find_member(const std::string, std::string &, std::vector &, Value & ); + + bool find_member(const std::string, std::string &, TrieNode *, Value &); + bool find_member(Value &, std::string &, TrieNode *, Value &); + + bool add_array_objects(std::queue &, Value &); + + bool _is_root, _is_schema, _is_buffer; + + std::unique_ptr _ref_schema_doc; + std::map _key_value_pairs; + std::string _contents; + std::string _buffer; + +}; + + +#endif