Initial commit
[com/gs-lite.git] / src / ftacmp / schemaparser_impl.h
1 /* ------------------------------------------------
2 Copyright 2014 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 #ifndef __INTERFACE_IMPL_INCLUDED__
16 #define __INTERFACE_IMPL_INCLUDED__
17
18 #include"schemaparser.h"
19
20
21  #include"type_indicators.h"
22  #include"type_objects.h"
23  #include"parse_fta.h"
24  #include "gstypes.h"
25
26
27
28
29 //      access_result (access_fcn)(char *tuple, int offset);
30 class tuple_access_info{
31 public:
32         std::string field_name;
33         int offset;
34         data_type *pdt;
35
36
37         tuple_access_info(){
38                 pdt = NULL;
39                 offset = 0;
40         };
41
42         int init(field_entry *fe){
43                 field_name = fe->get_name();
44                 pdt = new data_type(fe->get_type());
45                 return(pdt->type_indicator());
46         };
47 };
48
49 class param_block_info{
50 public:
51         std::string param_name;
52         access_result value;
53         data_type *pdt;
54         unsigned int offset;
55         bool value_set;
56
57         param_block_info(){
58                 pdt = NULL;
59                 offset = 0;
60                 value_set = false;
61         };
62
63         int init(var_pair_t *vp){
64                 value_set = false;
65                 param_name = vp->name;
66                 pdt = new data_type(vp->val);
67                 switch(pdt->get_type()){
68                         case int_t:
69                                 value.r.i=0; break;
70                         case u_int_t:
71                         case u_short_t:
72                         case bool_t:
73                                 value.r.ui=0; break;
74                         case floating_t:
75                                 value.r.f = 0.0; break;
76                         case u_llong_t:
77                                 value.r.ul = 0; break;
78                         case llong_t:
79                                 value.r.l=0; break;
80                         case timeval_t:
81                                 value.r.t.tv_sec=0; value.r.t.tv_usec=0; break;
82                         case v_str_t:
83                                 value.r.vs.length = 0; value.r.vs.offset = 0; value.r.vs.reserved=0; break;
84                         case fstring_t:
85                                 value.r.fs.data = NULL;
86                                 value.r.fs.size = 0;
87                                 break;
88                         default:
89                                 break;
90                 }
91                 return(pdt->type_indicator());
92         };
93 };
94
95
96
97 class query_rep{
98 public:
99         std::string name;
100
101         std::vector<tuple_access_info> field_info;
102         int min_tuple_size;
103
104         std::vector<param_block_info> param_info;
105         int min_param_size;
106
107         query_rep(std::string nm, int ntuples, int nparams) :
108                 name(nm), field_info(ntuples), param_info(nparams) {
109                         min_tuple_size = 0;
110                         min_param_size = 0;
111         };
112
113         int set_field_info(int f, field_entry *fe){
114                 if(f<0 || f>=field_info.size()) return(-1);
115                 return(field_info[f].init(fe));
116         };
117
118         int finalize_field_info(){
119                 int f;
120                 int curr_pos = 0;
121                 int fld_undefined = 0;
122                 for(f=0;f<field_info.size();++f){
123                         field_info[f].offset = curr_pos;
124                         int sz = field_info[f].pdt->type_size();
125                         if(sz==0) fld_undefined = 1;
126                         curr_pos += sz;
127                 }
128                 min_tuple_size = curr_pos;
129                 if(fld_undefined) return(-1);
130                 else return(0);
131         };
132
133         int set_param_info(int p, var_pair_t *vp){
134                 if(p<0 || p>=param_info.size()) return(-1);
135                 return(param_info[p].init(vp));
136         };
137
138         int finalize_param_info(){
139                 int p;
140                 int curr_pos = 0;
141                 int fld_undefined = 0;
142                 for(p=0;p<param_info.size();++p){
143                         param_info[p].offset = curr_pos;
144                         int sz = param_info[p].pdt->type_size();
145                         if(sz==0) fld_undefined = 1;
146                         curr_pos += sz;
147                 }
148                 min_param_size = curr_pos;
149                 if(fld_undefined) return(-1);
150                 else return(0);
151         };
152
153
154 };
155
156 //                      Diagnostic tool.
157 void ftaschema_debugdump(int sch_handle);
158
159 #endif
160