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
7 http://www.apache.org/licenses/LICENSE-2.0
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 ------------------------------------------- */
16 // TODO garbage collection isn't being done
17 // the json package doesn't do any GC.
21 #ifndef __SCHEMAPARSER_IMPL_INCLUDED__
22 #define __SCHEMAPARSER_IMPL_INCLUDED__
24 #include"schemaparser.h"
27 ///////////////////////////////////////
32 unsigned int reserved;
38 //////////////////////////////////////////////////////
40 // Use to load definitions from json
41 // Internally used class.
55 field_entry(){ this->init(); }
56 std::string load_from_json(mc_json::json_value *froot);
59 ////////////////////////////////////////
60 // Parsed representation from the json.
61 // Internally used class.
62 class tuple_access_info{
64 std::string field_name;
74 int init(field_entry *fe);
75 std::string to_string();
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{
85 std::vector<std::string> keys;
86 std::vector<tuple_access_info> field_info;
92 std::string init(const mc_json::json_value *strm);
95 // Return a text representation
96 std::string to_string();
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.
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);
115 // This class parses a json representation of the streams and manages them
116 class _mc_schemas : public mc_schemas{
118 std::map<std::string, _query_rep *> qreps;
119 std::map<std::string, std::string> qerrs;
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);
130 void init(const char *n);
132 // true if there are any errors.
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);