Add new udafs and RMR support to gsprintconsole_ves
[com/gs-lite.git] / src / ftacmp / type_objects.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 __TYPE_OBJECTS_H_DEFINED__
16 #define __TYPE_OBJECTS_H_DEFINED__
17
18 #include <string>
19 #include<vector>
20
21 #include"literal_types.h"
22 #include"parse_schema.h"
23 #include"type_indicators.h"
24 #include"gstypes.h"
25 #include"vstring.h"
26
27 enum dtype {u_int_t, int_t, u_llong_t, llong_t, u_short_t, floating_t,
28                         bool_t, v_str_t, timeval_t, ip_t, ipv6_t, fstring_t, undefined_t};
29
30 enum temporal_type {increasing_t, decreasing_t, constant_t, varying_t};
31                 // varying_t means I don't know.
32         // constant_t MUST MEAN THAT ALL VALUES IN THE SE TREE ARE LITERALS!
33
34
35 class data_type{
36 private:
37   std::string schema_type;              // String representation of the data type.
38   dtype type;                                   // Internal representation of the data type.
39   std::string subtype;                          // specialization of the type.
40                                                                 // use to restrict access and provide annotation
41   temporal_type temporal;               // How does the value change over time.
42   int size;                                             // # bytes, it it can't be readily determined
43
44   void assign_schema_type();
45   void assign_type_from_string(std::string st);
46
47 public:
48   data_type(){type = undefined_t; assign_schema_type(); size=0; temporal=varying_t;};
49   data_type(std::string st);
50   data_type(std::string st, param_list *modifiers);
51   data_type(int it);
52   data_type(data_type *lhs, std::string &op);
53   data_type(data_type *lhs, data_type *rhs, const std::string &op);
54
55   static temporal_type compute_temporal_type(temporal_type l_tempo,  std::string &op);
56   static temporal_type compute_temporal_type(temporal_type l_tempo, temporal_type r_tempo,  dtype l_type, dtype r_type, const std::string &op);
57
58   data_type *duplicate();
59   field_entry *make_field_entry(std::string n);
60
61   void set_aggr_data_type(const std::string &op, data_type *dt);
62
63   int type_indicator();
64
65   dtype get_type(){return type;                                         };
66   std::string get_type_str(){return schema_type;        };
67   std::string to_string();
68
69   temporal_type get_temporal(){return temporal;         };
70   void set_temporal(temporal_type t){temporal = t;              };
71   void reset_temporal(){ if(this->is_temporal()) temporal = varying_t;};
72   bool is_temporal(){return( temporal == increasing_t || temporal == decreasing_t);};
73   bool is_increasing(){return( temporal == increasing_t );};
74   bool is_decreasing(){return( temporal == decreasing_t );};
75
76   std::string get_temporal_string();
77   std::vector<std::string> get_param_keys();
78   std::string get_param_val(std::string k);
79
80   bool is_defined(){return(type != undefined_t);        };
81
82   bool is_comparable(data_type *rhs, std::string op);
83
84   std::string get_CC_accessor_type();
85   std::string get_cvar_type();
86   std::string get_tuple_cvar_type();
87   std::string make_cvar(std::string v);
88   std::string make_tuple_cvar(std::string v);
89   std::string get_host_cvar_type();
90   std::string make_host_cvar(std::string v);
91   std::string make_host_tuple_cvar(std::string v);
92   std::string get_hfta_unpack_fcn();
93   std::string get_hfta_unpack_fcn_noxf();
94
95   bool complex_comparison(data_type *dt);
96   std::string get_comparison_fcn(data_type *dt);
97   std::string get_hfta_comparison_fcn(data_type *dt);
98   std::string get_equals_fcn(data_type *dt);
99   std::string get_hfta_equals_fcn(data_type *dt);
100
101   bool complex_operator(data_type *dt, std::string &op);
102   std::string get_complex_operator(data_type *dt, std::string &op);
103
104   bool complex_operator(std::string &op);
105   std::string get_complex_operator(std::string &op);
106
107     bool use_hashfunc();
108         std::string get_hfta_hashfunc();
109
110   bool needs_hn_translation();
111   std::string hton_translation();
112   std::string ntoh_translation();
113
114   bool is_buffer_type();
115 //              LFTA functions
116   std::string get_buffer_assign_copy();
117   std::string get_buffer_tuple_copy();
118   std::string get_buffer_replace();
119   std::string get_buffer_size();
120   std::string get_buffer_destroy();
121 //              HFTA functions
122   std::string get_hfta_buffer_assign_copy();
123   std::string get_hfta_buffer_tuple_copy();
124   std::string get_hfta_buffer_replace();
125   std::string get_hfta_buffer_size();
126   std::string get_hfta_buffer_destroy();
127   std::string get_hfta_buffer_init();
128
129   bool is_structured_type();
130 //  std::string get_interface_type();
131
132 //              These functions are obsolete
133   std::string handle_registration_name();
134   std::string hfta_handle_registration_name();
135   std::string get_handle_destructor();
136
137   bool fta_legal_type();
138   static bool fta_legal_operation(data_type *lhs, data_type *rhs, std::string &op);
139   static bool fta_legal_operation(data_type *lhs, std::string &op);
140
141 //              for schemaparser
142   int type_size();
143
144 /*
145 //              for external functions and predicates
146 bool call_compatible(data_type *o);
147
148 //              test for equality : used by bind_to_schema and by testing for
149 //              mergability.
150 bool equal(data_type *o);
151 */
152
153   bool subsumes_type(data_type *o);
154   bool equals(data_type *o);
155   bool equal_subtypes(data_type *o);
156
157 // literals corresponding to minimum and maximum values
158   std::string get_min_literal();
159   std::string get_max_literal();
160
161 //      char* to X functions
162   std::string get_wl_extract_fcn();
163
164
165 };
166
167
168 #endif