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