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
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 ------------------------------------------- */
15 #ifndef __TYPE_OBJECTS_H_DEFINED__
16 #define __TYPE_OBJECTS_H_DEFINED__
21 #include"literal_types.h"
22 #include"parse_schema.h"
23 #include"type_indicators.h"
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};
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!
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
44 void assign_schema_type();
45 void assign_type_from_string(std::string st);
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);
52 data_type(data_type *lhs, std::string &op);
53 data_type(data_type *lhs, data_type *rhs, const std::string &op);
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);
58 data_type *duplicate();
59 field_entry *make_field_entry(std::string n);
61 void set_aggr_data_type(const std::string &op, data_type *dt);
65 dtype get_type(){return type; };
66 std::string get_type_str(){return schema_type; };
67 std::string to_string();
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 );};
76 std::string get_temporal_string();
77 std::vector<std::string> get_param_keys();
78 std::string get_param_val(std::string k);
80 bool is_defined(){return(type != undefined_t); };
82 bool is_comparable(data_type *rhs, std::string op);
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();
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);
101 bool complex_operator(data_type *dt, std::string &op);
102 std::string get_complex_operator(data_type *dt, std::string &op);
104 bool complex_operator(std::string &op);
105 std::string get_complex_operator(std::string &op);
108 std::string get_hfta_hashfunc();
110 bool needs_hn_translation();
111 std::string hton_translation();
112 std::string ntoh_translation();
114 bool is_buffer_type();
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();
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();
129 bool is_structured_type();
130 // std::string get_interface_type();
132 // These functions are obsolete
133 std::string handle_registration_name();
134 std::string hfta_handle_registration_name();
135 std::string get_handle_destructor();
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);
145 // for external functions and predicates
146 bool call_compatible(data_type *o);
148 // test for equality : used by bind_to_schema and by testing for
150 bool equal(data_type *o);
153 bool subsumes_type(data_type *o);
154 bool equals(data_type *o);
155 bool equal_subtypes(data_type *o);
157 // literals corresponding to minimum and maximum values
158 std::string get_min_literal();
159 std::string get_max_literal();
161 // char* to X functions
162 std::string get_wl_extract_fcn();