9d7139cd9639b66dd7baacfc431bde47c42d7e72
[com/gs-lite.git] / src / ftacmp / nic_def.h
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 #ifndef _FTA_NIC_DEF_H_INCLUDED__\r
16 #define _FTA_NIC_DEF_H_INCLUDED__\r
17 \r
18 #include<vector>\r
19 #include<string>\r
20 #include<map>\r
21 \r
22 class nic_property{\r
23 public:\r
24         std::vector<std::string> opta;  // option args\r
25         std::vector<std::string> optv;  // val of option args\r
26         std::vector<std::string> typea; // legal types \r
27         std::vector<std::string> opba;  // legal binary ops\r
28         std::vector<std::string> opua;  // legal unary ops\r
29         std::vector<std::string> fieldsa; // illegal fields\r
30         std::vector<std::string> funca;  // legal functions\r
31 \r
32         nic_property(){};\r
33 \r
34         bool legal_type(std::string t);\r
35         bool legal_unary_op(std::string t);\r
36         bool legal_binary_op(std::string t);\r
37         bool illegal_field(std::string t);\r
38         bool option_exists(std::string t);\r
39         std::string option_value(std::string t);\r
40 };\r
41 \r
42 \r
43 nic_property *load_nic_property(std::string dir, std::string name);\r
44 \r
45 \r
46 class nic_prop_db{\r
47 public:\r
48         std::string dir;\r
49         std::map<std::string, nic_property *> ndb;\r
50 \r
51         nic_prop_db(std::string d){dir=d;};\r
52 \r
53         \r
54         nic_property *get_nic_property(std::string nics, int &err_no){\r
55                 if(ndb.count(nics))\r
56                         return ndb[nics];\r
57                 nic_property *ret = load_nic_property(dir, nics);\r
58                 if(ret)\r
59                         ndb[nics] = ret;\r
60                 return ret;\r
61         };\r
62 \r
63 \r
64         std::string get_nic_prop_val(std::string nics, std::string prop,int &err_no){\r
65                 nic_property *nicp = this->get_nic_property(nics, err_no);\r
66                 if(!nicp){\r
67                         fprintf(stderr,"ERROR cannot load nic properties %s for nic type %s in get_nic_prop_val\n",nics.c_str(), prop.c_str());\r
68                                 exit(1);\r
69                 }\r
70                 if(nicp->option_exists(prop)){\r
71                         return nicp->option_value("Return");\r
72                 }else{\r
73                         return "";\r
74                 }\r
75 \r
76         }\r
77 };\r
78 \r
79 \r
80 void NicParser_setfileinput(FILE *f);\r
81 \r
82 \r
83 \r
84 #endif\r