1 /* ------------------------------------------------
2 Copyright 2014 AT&T Intellectual Property
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ------------------------------------------- */
23 #include"field_list.h"
32 static struct type_map_t type_map[] = {
41 "INT(_huge_)", "INT(_huge_)",
42 "LLONG", "INT(_huge_)",
43 "Llong", "INT(_huge_)",
44 "llong", "INT(_huge_)",
45 "INTEGER(_huge_)", "INT(_huge_)",
52 "UINT(_huge_)", "UINT(_huge_)",
53 "ULLONG", "UINT(_huge_)",
54 "Ullong", "UINT(_huge_)",
55 "ullong", "UINT(_huge_)",
64 "DATE_CLOCK", "DATE_CLOCK",
83 field_list::field_list(xml_t *x){
85 for(i=0;type_map[i].from != ""; i++){
86 type_verifier[type_map[i].from] = type_map[i].to;
88 type_verifier[""] = "";
90 for(i=0;i<x->leaves.size();i++){
91 if(x->leaves[i]->name != "field"){
92 fprintf(stderr,"WARNING, unrecognized leaf element %s in field list file, ignoring.\n",x->leaves[i]->name.c_str());
96 std::string fname, ftype;
97 for(j=0;j<x->leaves[i]->attrs.size();j++){
98 if(x->leaves[i]->attrs[j] == "name"){
100 fprintf(stderr,"WARNING, found duplicate name property for a field (#%d, %s) in the field list, ignoring second name %s.\n",i,fname.c_str(), x->leaves[i]->vals[j].c_str());
102 fname = x->leaves[i]->vals[j];
107 fprintf(stderr,"WARNING, field %d has an empty name, ignoring\n",i);
111 for(j=0;j<x->leaves[i]->attrs.size();j++){
112 if(x->leaves[i]->attrs[j] == "type"){
114 fprintf(stderr,"WARNING, found duplicate type property for field %s in the field list, ignoring.\n",fname.c_str());
116 ftype = x->leaves[i]->vals[j];
121 if(fields.count(fname)){
122 fprintf(stderr,"WARNING, duplicate field list name %s, ignoring repeat entry.\n",fname.c_str());
125 if(type_verifier.count(ftype) == 0){
126 fprintf(stderr,"WARNING, field %s in the field list has unrecognized type %s, ignoring the type.\n",fname.c_str(),ftype.c_str());
130 string::size_type ix = fname.rfind("/");
131 if(ix != string::npos){
132 fname = fname.substr(ix+1);
135 fields[fname] = ftype;