Added quantiling UDAFs
[com/gs-lite.git] / src / ftacmp / nic_def.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 #include<stdio.h>\r
16 #include<stdlib.h>\r
17 \r
18 #include"nic_def.h"\r
19 \r
20 extern int NicParserparse(void);\r
21 extern FILE *NicParserin;\r
22 extern int NicParserdebug;\r
23 \r
24 \r
25 nic_property *nicp;\r
26 std::vector<std::string> nic_attr_vec;\r
27 std::vector<std::string> nic_val_vec;\r
28 std::string nic_a, nic_v;\r
29 \r
30 using namespace std;\r
31 \r
32 nic_property *load_nic_property(std::string dir, std::string name){\r
33 \r
34         string fname;\r
35         if(dir != "")\r
36                 fname = dir + "/nic_property_"+name+".def";\r
37         else\r
38                 fname = "nic_property_"+name+".def";\r
39 \r
40         FILE *nicf = fopen(fname.c_str(),"r");\r
41         if(! nicf){\r
42                 fprintf(stderr,"ERROR, can't open nic property file %s\n",fname.c_str());\r
43                 return NULL;\r
44         }\r
45 \r
46 NicParserdebug = 0;\r
47         nicp = new nic_property();\r
48         NicParser_setfileinput(nicf);\r
49         if(NicParserparse()){\r
50                 fprintf(stderr,"could not parse nic property file %s\n",fname.c_str());\r
51                 return NULL;\r
52         }\r
53         \r
54         return nicp;\r
55 }\r
56 \r
57 bool nic_property::legal_type(string t){\r
58 int i;\r
59         for(i=0;i<typea.size();++i){\r
60                 if(t==typea[i])\r
61                         return true;\r
62         }\r
63         return false;\r
64 }\r
65 \r
66 \r
67 bool nic_property::legal_unary_op(string t){\r
68 int i;\r
69         for(i=0;i<opua.size();++i){\r
70                 if(t==opua[i])\r
71                         return true;\r
72         }\r
73         return false;\r
74 }\r
75 \r
76 \r
77 \r
78 bool nic_property::legal_binary_op(string t){\r
79 int i;\r
80         for(i=0;i<opba.size();++i){\r
81                 if(t==opba[i])\r
82                         return true;\r
83         }\r
84         return false;\r
85 }\r
86 \r
87 \r
88 bool nic_property::illegal_field(string t){\r
89 int i;\r
90         for(i=0;i<fieldsa.size();++i){\r
91                 if(t==fieldsa[i])\r
92                         return true;\r
93         }\r
94         return false;\r
95 }\r
96 \r
97 \r
98 \r
99 bool nic_property::option_exists(string t){\r
100 int i;\r
101         for(i=0;i<opta.size();++i){\r
102                 if(t==opta[i])\r
103                         return true;\r
104         }\r
105         return false;\r
106 }\r
107 \r
108 \r
109 string nic_property::option_value(string t){\r
110 int i;\r
111         for(i=0;i<opta.size();++i){\r
112                 if(t==opta[i])\r
113                         return optv[i];\r
114         }\r
115         return "";\r
116 }\r
117 \r
118 \r
119 \r
120 \r
121 \r
122 \r
123 \r
124 \r
125 \r
126 \r
127 \r
128 \r