Added quantiling UDAFs
[com/gs-lite.git] / src / ftacmp / type_objects.cc
1 /* ------------------------------------------------\r
2 Copyright 2014 AT&T Intellectual Property\r
3    Licensed under the Apache License, Version 2.0 (the "License");\r
4    you may not use this file except in compliance with the License.\r
5    You may obtain a copy of the License at\r
6 \r
7      http://www.apache.org/licenses/LICENSE-2.0\r
8 \r
9    Unless required by applicable law or agreed to in writing, software\r
10    distributed under the License is distributed on an "AS IS" BASIS,\r
11    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12    See the License for the specific language governing permissions and\r
13    limitations under the License.\r
14  ------------------------------------------- */\r
15 \r
16 #include"type_objects.h"\r
17 \r
18 #include <stdio.h>\r
19 \r
20 using namespace std;\r
21 \r
22 void data_type::assign_schema_type(){\r
23         char tmps[100];\r
24         switch(type){\r
25         case bool_t:\r
26                 schema_type = "BOOL";\r
27                 break;\r
28         case u_short_t:\r
29                 schema_type = "USHORT";\r
30                 break;\r
31         case u_int_t:\r
32                 schema_type = "UINT";\r
33                 break;\r
34         case int_t:\r
35                 schema_type = "INT";\r
36                 break;\r
37         case u_llong_t:\r
38                 schema_type = "ULLONG";\r
39                 break;\r
40         case llong_t:\r
41                 schema_type = "LLONG";\r
42                 break;\r
43         case floating_t:\r
44                 schema_type = "FLOAT";\r
45                 break;\r
46         case v_str_t:\r
47                 schema_type = "V_STR";\r
48                 break;\r
49         case timeval_t:\r
50                 schema_type = "TIMEVAL";\r
51                 break;\r
52         case ip_t:\r
53                 schema_type = "IP";\r
54                 break;\r
55         case ipv6_t:\r
56                 schema_type = "IPV6";\r
57                 break;\r
58         case fstring_t:\r
59                 sprintf(tmps,"FSTRING%d",size);\r
60                 schema_type = tmps;\r
61                 break;\r
62         default:\r
63                 schema_type = "UNDEFINED_TYPE";\r
64                 break;\r
65         }\r
66 }\r
67 \r
68 \r
69 data_type::data_type(string st){\r
70         size=0;\r
71         temporal = varying_t;\r
72         subtype = "";\r
73         assign_type_from_string(st);\r
74 }\r
75 \r
76 \r
77 //              Assign data type of a colref using information about\r
78 //              modifiers as well as data type.  This should be made robust.\r
79 data_type::data_type(string st, param_list *modifiers){\r
80         size=0;\r
81         temporal = varying_t;\r
82         subtype="";\r
83         assign_type_from_string(st);\r
84 \r
85     if(modifiers != NULL){\r
86                 int i;\r
87                 for(i=0;i<modifiers->size();i++){\r
88                         if(     modifiers->contains_key("increasing") ||\r
89                                 modifiers->contains_key("Increasing") ||\r
90                                 modifiers->contains_key("INCREASING")){\r
91                                         temporal = increasing_t;\r
92                         }\r
93                         if(     modifiers->contains_key("decreasing") ||\r
94                                 modifiers->contains_key("Decreasing") ||\r
95                                 modifiers->contains_key("DECREASING")){\r
96                                         temporal = decreasing_t;\r
97                         }\r
98                         if(modifiers->contains_key("subtype")){\r
99                                 subtype = modifiers->val_of("subtype");\r
100                         }\r
101                 }\r
102         }\r
103 }\r
104 \r
105 \r
106 void data_type::assign_type_from_string(string st){\r
107         if(st == "bool" || st == "Bool" || st == "BOOL"){\r
108                 type = bool_t;\r
109                 assign_schema_type();\r
110                 return;\r
111         }\r
112         if(st == "ushort" || st == "Ushort" || st == "USHORT"){\r
113                 type = u_short_t;\r
114                 assign_schema_type();\r
115                 return;\r
116         }\r
117         if(st == "uint" || st == "Uint" || st == "UINT"){\r
118                 type = u_int_t;\r
119                 assign_schema_type();\r
120                 return;\r
121         }\r
122         if(st == "int" || st == "Int" || st == "INT"){\r
123                 type = int_t;\r
124                 assign_schema_type();\r
125                 return;\r
126         }\r
127         if(st == "ullong" || st == "Ullong" || st == "ULLONG"){\r
128                 type = u_llong_t;\r
129                 assign_schema_type();\r
130                 return;\r
131         }\r
132         if(st == "llong" || st == "llong" || st == "LLONG"){\r
133                 type = llong_t;\r
134                 assign_schema_type();\r
135                 return;\r
136         }\r
137         if(st == "float" || st == "Float" || st == "FLOAT"){\r
138                 type = floating_t;\r
139                 assign_schema_type();\r
140                 return;\r
141         }\r
142         if(st == "string" || st == "String" || st == "STRING" ||\r
143                 st == "v_str" || st == "V_str" || st == "V_STR"){\r
144                 type = v_str_t;\r
145                 assign_schema_type();\r
146                 return;\r
147         }\r
148         if(st == "timeval" || st == "Timeval" || st == "TIMEVAL"){\r
149                 type = timeval_t;\r
150                 assign_schema_type();\r
151                 return;\r
152         }\r
153         if(st == "IP"){\r
154                 type = ip_t;\r
155                 assign_schema_type();\r
156                 return;\r
157         }\r
158         if(st == "IPV6" || st == "IPv6"){\r
159                 type = ipv6_t;\r
160                 assign_schema_type();\r
161                 return;\r
162         }\r
163         if(sscanf(st.c_str(),"fstring%d",&size)>0){\r
164                 type = fstring_t;\r
165                 assign_schema_type();\r
166                 return;\r
167         }\r
168         if(sscanf(st.c_str(),"Fstring%d",&size)>0){\r
169                 type = fstring_t;\r
170                 assign_schema_type();\r
171                 return;\r
172         }\r
173         if(sscanf(st.c_str(),"FSTRING%d",&size)>0){\r
174                 type = fstring_t;\r
175                 assign_schema_type();\r
176                 return;\r
177         }\r
178 \r
179         type = undefined_t;\r
180         assign_schema_type();\r
181 }\r
182 \r
183 \r
184 data_type::data_type(data_type *lhs, string &op){\r
185 \r
186 //  type = undefined_t;\r
187 //  temporal_type l_tempo = lhs->get_temporal();;\r
188 //  if(l_tempo == constant_t) temporal = constant_t;\r
189 //  else temporal = varying_t;\r
190         size=0;\r
191         temporal = compute_temporal_type(lhs->get_temporal(),op);\r
192 \r
193   if(op == "-"){\r
194         switch(lhs->get_type()){\r
195         case int_t:\r
196                 type = int_t;\r
197                 break;\r
198         case u_int_t:\r
199         case u_short_t:\r
200                 type = int_t;\r
201 //              if(l_tempo == increasing_t) temporal = decreasing_t;\r
202 //              if(l_tempo == decreasing_t) temporal = increasing_t;\r
203                 break;\r
204         case u_llong_t:\r
205         case llong_t:\r
206                 type = llong_t;\r
207 //              if(l_tempo == increasing_t) temporal = decreasing_t;\r
208 //              if(l_tempo == decreasing_t) temporal = increasing_t;\r
209                 break;\r
210         case floating_t:\r
211                 type = floating_t;\r
212 //              if(l_tempo == increasing_t) temporal = decreasing_t;\r
213 //              if(l_tempo == decreasing_t) temporal = increasing_t;\r
214                 break;\r
215         default:\r
216                 break;\r
217         }\r
218   }\r
219 \r
220   if(op == "!"){\r
221         switch(lhs->get_type()){\r
222         case int_t:\r
223         case u_int_t:\r
224         case u_short_t:\r
225         case u_llong_t:\r
226         case llong_t:\r
227         case bool_t:\r
228         case ip_t:\r
229                 type = lhs->get_type();\r
230                 break;\r
231         default:\r
232                 break;\r
233         }\r
234   }\r
235 \r
236   if(op == "~"){\r
237         switch(lhs->get_type()){\r
238         case int_t:\r
239         case u_int_t:\r
240         case u_short_t:\r
241         case u_llong_t:\r
242         case llong_t:\r
243         case ip_t:\r
244                 type = lhs->get_type();\r
245                 break;\r
246         default:\r
247                 break;\r
248         }\r
249   }\r
250 \r
251   subtype = lhs->subtype;\r
252   assign_schema_type();\r
253 }\r
254 \r
255 temporal_type data_type::compute_temporal_type(temporal_type l_tempo, string &op){\r
256         temporal_type ret;\r
257 \r
258   if(l_tempo == constant_t) ret = constant_t;\r
259   else ret = varying_t;\r
260 \r
261   if(op == "-"){\r
262         if(l_tempo == increasing_t) ret = decreasing_t;\r
263         else if(l_tempo == decreasing_t) ret = increasing_t;\r
264   }\r
265   return ret;\r
266 \r
267 }\r
268 \r
269 data_type::data_type(data_type *lhs, data_type *rhs, const string &op){\r
270         size=0;\r
271 \r
272   type = undefined_t;\r
273   dtype l_type = lhs->get_type();\r
274   dtype r_type = rhs->get_type();\r
275 \r
276 //              First, deduce the type of the result.\r
277   if( (op=="-")||(op=="+")||(op=="/")||(op=="*")||(op=="%")||(op==">>")||(op=="<<") ){\r
278         switch(lhs->get_type()){\r
279         case u_short_t:\r
280                 switch(rhs->get_type()){\r
281                 case u_short_t:\r
282                 case u_int_t:\r
283                 case int_t:\r
284                         type = rhs->get_type();\r
285                         break;\r
286                 case llong_t:\r
287                 case u_llong_t:\r
288                         if(op != ">>" && op != "<<")\r
289                                 type = rhs->get_type();\r
290                         break;\r
291                 case floating_t:\r
292                         if(op != "%" && op != ">>" && op != "<<")\r
293                                 type = floating_t;\r
294                         break;\r
295                 case timeval_t:\r
296                         if(op == "+") type = timeval_t;\r
297                         break;\r
298                 default:\r
299                         break;\r
300                 }\r
301                 break;\r
302         case u_int_t:\r
303                 switch(rhs->get_type()){\r
304                 case u_short_t:\r
305                 case int_t:\r
306                 case u_int_t:\r
307                         type = u_int_t;\r
308                         break;\r
309                 case llong_t:\r
310                 case u_llong_t:\r
311                         if(op != ">>" && op != "<<")\r
312                                 type = rhs->get_type();\r
313                         break;\r
314                 case floating_t:\r
315                         if(op != "%" && op != ">>" && op != "<<")\r
316                                 type = floating_t;\r
317                         break;\r
318                 case timeval_t:\r
319                         if(op == "+") type = timeval_t;\r
320                         break;\r
321                 default:\r
322                         break;\r
323                 }\r
324                 break;\r
325         case int_t:\r
326                 switch(rhs->get_type()){\r
327                 case int_t:\r
328                 case u_short_t:\r
329                         type = int_t;\r
330                         break;\r
331                 case u_int_t:\r
332                         type = rhs->get_type();\r
333                         break;\r
334                 case llong_t:\r
335                 case u_llong_t:\r
336                         if(op != ">>" && op != "<<")\r
337                                 type = rhs->get_type();\r
338                         break;\r
339                 case floating_t:\r
340                         if(op != "%" && op != ">>" && op != "<<")\r
341                                 type = floating_t;\r
342                         break;\r
343                 case timeval_t:\r
344                         if(op == "+") type = timeval_t;\r
345                         break;\r
346                 default:\r
347                         break;\r
348                 }\r
349                 break;\r
350         case llong_t:\r
351                 switch(rhs->get_type()){\r
352                 case int_t:\r
353                 case u_int_t:\r
354                 case u_short_t:\r
355                         type = llong_t;\r
356                         break;\r
357                 case llong_t:\r
358                         if(op != ">>" && op != "<<")\r
359                                 type = llong_t;\r
360                         break;\r
361                 case u_llong_t:\r
362                         if(op != ">>" && op != "<<")\r
363                                 type = u_llong_t;\r
364                         break;\r
365                 case floating_t:\r
366                         if(op != "%" && op != ">>" && op != "<<")\r
367                                 type = floating_t;\r
368                         break;\r
369                 default:\r
370                         break;\r
371                 }\r
372                 break;\r
373         case u_llong_t:\r
374                 switch(rhs->get_type()){\r
375                 case int_t:\r
376                 case u_int_t:\r
377                 case u_short_t:\r
378                         type = u_llong_t;\r
379                         break;\r
380                 case u_llong_t:\r
381                 case llong_t:\r
382                         if(op != ">>" && op != "<<")\r
383                                 type = u_llong_t;\r
384                         break;\r
385                 case floating_t:\r
386                         if(op != "%" && op != ">>" && op != "<<")\r
387                                 type = floating_t;\r
388                         break;\r
389                 default:\r
390                         break;\r
391                 }\r
392                 break;\r
393         case floating_t:\r
394           if(op != "%" && op != ">>" && op != "<<"){\r
395                 switch(rhs->get_type()){\r
396                 case int_t:\r
397                 case floating_t:\r
398                 case u_int_t:\r
399                 case u_short_t:\r
400                 case llong_t:\r
401                 case u_llong_t:\r
402                         type = floating_t;\r
403                         break;\r
404                 default:\r
405                         break;\r
406                 }\r
407           }\r
408           break;\r
409 \r
410         case timeval_t:\r
411                 switch(rhs->get_type()){\r
412                 case int_t:\r
413                 case u_int_t:\r
414                 case u_short_t:\r
415                         if(op == "+" || op == "-" || op == "/"){\r
416                                 type = timeval_t;\r
417                         }\r
418                         break;\r
419                 case timeval_t:\r
420                         if(op == "-"){\r
421                                 type = int_t;\r
422                         }\r
423                         break;\r
424                 default:\r
425                         break;\r
426                 }\r
427         default:\r
428                 break;\r
429 \r
430         }\r
431   }\r
432 \r
433   if( (op == "|") || (op == "&") ){\r
434         switch(lhs->get_type()){\r
435         case u_short_t:\r
436                 switch(rhs->get_type()){\r
437                 case u_short_t:\r
438                 case u_int_t:\r
439                 case int_t:\r
440                 case llong_t:\r
441                 case u_llong_t:\r
442                         type = rhs->get_type();\r
443                         break;\r
444                 case bool_t:\r
445                         type = bool_t;\r
446                         break;\r
447                 default:\r
448                         break;\r
449                 }\r
450                 break;\r
451         case u_int_t:\r
452                 switch(rhs->get_type()){\r
453                 case u_short_t:\r
454                 case u_int_t:\r
455                 case int_t:\r
456                         type = u_int_t;\r
457                         break;\r
458                 case llong_t:\r
459                 case u_llong_t:\r
460                         type = rhs->get_type();\r
461                         break;\r
462                 case bool_t:\r
463                         type = bool_t;\r
464                         break;\r
465                         case ip_t:\r
466                                 type = ip_t;\r
467                                 break;\r
468                 default:\r
469                         break;\r
470                 }\r
471                 break;\r
472         case int_t:\r
473                 switch(rhs->get_type()){\r
474                 case int_t:\r
475                 case u_short_t:\r
476                         type = int_t;\r
477                         break;\r
478                 case bool_t:\r
479                         type = bool_t;\r
480                         break;\r
481                 case u_int_t:\r
482                 case llong_t:\r
483                 case u_llong_t:\r
484                         type = rhs->get_type();\r
485                         break;\r
486                         case ip_t:\r
487                                 type = ip_t;\r
488                                 break;\r
489                 default:\r
490                         break;\r
491                 }\r
492                 break;\r
493         case llong_t:\r
494                 switch(rhs->get_type()){\r
495                 case int_t:\r
496                 case u_int_t:\r
497                 case u_short_t:\r
498                 case llong_t:\r
499                         type = llong_t;\r
500                         break;\r
501                 case u_llong_t:\r
502                         type = rhs->get_type();\r
503                         break;\r
504                 case bool_t:\r
505                         type = bool_t;\r
506                         break;\r
507                 default:\r
508                         break;\r
509                 }\r
510                 break;\r
511         case u_llong_t:\r
512                 switch(rhs->get_type()){\r
513                 case int_t:\r
514                 case u_int_t:\r
515                 case u_short_t:\r
516                 case llong_t:\r
517                 case u_llong_t:\r
518                         type = u_llong_t;\r
519                         break;\r
520                 case bool_t:\r
521                         type = bool_t;\r
522                         break;\r
523                 default:\r
524                         break;\r
525                 }\r
526                 break;\r
527         case bool_t:\r
528                 switch(rhs->get_type()){\r
529                 case int_t:\r
530                 case u_int_t:\r
531                 case u_short_t:\r
532                 case llong_t:\r
533                 case u_llong_t:\r
534                 case bool_t:\r
535                         type = bool_t;\r
536                         break;\r
537                 default:\r
538                         break;\r
539                 }\r
540                 break;\r
541                 case ip_t:\r
542                         switch(rhs->get_type()){\r
543                         case int_t:\r
544                         case u_int_t:\r
545                         case ip_t:\r
546                                 type = ip_t;\r
547                                 break;\r
548                         default:\r
549                                 break;\r
550                         }\r
551                         break;\r
552                 case ipv6_t:\r
553                         if(rhs->get_type() == ipv6_t)\r
554                                 type = ipv6_t;\r
555                         break;\r
556                 default:\r
557                         break;\r
558                 }\r
559         }\r
560         assign_schema_type();\r
561         temporal = compute_temporal_type(lhs->get_temporal(),rhs->get_temporal(),lhs->get_type(), rhs->get_type(), op);\r
562         if(lhs->subtype == rhs->subtype){\r
563                 subtype = lhs->subtype;\r
564         }else{\r
565                 subtype = "";\r
566         }\r
567 }\r
568 \r
569 \r
570 temporal_type data_type::compute_temporal_type(temporal_type l_tempo, temporal_type r_tempo, dtype l_type, dtype r_type, const string &op){\r
571         temporal_type ret;\r
572 \r
573 //                      Next, deduce the temporalness of the result.\r
574 //                      One complication : if the value of the RHS or LHS is\r
575 //                      negative, we can't deduce anything about the temporality\r
576 //                      of the result.\r
577   ret = varying_t;\r
578 //  temporal_type l_tempo = lhs->get_temporal();\r
579 //  temporal_type r_tempo = rhs->get_temporal();\r
580 //  dtype l_type = lhs->get_type();\r
581 //  dtype r_type = rhs->get_type();\r
582 \r
583   if(op == "+"){\r
584         if(l_tempo == constant_t) ret = r_tempo;\r
585         if(r_tempo == constant_t) ret = l_tempo;\r
586         if(l_tempo == r_tempo) ret = r_tempo;\r
587   }\r
588   if(op == "-"){\r
589         if(l_tempo == constant_t && r_tempo == constant_t) ret = constant_t;\r
590         if((l_tempo == constant_t || l_tempo ==decreasing_t) &&\r
591                      r_tempo == increasing_t &&\r
592                         (r_type != int_t && r_type != floating_t) ) ret = decreasing_t;\r
593         if((l_tempo == constant_t || l_tempo ==increasing_t) &&\r
594                          r_tempo == decreasing_t &&\r
595                         (r_type != int_t && r_type != floating_t) ) ret = increasing_t;\r
596   }\r
597 \r
598 //              If the value might be negative, can't deduce anything\r
599 //                      However Java doesn't have unsigned types so the logic which forbids int has to be relaxed.\r
600   if(op == "*"){\r
601 //      if((l_type!=int_t && l_type!=floating_t && l_type!=llong_t) && (r_type!=int_t && r_type!=floating_t && r_type!=llong_t)){\r
602         if(!((l_type==int_t || l_type==floating_t || l_type==llong_t) && (r_type==int_t || r_type==floating_t || r_type==llong_t))){\r
603                 if(l_tempo == constant_t) ret = r_tempo;\r
604                 if(r_tempo == constant_t) ret = l_tempo;\r
605                 if(l_tempo == r_tempo) ret = r_tempo;\r
606          }\r
607   }\r
608   if(op == "/"){\r
609 //      if((l_type!=int_t && l_type!=floating_t && l_type!=llong_t) && (r_type!=int_t && r_type!=floating_t && r_type!=llong_t)){\r
610         if(!((l_type==int_t || l_type==floating_t || l_type==llong_t) && (r_type==int_t || r_type==floating_t || r_type==llong_t))){\r
611                 if((l_tempo == constant_t || l_tempo ==decreasing_t) &&\r
612                                  (r_tempo == increasing_t)) ret = decreasing_t;\r
613                 if((l_tempo == constant_t || l_tempo ==increasing_t) &&\r
614                                  (r_tempo == decreasing_t )) ret = increasing_t;\r
615                 if(r_tempo == constant_t) ret = l_tempo;\r
616         }\r
617   }\r
618 \r
619   return(ret);\r
620 \r
621 }\r
622 \r
623 \r
624 data_type *data_type::duplicate(){\r
625     data_type *ret = new data_type();\r
626     ret->schema_type = schema_type;\r
627         ret->size = size;\r
628     ret->type = type;\r
629     ret->temporal = temporal;\r
630         ret->subtype = subtype;\r
631 \r
632     return(ret);\r
633 }\r
634 \r
635 field_entry *data_type::make_field_entry(string n){\r
636         field_entry *fe = new field_entry(n, schema_type);\r
637     if(temporal == increasing_t)\r
638         fe->add_modifier("INCREASING");\r
639     if(temporal == decreasing_t)\r
640         fe->add_modifier("DECREASING");\r
641         if(subtype != "") fe->add_modifier("subtype",subtype.c_str());\r
642         return fe;\r
643 }\r
644 \r
645 bool data_type::fta_legal_operation(\r
646                         data_type *lhs, data_type *rhs, string &op){\r
647 \r
648   dtype l_type = lhs->get_type();\r
649   dtype r_type = rhs->get_type();\r
650 \r
651 \r
652 //              Currently, anything goes.  Should be controlled by\r
653 //              a config file.\r
654 \r
655         return(true);\r
656 \r
657 //      Only +, -, *, /, |, & are legal in the fta.\r
658 //      The only ops on a llong or ullong are +, -\r
659 //      no ops on float, timeval permitted, but these\r
660 //      are illegal data types in the FTA and are handled elsewhere.\r
661 \r
662   if(!( (op == "-") || (op == "+") || (op == "/") || (op == "*")  || (op == "|") || (op == "&")))\r
663         return(false);\r
664 \r
665   if( (l_type == llong_t) || (l_type == u_llong_t) || (r_type == llong_t) || (r_type == u_llong_t)){\r
666       if(op == "*" || op == "/")\r
667           return(false);\r
668   }\r
669 \r
670   return(true);\r
671 \r
672 }\r
673 \r
674 \r
675 bool data_type::fta_legal_operation(data_type *lhs, string &op){\r
676 \r
677 \r
678 //      negation and not are as legal at the fta on all fta-legal types\r
679 //      as at the user level.\r
680     return(true);\r
681 }\r
682 \r
683 bool data_type::fta_legal_type(){\r
684 \r
685 //                      Currently, anything goes.\r
686 //                      Should control by a config file.\r
687 //      Currently, only the float and the timeval are not legal at the fta.\r
688 //    if(type == floating_t || type == timeval_t) return(false);\r
689 \r
690     return(true);\r
691 }\r
692 \r
693 \r
694 //              The data type of a literal\r
695 \r
696 data_type::data_type(int it){\r
697         temporal = constant_t;\r
698         subtype = "";\r
699     switch(it){\r
700         case LITERAL_INT:\r
701                 type = u_int_t;\r
702                 break;\r
703         case LITERAL_LONGINT:\r
704                 type = u_llong_t;\r
705                 break;\r
706         case LITERAL_FLOAT:\r
707                 type = floating_t;\r
708                 break;\r
709         case LITERAL_STRING:\r
710                 type = v_str_t;\r
711                 break;\r
712         case LITERAL_BOOL:\r
713                 type = bool_t;\r
714                 break;\r
715         case LITERAL_TIMEVAL:\r
716                 type = timeval_t;\r
717                 break;\r
718         case LITERAL_IP:\r
719                 type = ip_t;\r
720                 break;\r
721         case LITERAL_IPV6:\r
722                 type = ipv6_t;\r
723                 break;\r
724         default:\r
725                 type = undefined_t;\r
726                 break;\r
727         }\r
728 \r
729         assign_schema_type();\r
730 }\r
731 \r
732 void data_type::set_aggr_data_type(const string &op, data_type *dt){\r
733         dtype se_type = dt->type;\r
734         type = undefined_t;\r
735         temporal = varying_t;\r
736 \r
737     if(op == "AVG"){\r
738         if((se_type == u_int_t)||(se_type == u_short_t)||(se_type == int_t)||\r
739             (se_type == u_llong_t)||(se_type == llong_t)||(se_type == floating_t))\r
740             type = floating_t;\r
741     }\r
742 \r
743 \r
744         if(op == "SUM"){\r
745                 if((se_type == u_int_t) || (se_type == u_short_t) || (se_type == bool_t))\r
746                         type = u_int_t;\r
747                 if((se_type == int_t) || (se_type == u_llong_t) ||\r
748                           (se_type == llong_t) || (se_type == floating_t) )\r
749                         type = se_type;\r
750 //              temporal = dt->temporal;        // temporal not preserved by sum.\r
751                 subtype = dt->subtype;\r
752         }\r
753         if(op == "MIN" || op == "MAX"){\r
754                 type = se_type;\r
755 //              temporal = dt->temporal;        // temporal not preserved by min or max.\r
756                 subtype = dt->subtype;\r
757         }\r
758         if(op == "AND_AGGR" || op == "OR_AGGR" || op == "XOR_AGGR"){\r
759                 if( (se_type == u_int_t) || (se_type == u_short_t) ||\r
760                         (se_type == int_t) || (se_type == llong_t) ||\r
761                         (se_type == u_llong_t) || (se_type == bool_t) )\r
762                                 type = se_type;\r
763                 subtype = dt->subtype;\r
764         }\r
765   assign_schema_type();\r
766 }\r
767 \r
768 \r
769 \r
770 \r
771 bool data_type::is_comparable(data_type *rhs, string op){\r
772 \r
773         switch(type){\r
774         case u_short_t:\r
775         case int_t:\r
776         case u_int_t:\r
777         case u_llong_t:\r
778         case llong_t:\r
779         case floating_t:\r
780         case ip_t:\r
781                 switch(rhs->type){\r
782                 case int_t:\r
783                 case floating_t:\r
784                 case u_short_t:\r
785                 case u_int_t:\r
786                 case u_llong_t:\r
787                 case llong_t:\r
788                 case ip_t:\r
789                         return(true);\r
790                 default:\r
791                         return(false);\r
792                 }\r
793 \r
794         case v_str_t:\r
795                 switch(rhs->type){\r
796                 case v_str_t:\r
797                         return(true);\r
798                 default:\r
799                         return(false);\r
800                 }\r
801 \r
802         case bool_t:\r
803                 switch(rhs->type){\r
804                 case bool_t:\r
805                         return(true);\r
806                 default:\r
807                         return(false);\r
808                 }\r
809         case timeval_t:\r
810                 switch(rhs->type){\r
811                 case timeval_t:\r
812                         return(true);\r
813                 default:\r
814                         return(false);\r
815                 }\r
816         case ipv6_t:\r
817                 if(rhs->type == ipv6_t)\r
818                         return true;\r
819                 else\r
820                         return false;\r
821         default:\r
822                 return(false);\r
823         }\r
824 \r
825         return(false);\r
826 }\r
827 \r
828 \r
829 //                      type string to get val from pass-by-ref fcn.\r
830 //                      (Does not seem to be used ?)\r
831 string data_type::get_CC_accessor_type(){\r
832         switch(type){\r
833         case int_t:\r
834                 return("gs_int32_t *");\r
835         case bool_t:\r
836         case u_short_t:\r
837         case u_int_t:\r
838         case ip_t:\r
839                 return("gs_uint32_t *");\r
840         case u_llong_t:\r
841                 return("gs_uint64_t *");\r
842         case llong_t:\r
843                 return("gs_int64_t *");\r
844         case floating_t:\r
845                 return("gs_float_t *");\r
846         case v_str_t:\r
847                 return("struct gs_string *");\r
848         case fstring_t:\r
849                 return("gs_int8_t *");\r
850         case timeval_t:\r
851                 return("struct timeval *");\r
852         case ipv6_t:\r
853                 return("struct ipv6_str *");\r
854         default:\r
855                 return("ERROR: Unknown type in data_type::get_CC_accessor_type\n");\r
856         }\r
857 }\r
858 \r
859 //              type of a variable holding this value.\r
860 string data_type::get_cvar_type(){\r
861         char tmps[100];\r
862         switch(type){\r
863         case int_t:\r
864                 return("gs_int32_t ");\r
865         case u_int_t:\r
866         case u_short_t:\r
867         case bool_t:\r
868         case ip_t:\r
869                 return("gs_uint32_t ");\r
870         case u_llong_t:\r
871                 return("gs_uint64_t ");\r
872         case llong_t:\r
873                 return("gs_int64_t ");\r
874         case floating_t:\r
875                 return("gs_float_t ");\r
876         case v_str_t:\r
877                 return("struct gs_string");\r
878         case ipv6_t:\r
879                 return("struct ipv6_str");\r
880         case fstring_t:\r
881                 sprintf(tmps,"gs_int8_t[%d] ",size);\r
882                 return(tmps);\r
883         case timeval_t:\r
884                 return("struct timeval ");\r
885         default:\r
886                 return("ERROR: Unknown type in data_type::get_cvar_type\n");\r
887         }\r
888 }\r
889 \r
890 //              type of a variable holding this value.\r
891 string data_type::get_tuple_cvar_type(){\r
892         char tmps[100];\r
893         switch(type){\r
894         case int_t:\r
895                 return("gs_int32_t ");\r
896         case u_int_t:\r
897         case u_short_t:\r
898         case bool_t:\r
899         case ip_t:\r
900                 return("gs_uint32_t ");\r
901         case u_llong_t:\r
902                 return("gs_uint64_t ");\r
903         case llong_t:\r
904                 return("gs_int64_t ");\r
905         case floating_t:\r
906                 return("gs_float_t ");\r
907         case v_str_t:\r
908                 return("struct string32");\r
909         case ipv6_t:\r
910                 return("struct ipv6_str");\r
911         case fstring_t:\r
912                 sprintf(tmps,"gs_int8_t[%d] ",size);\r
913                 return(tmps);\r
914         case timeval_t:\r
915                 return("struct timeval ");\r
916         default:\r
917                 return("ERROR: Unknown type in data_type::get_cvar_type\n");\r
918         }\r
919 }\r
920 \r
921 \r
922 \r
923 //              type of an in-memory variable holding this value.\r
924 //              TODO: use get_cvar_type as a subroutine\r
925 string data_type::make_cvar(std::string v){\r
926         char tmps[100];\r
927         switch(type){\r
928         case int_t:\r
929                 return("gs_int32_t "+v);\r
930         case u_int_t:\r
931         case u_short_t:\r
932         case bool_t:\r
933         case ip_t:\r
934                 return("gs_uint32_t "+v);\r
935         case u_llong_t:\r
936                 return("gs_uint64_t "+v);\r
937         case llong_t:\r
938                 return("gs_int64_t "+v);\r
939         case floating_t:\r
940                 return("gs_float_t "+v);\r
941         case v_str_t:\r
942                 return("struct gs_string "+v);\r
943         case ipv6_t:\r
944                 return("struct ipv6_str "+v);\r
945         case fstring_t:\r
946                 sprintf(tmps,"gs_int8_t %s[%d] ",v.c_str(),size);\r
947                 return(tmps);\r
948         case timeval_t:\r
949                 return("struct timeval "+v);\r
950         default:\r
951                 return("ERROR: Unknown type in data_type::make_cvar\n");\r
952         }\r
953 }\r
954 \r
955 //              type of a tuple variable holding this value.\r
956 //              TODO: use get_tuple_cvar_type as a subroutine\r
957 string data_type::make_tuple_cvar(std::string v){\r
958         char tmps[100];\r
959         switch(type){\r
960         case int_t:\r
961                 return("gs_int32_t "+v);\r
962         case u_int_t:\r
963         case u_short_t:\r
964         case bool_t:\r
965         case ip_t:\r
966                 return("gs_uint32_t "+v);\r
967         case u_llong_t:\r
968                 return("gs_uint64_t "+v);\r
969         case llong_t:\r
970                 return("gs_int64_t "+v);\r
971         case floating_t:\r
972                 return("gs_float_t "+v);\r
973         case v_str_t:\r
974                 return("struct string32 "+v);\r
975         case ipv6_t:\r
976                 return("struct ipv6_str "+v);\r
977         case fstring_t:\r
978                 sprintf(tmps,"gs_int8_t %s[%d] ",v.c_str(),size);\r
979                 return(tmps);\r
980         case timeval_t:\r
981                 return("struct timeval "+v);\r
982         default:\r
983                 return("ERROR: Unknown type in data_type::make_cvar\n");\r
984         }\r
985 }\r
986 \r
987 \r
988 //              type of a variable holding this value.\r
989 //              The type at the host might be different (esp. string vs. vstring)\r
990 string data_type::get_host_cvar_type(){\r
991         char tmps[100];\r
992         switch(type){\r
993         case int_t:\r
994                 return("gs_int32_t ");\r
995         case u_int_t:\r
996         case u_short_t:\r
997         case bool_t:\r
998         case ip_t:\r
999                 return("gs_uint32_t ");\r
1000         case u_llong_t:\r
1001                 return("gs_uint64_t ");\r
1002         case llong_t:\r
1003                 return("gs_int64_t ");\r
1004         case floating_t:\r
1005                 return("gs_float_t ");\r
1006         case v_str_t:\r
1007                 return("struct vstring");\r
1008         case ipv6_t:\r
1009                 return("struct hfta_ipv6_str");\r
1010         case fstring_t:\r
1011                 sprintf(tmps,"gs_int8_t[%d] ",size);\r
1012                 return(tmps);\r
1013         case timeval_t:\r
1014                 return("struct timeval ");\r
1015         default:\r
1016                 return("ERROR: Unknown type in data_type::get_host_cvar_type\n");\r
1017         }\r
1018 }\r
1019 \r
1020 \r
1021 //              type of a variable holding this value.\r
1022 //              The type at the host might be different (esp. string vs. vstring)\r
1023 string data_type::make_host_cvar(std::string v){\r
1024         char tmps[100];\r
1025         switch(type){\r
1026         case int_t:\r
1027                 return("gs_int32_t "+v);\r
1028         case u_int_t:\r
1029         case u_short_t:\r
1030         case bool_t:\r
1031         case ip_t:\r
1032                 return("gs_uint32_t "+v);\r
1033         case u_llong_t:\r
1034                 return("gs_uint64_t "+v);\r
1035         case llong_t:\r
1036                 return("gs_int64_t "+v);\r
1037         case floating_t:\r
1038                 return("gs_float_t "+v);\r
1039         case v_str_t:\r
1040                 return("struct vstring "+v);\r
1041         case ipv6_t:\r
1042                 return("struct hfta_ipv6_str "+v);\r
1043         case fstring_t:\r
1044                 sprintf(tmps,"gs_int8_t %s[%d] ",v.c_str(),size);\r
1045                 return(tmps);\r
1046         case timeval_t:\r
1047                 return("struct timeval "+v);\r
1048         default:\r
1049                 return("ERROR: Unknown type in data_type::make_host_cvar\n");\r
1050         }\r
1051 }\r
1052 \r
1053 string data_type::make_host_tuple_cvar(std::string v){\r
1054         char tmps[100];\r
1055         switch(type){\r
1056         case int_t:\r
1057                 return("gs_int32_t "+v);\r
1058         case u_int_t:\r
1059         case u_short_t:\r
1060         case bool_t:\r
1061         case ip_t:\r
1062                 return("gs_uint32_t "+v);\r
1063         case u_llong_t:\r
1064                 return("gs_uint64_t "+v);\r
1065         case llong_t:\r
1066                 return("gs_int64_t "+v);\r
1067         case floating_t:\r
1068                 return("gs_float_t "+v);\r
1069         case v_str_t:\r
1070                 return("struct vstring32 "+v);\r
1071         case ipv6_t:\r
1072                 return("struct hfta_ipv6_str "+v);\r
1073         case fstring_t:\r
1074                 sprintf(tmps,"gs_int8_t %s[%d] ",v.c_str(),size);\r
1075                 return(tmps);\r
1076         case timeval_t:\r
1077                 return("struct timeval "+v);\r
1078         default:\r
1079                 return("ERROR: Unknown type in data_type::make_host_cvar\n");\r
1080         }\r
1081 }\r
1082 \r
1083 \r
1084 \r
1085 string data_type::get_hfta_unpack_fcn(){\r
1086         switch(type){\r
1087         case int_t:\r
1088                 return("fta_unpack_int");\r
1089         case u_int_t:\r
1090         case ip_t:\r
1091                 return("fta_unpack_uint");\r
1092         case u_short_t:\r
1093                 return("fta_unpack_ushort");\r
1094         case bool_t:\r
1095                 return("fta_unpack_bool");\r
1096         case u_llong_t:\r
1097                 return("fta_unpack_ullong");\r
1098         case llong_t:\r
1099                 return("fta_unpack_llong");\r
1100         case floating_t:\r
1101                 return("fta_unpack_float");\r
1102         case v_str_t:\r
1103                 return("fta_unpack_vstr");\r
1104         case fstring_t:\r
1105                 return("fta_unpack_fstring");\r
1106         case timeval_t:\r
1107                 return("fta_unpack_timeval");\r
1108         case ipv6_t:\r
1109                 return("fta_unpack_ipv6");\r
1110         default:\r
1111                 return("ERROR: Unknown type in dtype::get_hfta_unpack_fcn\n");\r
1112         }\r
1113 }\r
1114 \r
1115 string data_type::get_hfta_unpack_fcn_noxf(){\r
1116         switch(type){\r
1117         case int_t:\r
1118                 return("fta_unpack_int_noxf");\r
1119         case u_int_t:\r
1120         case ip_t:\r
1121                 return("fta_unpack_uint_noxf");\r
1122         case u_short_t:\r
1123                 return("fta_unpack_ushort_noxf");\r
1124         case bool_t:\r
1125                 return("fta_unpack_bool_noxf");\r
1126         case u_llong_t:\r
1127                 return("fta_unpack_ullong_noxf");\r
1128         case llong_t:\r
1129                 return("fta_unpack_llong_noxf");\r
1130         case floating_t:\r
1131                 return("fta_unpack_float_noxf");\r
1132         case v_str_t:\r
1133                 return("fta_unpack_vstr_noxf");\r
1134         case fstring_t:\r
1135                 return("fta_unpack_fstring_noxf");\r
1136         case timeval_t:\r
1137                 return("fta_unpack_timeval_noxf");\r
1138         case ipv6_t:\r
1139                 return("fta_unpack_ipv6_noxf");\r
1140         default:\r
1141                 return("ERROR: Unknown type in dtype::get_hfta_unpack_fcn_noxf\n");\r
1142         }\r
1143 }\r
1144 \r
1145 \r
1146 //              Return true if comparing these types requires\r
1147 //              a special function.\r
1148 //              Note:\r
1149 //                1) the function should act like strcmp (-1, 0, 1)\r
1150 //                2) this fcn assumes that type checking\r
1151 //                        has already been done.\r
1152 bool data_type::complex_comparison(data_type *dt){\r
1153   switch(type){\r
1154         case timeval_t:\r
1155         case ipv6_t:\r
1156         case v_str_t:\r
1157         case fstring_t:\r
1158                 return(true);\r
1159         default:\r
1160                 return(false);\r
1161         }\r
1162 }\r
1163 \r
1164 string data_type::get_comparison_fcn(data_type *dt){\r
1165   switch(type){\r
1166         case timeval_t:\r
1167                 return("Compare_Timeval");\r
1168         case v_str_t:\r
1169                 return("str_compare");\r
1170         case ipv6_t:\r
1171                 return("ipv6_compare");\r
1172         default:\r
1173                 return("ERROR_NO_SUCH_COMPARISON_FCN");\r
1174         }\r
1175 \r
1176 \r
1177 }\r
1178 \r
1179 string data_type::get_hfta_comparison_fcn(data_type *dt){\r
1180   switch(type){\r
1181         case timeval_t:\r
1182                 return("hfta_Compare_Timeval");\r
1183         case v_str_t:\r
1184                 return("hfta_vstr_compare");\r
1185         case ipv6_t:\r
1186                 return("hfta_ipv6_compare");\r
1187         default:\r
1188                 return("ERROR_NO_SUCH_COMPARISON_FCN");\r
1189         }\r
1190 }\r
1191 \r
1192 //              Return true if operating on  these types requires\r
1193 //              a special function for this operator.\r
1194 //              Note:\r
1195 //                1) the function should act like\r
1196 //                              int operator_fcn(*retun_val, *lhs, *rhs)\r
1197 //                2) this fcn assumes that type checking\r
1198 //                        has already been done.\r
1199 bool data_type::complex_operator(data_type *dt, string &op){\r
1200         switch(type){\r
1201         case int_t:\r
1202                 switch(dt->type){\r
1203                 case timeval_t:\r
1204                         if(op == "+")\r
1205                                 return(true);\r
1206                         break;\r
1207                 default:\r
1208                         break;\r
1209                 }\r
1210                 break;\r
1211         case timeval_t:\r
1212                 switch(dt->type){\r
1213                 case int_t:\r
1214                 case u_int_t:\r
1215                 case u_short_t:\r
1216                         if(op == "+" || op == "-" || op == "/")\r
1217                                 return(true);\r
1218                         break;\r
1219                 case timeval_t:\r
1220                         if(op == "-")\r
1221                                 return(true);\r
1222                         break;\r
1223                 default:\r
1224                         break;\r
1225                 }\r
1226         case ipv6_t:\r
1227                 if((op=="&" || op=="|") && dt->type == ipv6_t)\r
1228                         return true;\r
1229         break;\r
1230         default:\r
1231                 break;\r
1232         }\r
1233 \r
1234         return(false);\r
1235 }\r
1236 \r
1237 bool data_type::complex_operator(string &op){\r
1238         return(false);\r
1239 }\r
1240 \r
1241 string data_type::get_complex_operator(data_type *dt, string &op){\r
1242         switch(type){\r
1243         case int_t:\r
1244                 switch(dt->type){\r
1245                 case timeval_t:\r
1246                         if(op == "+")\r
1247                                 return("Add_Int_Timeval");\r
1248                         break;\r
1249                 default:\r
1250                         break;\r
1251                 }\r
1252                 break;\r
1253         case timeval_t:\r
1254                 switch(dt->type){\r
1255                 case int_t:\r
1256                 case u_int_t:\r
1257                 case u_short_t:\r
1258                         if(op == "+")\r
1259                                 return("Add_Timeval_Int");\r
1260                         if(op == "-")\r
1261                                 return("Subtract_Timeval_Int");\r
1262                         if(op == "/")\r
1263                                 return("Divide_Timeval_Int");\r
1264                         break;\r
1265                 case timeval_t:\r
1266                         if(op == "-")\r
1267                                 return("Subtract_Timeval_Timeval");\r
1268                         break;\r
1269                 default:\r
1270                         break;\r
1271                 }\r
1272                 break;\r
1273         case ipv6_t:\r
1274                 if(dt->type == ipv6_t){\r
1275                         if(op == "&")\r
1276                                 return("And_Ipv6");\r
1277                         if(op == "|")\r
1278                                 return("Or_Ipv6");\r
1279                 }\r
1280                 break;\r
1281         default:\r
1282                 break;\r
1283         }\r
1284 \r
1285         return("ERROR_NO_COMPLEX_BINARY_OPERATOR");\r
1286 }\r
1287 \r
1288 string data_type::get_complex_operator(string &op){\r
1289 \r
1290         return("ERROR_NO_COMPLEX_UNARY_OPERATOR");\r
1291 }\r
1292 \r
1293 \r
1294 bool data_type::use_hashfunc(){\r
1295         switch(type){\r
1296         case int_t:\r
1297         case u_int_t:\r
1298         case u_short_t:\r
1299         case bool_t:\r
1300         case ip_t:\r
1301                 return(false);\r
1302         case u_llong_t:\r
1303         case llong_t:\r
1304         case floating_t:\r
1305         case timeval_t:\r
1306         case ipv6_t:\r
1307         case v_str_t:\r
1308                 return(true);\r
1309         default:\r
1310                 fprintf(stderr,"ERROR: Unknown type in data_type::use_hashfunc\n");\r
1311                 exit(1);\r
1312                 return(false);\r
1313         }\r
1314 }\r
1315 string data_type::get_hfta_hashfunc(){\r
1316         switch(type){\r
1317         case int_t:\r
1318         case u_int_t:\r
1319         case u_short_t:\r
1320         case bool_t:\r
1321         case ip_t:\r
1322                 return("ERROR NO HFTA HASHFUNC");\r
1323 \r
1324         case u_llong_t:\r
1325                 //return("hfta_ullong_hashfunc");\r
1326                 return("hfta_ULLONG_to_hash");\r
1327         case llong_t:\r
1328                 //return("hfta_ullong_hashfunc");\r
1329                 return("hfta_LLONG_to_hash");\r
1330         case floating_t:\r
1331                 //return("hfta_float_hashfunc");\r
1332                 return("hfta_FLOAT_to_hash");\r
1333 \r
1334         case ipv6_t:\r
1335                 return("hfta_IPV6_to_hash");\r
1336         case timeval_t:\r
1337                 return("hfta_timeval_hashfunc");\r
1338         case v_str_t:\r
1339                 return("hfta_vstr_hashfunc");\r
1340         default:\r
1341                 fprintf(stderr,"ERROR: Unknown type in data_type::get_hfta_hashfunc\n");\r
1342                 exit(1);\r
1343                 return("false"); // to make compiler happy\r
1344         }\r
1345 }\r
1346 \r
1347 //              Return true if the data type contains a ptr to a\r
1348 //              memory buffer.  (copying sometimes requires special cate).\r
1349 //              ASSUMPTION:\r
1350 bool data_type::is_buffer_type(){\r
1351         switch(type){\r
1352         case int_t:\r
1353         case u_int_t:\r
1354         case u_short_t:\r
1355         case bool_t:\r
1356         case u_llong_t:\r
1357         case llong_t:\r
1358         case floating_t:\r
1359         case timeval_t:\r
1360         case ipv6_t:\r
1361         case ip_t:\r
1362         case fstring_t:\r
1363                 return(false);\r
1364         case v_str_t:\r
1365                 return(true);\r
1366         default:\r
1367                 fprintf(stderr,"ERROR: Unknown type in dtype::is_buffer_type\n");\r
1368                 exit(1);\r
1369                 return(false);\r
1370         }\r
1371 }\r
1372 \r
1373 //              Fcns which return the names of functions for\r
1374 //              handling complex types.\r
1375 \r
1376 //-----------------------------\r
1377 //              LFTA functions\r
1378 \r
1379 string data_type::get_buffer_assign_copy(){\r
1380   switch(type){\r
1381         case v_str_t:\r
1382                 return("str_assign_with_copy");\r
1383         default:\r
1384                 break;\r
1385         }\r
1386 \r
1387         return("ERROR_NO_SUCH_buffer_assign_copy_FCN");\r
1388 }\r
1389 \r
1390 string data_type::get_buffer_tuple_copy(){\r
1391   switch(type){\r
1392         case v_str_t:\r
1393                 return("str_assign_with_copy_in_tuple");\r
1394         default:\r
1395                 break;\r
1396         }\r
1397 \r
1398         return("ERROR_NO_SUCH_buffer_tuple_copy_FCN");\r
1399 }\r
1400 \r
1401 string data_type::get_buffer_replace(){\r
1402   switch(type){\r
1403         case v_str_t:\r
1404                 return("str_replace");\r
1405         default:\r
1406                 break;\r
1407         }\r
1408 \r
1409         return("ERROR_NO_SUCH_buffer_replace_FCN");\r
1410 }\r
1411 \r
1412 string data_type::get_buffer_size(){\r
1413   switch(type){\r
1414         case v_str_t:\r
1415                 return("str_length");\r
1416         default:\r
1417                 break;\r
1418         }\r
1419 \r
1420         return("ERROR_NO_SUCH_buffer_size_FCN");\r
1421 }\r
1422 \r
1423 string data_type::get_buffer_destroy(){\r
1424   switch(type){\r
1425         case v_str_t:\r
1426                 return("str_destroy");\r
1427         default:\r
1428                 break;\r
1429         }\r
1430 \r
1431         return("ERROR_NO_SUCH_buffer_destroy_FCN");\r
1432 }\r
1433 \r
1434 //-----------------------------\r
1435 //              HFTA fcns\r
1436 \r
1437 string data_type::get_hfta_buffer_assign_copy(){\r
1438   switch(type){\r
1439         case v_str_t:\r
1440                 return("hfta_vstr_assign_with_copy");\r
1441         default:\r
1442                 break;\r
1443         }\r
1444 \r
1445         return("ERROR_NO_SUCH_buffer_assign_copy_FCN");\r
1446 }\r
1447 \r
1448 string data_type::get_hfta_buffer_tuple_copy(){\r
1449   switch(type){\r
1450         case v_str_t:\r
1451                 return("hfta_vstr_assign_with_copy_in_tuple");\r
1452         default:\r
1453                 break;\r
1454         }\r
1455 \r
1456         return("ERROR_NO_SUCH_buffer_tuple_copy_FCN");\r
1457 }\r
1458 \r
1459 string data_type::get_hfta_buffer_replace(){\r
1460   switch(type){\r
1461         case v_str_t:\r
1462                 return("hfta_vstr_replace");\r
1463         default:\r
1464                 break;\r
1465         }\r
1466 \r
1467         return("ERROR_NO_SUCH_buffer_replace_FCN");\r
1468 }\r
1469 \r
1470 string data_type::get_hfta_buffer_size(){\r
1471   switch(type){\r
1472         case v_str_t:\r
1473                 return("hfta_vstr_length");\r
1474         default:\r
1475                 break;\r
1476         }\r
1477 \r
1478         return("ERROR_NO_SUCH_buffer_size_FCN");\r
1479 }\r
1480 \r
1481 string data_type::get_hfta_buffer_destroy(){\r
1482   switch(type){\r
1483         case v_str_t:\r
1484                 return("hfta_vstr_destroy");\r
1485         default:\r
1486                 break;\r
1487         }\r
1488 \r
1489         return("ERROR_NO_SUCH_buffer_destroy_FCN");\r
1490 }\r
1491 //-----------------------------\r
1492 \r
1493 \r
1494 //              Return true if the data type is represented by a strucutre.\r
1495 bool data_type::is_structured_type(){\r
1496         switch(type){\r
1497         case int_t:\r
1498         case u_int_t:\r
1499         case u_short_t:\r
1500         case bool_t:\r
1501         case u_llong_t:\r
1502         case llong_t:\r
1503         case floating_t:\r
1504         case ip_t:\r
1505                 return(false);\r
1506         case timeval_t:\r
1507         case ipv6_t:\r
1508         case v_str_t:\r
1509         case fstring_t:\r
1510                 return(true);\r
1511         default:\r
1512                 fprintf(stderr,"ERROR: Unknown type in dtype::is_structured_type\n");\r
1513                 exit(1);\r
1514                 return(false);\r
1515         }\r
1516 }\r
1517 \r
1518 \r
1519 //              type of a variable holding this value.\r
1520 //                      Seems to be a relic\r
1521 /*\r
1522 string data_type::get_interface_type(){\r
1523         char tmps[100];\r
1524         switch(type){\r
1525         case int_t:\r
1526                 return("int ");\r
1527         case u_int_t:\r
1528                 return("unsigned int ");\r
1529         case u_short_t:\r
1530                 return("unsigned short int ");\r
1531         case bool_t:\r
1532                 return("int ");\r
1533         case u_llong_t:\r
1534                 return("unsigned long long int ");\r
1535         case llong_t:\r
1536                 return("long long int ");\r
1537         case floating_t:\r
1538                 return("double ");\r
1539         case v_str_t:\r
1540                 return("ERROR");\r
1541         case fstring_t:\r
1542                 sprintf(tmps,"char[%d] ",size);\r
1543                 return(tmps);\r
1544         case timeval_t:\r
1545                 return("ERROR ");\r
1546         case ipv6_t:\r
1547                 return "ERROR";\r
1548         default:\r
1549                 return("ERROR: Unknown type in dtype::get_interface_type\n");\r
1550         }\r
1551 }\r
1552 */\r
1553 \r
1554 \r
1555 //              This type of handle registration is obsolete\r
1556 \r
1557 string data_type::handle_registration_name(){\r
1558 \r
1559                 switch(type){\r
1560                 case v_str_t:\r
1561                         return("str_register_search_string");\r
1562                 default:\r
1563                         return("");\r
1564                 }\r
1565                 return("ERROR UNKNOWN LITERAL");\r
1566         };\r
1567 \r
1568 string data_type::hfta_handle_registration_name(){\r
1569 \r
1570                 switch(type){\r
1571                 case v_str_t:\r
1572                         return("vstr_register_search_string");\r
1573                 default:\r
1574                         return("");\r
1575                 }\r
1576                 return("ERROR UNKNOWN LITERAL");\r
1577         };\r
1578 \r
1579 \r
1580 string data_type::get_handle_destructor(){\r
1581 \r
1582                 switch(type){\r
1583                 case v_str_t:\r
1584                         return("str_release_search_string");\r
1585                 default:\r
1586                         return("");\r
1587                 }\r
1588                 return("ERROR UNKNOWN LITERAL");\r
1589         };\r
1590 \r
1591 \r
1592 //  should be the inverse of\r
1593 //      data_type::data_type(string st, param_list *modifiers)\r
1594 vector<string> data_type::get_param_keys(){\r
1595     vector<string> retval;\r
1596 \r
1597     if(temporal == increasing_t)\r
1598         retval.push_back("INCREASING");\r
1599     if(temporal == decreasing_t)\r
1600         retval.push_back("DECREASING");\r
1601         if(subtype != "") retval.push_back("subtype");\r
1602 \r
1603     return(retval);\r
1604 }\r
1605 \r
1606 string data_type::get_param_val(string k){\r
1607         if(k=="subtype") return subtype;\r
1608         return "";\r
1609 }\r
1610 \r
1611 std::string data_type::get_temporal_string(){\r
1612     if(temporal == increasing_t)\r
1613         return("INCREASING");\r
1614     if(temporal == decreasing_t)\r
1615         return("DECREASING");\r
1616         return("");\r
1617 }\r
1618 \r
1619 \r
1620 bool data_type::needs_hn_translation(){\r
1621         switch(type){\r
1622         case int_t:\r
1623         case u_int_t:\r
1624         case u_short_t:\r
1625         case bool_t:\r
1626         case u_llong_t:\r
1627         case llong_t:\r
1628         case floating_t:\r
1629         case timeval_t:\r
1630         case ipv6_t:\r
1631         case v_str_t:\r
1632         case ip_t:\r
1633                 return(true);\r
1634         case fstring_t:\r
1635                 return(false);\r
1636         default:\r
1637                 fprintf(stderr,"INTERNAL ERROR: Unknown type in dtype::needs_hn_translation\n");\r
1638                 exit(1);\r
1639                 return(false);\r
1640         }\r
1641 }\r
1642 \r
1643 std::string data_type::hton_translation(){\r
1644 fprintf(stderr,"INTERNAL ERROR, hton_translation called.\n");\r
1645 return("");\r
1646 \r
1647         switch(type){\r
1648         case int_t:\r
1649         case u_int_t:\r
1650         case u_short_t:\r
1651         case bool_t:\r
1652         case ip_t:\r
1653                 return("htonl");\r
1654                 break;\r
1655         case u_llong_t:\r
1656         case llong_t:\r
1657                 return("htonll");\r
1658                 break;\r
1659         case floating_t:\r
1660                 return("htonf");\r
1661                 break;\r
1662         case timeval_t:\r
1663                 return("htontv");\r
1664                 break;\r
1665         case ipv6_t:\r
1666                 return("hton_ipv6");\r
1667                 break;\r
1668         case v_str_t:\r
1669                 return("INTERNAL ERROR, net translation for buffered types needs special handling.\n");\r
1670         default:\r
1671                 fprintf(stderr,"INTERNAL ERROR: Unknown type in dtype::hton_translation\n");\r
1672                 exit(1);\r
1673                 return("INTERNAL ERROR: NO SUCH TYPE IN hton_translation");\r
1674         }\r
1675 }\r
1676 \r
1677 std::string data_type::ntoh_translation(){\r
1678 fprintf(stderr,"INTERNAL ERROR, ntoh_translation called.\n");\r
1679 return("");\r
1680 \r
1681         switch(type){\r
1682         case int_t:\r
1683         case u_int_t:\r
1684         case u_short_t:\r
1685         case bool_t:\r
1686         case ip_t:\r
1687                 return("ntohl");\r
1688                 break;\r
1689         case u_llong_t:\r
1690         case llong_t:\r
1691                 return("ntohll");\r
1692                 break;\r
1693         case floating_t:\r
1694                 return("ntohf");\r
1695                 break;\r
1696         case timeval_t:\r
1697                 return("ntohtv");\r
1698                 break;\r
1699         case ipv6_t:\r
1700                 return("ntoh_ipv6");\r
1701                 break;\r
1702         case v_str_t:\r
1703                 return("INTERNAL ERROR, net translation for buffered types needs special handling.\n");\r
1704         default:\r
1705                 fprintf(stderr,"INTERNAL ERROR: Unknown type in dtype::ntoh_translation\n");\r
1706                 exit(1);\r
1707                 return("INTERNAL ERROR: NO SUCH TYPE IN ntoh_translation");\r
1708         }\r
1709 }\r
1710 \r
1711 int data_type::type_indicator(){\r
1712         switch(type){\r
1713         case int_t:\r
1714                 return(INT_TYPE);\r
1715         case u_int_t:\r
1716                 return(UINT_TYPE);\r
1717         case u_short_t:\r
1718                 return(USHORT_TYPE);\r
1719         case bool_t:\r
1720                 return(BOOL_TYPE);\r
1721         case u_llong_t:\r
1722                 return(ULLONG_TYPE);\r
1723         case llong_t:\r
1724                 return(LLONG_TYPE);\r
1725         case floating_t:\r
1726                 return(FLOAT_TYPE);\r
1727         case timeval_t:\r
1728                 return(TIMEVAL_TYPE);\r
1729         case ipv6_t:\r
1730                 return(IPV6_TYPE);\r
1731         case ip_t:\r
1732                 return(IP_TYPE);\r
1733         case v_str_t:\r
1734                 return(VSTR_TYPE);\r
1735         case fstring_t:\r
1736                 return(FSTRING_TYPE);\r
1737         default:\r
1738                 return(UNDEFINED_TYPE);\r
1739         }\r
1740         return(UNDEFINED_TYPE);\r
1741 }\r
1742 \r
1743 //              for schemaparser\r
1744 \r
1745 int data_type::type_size(){\r
1746         switch(type){\r
1747         case int_t:\r
1748                 return(sizeof(gs_int32_t));\r
1749         case u_int_t:\r
1750         case u_short_t:\r
1751         case bool_t:\r
1752         case ip_t:\r
1753                 return(sizeof(gs_uint32_t));\r
1754         case u_llong_t:\r
1755                 return(sizeof(gs_uint64_t));\r
1756         case llong_t:\r
1757                 return(sizeof(gs_int64_t));\r
1758         case floating_t:\r
1759                 return(sizeof(gs_float_t));\r
1760         case timeval_t:\r
1761                 return(sizeof(timeval));                // IMPLEMENTATION DEPENDENT\r
1762         case ipv6_t:\r
1763                 return(sizeof(hfta_ipv6_str));          // IMPLEMENTATION DEPENDENT\r
1764         case v_str_t:\r
1765                 return(sizeof(vstring32));              // IMPLEMENTATION DEPENDENT\r
1766         case fstring_t:\r
1767                 return(size);\r
1768         default:\r
1769                 return(0);\r
1770         }\r
1771         return(0);\r
1772 }\r
1773 \r
1774 //              for external functions and predicates\r
1775 \r
1776 /*\r
1777 bool data_type::call_compatible(data_type *o){\r
1778         if(type != o->get_type()) return(false);\r
1779         if(type == fstring_t){\r
1780                 if(size != 0 && size != o->type_size()) return(false);\r
1781         }\r
1782         return(true);\r
1783 }\r
1784 \r
1785 //              test for equality : used by bind_to_schema and by testing for\r
1786 //              mergability.\r
1787 \r
1788 bool data_type::equal(data_type *o){\r
1789         if(type != o->get_type()) return(false);\r
1790         if(type == fstring_t){\r
1791                 if(size != o->type_size()) return(false);\r
1792         }\r
1793         return(true);\r
1794 }\r
1795 */\r
1796 \r
1797 bool data_type::subsumes_type(data_type *o){\r
1798         if(type != o->get_type()) return(false);\r
1799         if(type == fstring_t){\r
1800                 if(size != o->type_size()) return(false);\r
1801         }\r
1802         if(this->is_temporal() && temporal != o->get_temporal()) return false;\r
1803         if(subtype != "" && subtype != o->subtype) return false;\r
1804 \r
1805         return(true);\r
1806 }\r
1807 \r
1808 bool data_type::equals(data_type *o){\r
1809         if(type != o->get_type()) return(false);\r
1810         if(type == fstring_t){\r
1811                 if(size != o->type_size()) return(false);\r
1812         }\r
1813         if(temporal != o->get_temporal()) return false;\r
1814         if(subtype != o->subtype) return false;\r
1815 \r
1816         return(true);\r
1817 }\r
1818 \r
1819 bool data_type::equal_subtypes(data_type *o){\r
1820         if(type != o->get_type()) return(false);\r
1821         if(type == fstring_t){\r
1822                 if(size != o->type_size()) return(false);\r
1823         }\r
1824         if(subtype != o->subtype) return false;\r
1825 \r
1826         return(true);\r
1827 }\r
1828 \r
1829 \r
1830 string data_type::to_string(){\r
1831         string ret = schema_type;\r
1832         if(this->is_temporal() || subtype != ""){\r
1833                 ret += " (";\r
1834                  if(temporal == increasing_t)\r
1835                 ret += "INCREASING";\r
1836         if(temporal == decreasing_t)\r
1837                 ret += "DECREASING";\r
1838                 if(this->is_temporal() && subtype != "")\r
1839                         ret += ", ";\r
1840                 if(subtype != "")\r
1841                         ret += "subtype "+subtype;\r
1842                 ret += ")";\r
1843         }\r
1844         return ret;\r
1845 }\r
1846 \r
1847 \r
1848 \r
1849 string data_type::get_min_literal() {\r
1850         switch(type){\r
1851         case int_t:\r
1852                 return("INT_MIN");\r
1853         case bool_t:\r
1854         case u_short_t:\r
1855         case u_int_t:\r
1856         case ip_t:\r
1857                 return("0");\r
1858         case u_llong_t:\r
1859                 return("0");\r
1860         case llong_t:\r
1861                 return("LLONG_MIN");\r
1862         case floating_t:\r
1863                 return("DBL_MIN");\r
1864         case timeval_t:\r
1865                 return("{0,0}");\r
1866         case ipv6_t:\r
1867                 return("0000:0000:0000:0000:0000:0000:0000:0000");\r
1868         case v_str_t:\r
1869         case fstring_t:\r
1870                 return("ERROR: Min literal is undefined for strings\n");\r
1871         default:\r
1872                 return("ERROR: Unknown type in data_type::get_min_literal\n");\r
1873         }\r
1874 }\r
1875 \r
1876 string data_type::get_max_literal() {\r
1877         switch(type){\r
1878         case int_t:\r
1879                 return("INT_MAX");\r
1880         case bool_t:\r
1881         case u_short_t:\r
1882         case u_int_t:\r
1883         case ip_t:\r
1884                 return("UINT_MAX");\r
1885         case u_llong_t:\r
1886                 return("ULLONG_MAX");\r
1887         case llong_t:\r
1888                 return("LLONG_MAX");\r
1889         case floating_t:\r
1890                 return("DBL_MAX");\r
1891         case timeval_t:\r
1892                 return("{UINT_MAX,UINT_MAX}");\r
1893         case ipv6_t:\r
1894                 return("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");\r
1895         case v_str_t:\r
1896         case fstring_t:\r
1897                 return("ERROR: Max literal is undefined for strings\n");\r
1898         default:\r
1899                 return("ERROR: Unknown type in data_type::get_max_literal\n");\r
1900         }\r
1901 \r
1902 }\r
1903 \r