Initial commit
[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
99   bool complex_operator(data_type *dt, std::string &op);
100   std::string get_complex_operator(data_type *dt, std::string &op);
101
102   bool complex_operator(std::string &op);
103   std::string get_complex_operator(std::string &op);
104
105     bool use_hashfunc();
106         std::string get_hfta_hashfunc();
107
108   bool needs_hn_translation();
109   std::string hton_translation();
110   std::string ntoh_translation();
111
112   bool is_buffer_type();
113 //              LFTA functions
114   std::string get_buffer_assign_copy();
115   std::string get_buffer_tuple_copy();
116   std::string get_buffer_replace();
117   std::string get_buffer_size();
118   std::string get_buffer_destroy();
119 //              HFTA functions
120   std::string get_hfta_buffer_assign_copy();
121   std::string get_hfta_buffer_tuple_copy();
122   std::string get_hfta_buffer_replace();
123   std::string get_hfta_buffer_size();
124   std::string get_hfta_buffer_destroy();
125
126   bool is_structured_type();
127 //  std::string get_interface_type();
128
129 //              These functions are obsolete
130   std::string handle_registration_name();
131   std::string hfta_handle_registration_name();
132   std::string get_handle_destructor();
133
134   bool fta_legal_type();
135   static bool fta_legal_operation(data_type *lhs, data_type *rhs, std::string &op);
136   static bool fta_legal_operation(data_type *lhs, std::string &op);
137
138 //              for schemaparser
139   int type_size();
140
141 /*
142 //              for external functions and predicates
143 bool call_compatible(data_type *o);
144
145 //              test for equality : used by bind_to_schema and by testing for
146 //              mergability.
147 bool equal(data_type *o);
148 */
149
150   bool subsumes_type(data_type *o);
151   bool equals(data_type *o);
152   bool equal_subtypes(data_type *o);
153
154 // literals corresponding to minimum and maximum values
155   std::string get_min_literal();
156   std::string get_max_literal();
157
158
159 };
160
161
162 #endif