Fix: update the correct pre-built script to cmake-sonar.sh
[ric-app/mc.git] / schemaparser / schemaparser_impl.h
1 /* ------------------------------------------------
2 Copyright 2020 AT&T Intellectual Property
3    Licensed under the Apache License, Version 2.0 (the "License");
4    you may not use this file except in compliance with the License.
5    You may obtain a copy of the License at
6
7      http://www.apache.org/licenses/LICENSE-2.0
8
9    Unless required by applicable law or agreed to in writing, software
10    distributed under the License is distributed on an "AS IS" BASIS,
11    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12    See the License for the specific language governing permissions and
13    limitations under the License.
14  ------------------------------------------- */
15
16 //      TODO garbage collection isn't being done
17 //              the json package doesn't do any GC.
18
19
20
21 #ifndef __SCHEMAPARSER_IMPL_INCLUDED__
22 #define __SCHEMAPARSER_IMPL_INCLUDED__
23
24 #include"schemaparser.h"
25 #include "json.h"
26
27 ///////////////////////////////////////
28 //              structured types
29 struct vstring32 {
30     unsigned int length;
31     unsigned int offset;
32     unsigned int reserved;
33 };
34
35
36 namespace mc_schema{
37
38 //////////////////////////////////////////////////////
39 //              Field_entry
40 //              Use to load definitions from json
41 //              Internally used class.
42
43 class field_entry{
44 public:
45         std::string name;
46         std::string type;
47         int pos;
48         bool is_ts;
49
50         void init(){
51                 type=-1;
52                 pos=-1;
53                 is_ts = false;
54         }
55         field_entry(){ this->init(); }
56         std::string load_from_json(mc_json::json_value *froot);
57 };
58         
59 ////////////////////////////////////////
60 //              Parsed representation from the json.
61 //              Internally used class.
62 class tuple_access_info{
63 public:
64         std::string field_name;
65         int offset;
66         int pdt;
67         bool is_ts;
68
69         tuple_access_info(){
70                 pdt = UNDEFINED_TYPE;
71                 offset = 0;
72                 is_ts = 0;
73         };
74         int init(field_entry *fe);
75         std::string to_string();
76 };
77
78 ////////////////////////////////////////////
79 //              Represent the parsed schema of a query stream.
80 //              Created by mc_schema
81 //              will be returned on request from mc_schema
82 class _query_rep : public query_rep{
83 public:
84         std::string name;
85         std::vector<std::string> keys;
86         std::vector<tuple_access_info> field_info;
87         int min_tuple_size;
88
89         _query_rep() {
90                         min_tuple_size = 0;
91         };
92         std::string init(const mc_json::json_value *strm);
93         int finalize();
94
95 //              Return a text representation
96         std::string to_string();
97 //              Number of fields
98         int get_num_fields();
99 //              name of ith field (starting at zero)
100         std::string get_field_name(int i);
101 //              lookup field index by name, -1 if not found
102         int get_index_of_field(std::string name);
103 //              lookup field handle by name, -1 if not found
104         field_handle get_handle_of_field(std::string name);
105 //              data type of ith field.
106         int get_type(int i);
107 //              string representation of data type of ith field
108         std::string get_type_name(int i);
109 //              byte offset of ith field in a data block
110         int get_offset(int i);
111 //              handle of ith field in a data block
112         field_handle get_handle(int i);
113 };
114
115 //              This class parses a json representation of the streams and manages them
116 class _mc_schemas : public mc_schemas{
117 public:
118         std::map<std::string, _query_rep *> qreps;
119         std::map<std::string, std::string> qerrs;
120         std::string err;
121         char *nib_str;
122
123 //              n is a char buffer holding the json description of the stream schemas
124         _mc_schemas(const char *n);
125 //              n is a string holding the json description of the stream schemas
126         _mc_schemas(std::string s);
127
128         ~_mc_schemas();
129
130         void init(const char *n);
131
132 //              true if there are any errors.
133         bool has_errors();
134
135 //              string with the error reports.  empty if there is no error.
136         std::string get_errors();
137 //              return the names of the parsed streams.
138         std::vector<std::string> get_streams();
139 //              return the names of the unsucessfully parsed streams
140         std::vector<std::string> get_error_streams();
141 //              true if some stream was parsed successful or not
142         bool stream_found(std::string s);
143 //              true if there is a stream with name s which parsed successfully
144         bool stream_ok(std::string s);
145 //              return the error associated with a stream, if any.
146         std::string get_stream_error(std::string s);
147 //              Get the query representation of a successfully parsed stream
148         query_rep *get_query_rep(std::string s);
149
150 };      
151                 
152                 
153 }       
154
155 #endif
156