Fawkes API  Fawkes Development Version
pseudomap.cpp
1 
2 /***************************************************************************
3  * pseudomap.cpp - Interface generator pseudo representation
4  *
5  * Created: Thu Nov 20 15:09:23 2008
6  * Copyright 2006-2008 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include <interfaces/generator/pseudomap.h>
24 #include <interfaces/generator/type_checker.h>
25 #include <interfaces/generator/exceptions.h>
26 
27 #include <cstdlib>
28 
29 
30 /** @class InterfacePseudoMap "pseudomap.h"
31  * Interface generator internal representation of a pseudo map as parsed from
32  * the XML template file.
33  * @author Tim Niemueller
34  */
35 
36 
37 /** Constructor.
38  * @param name name of the pseudo map
39  * @param type type of the values in the map
40  * @param keytype type of the keys
41  * @param comment comment of the pseudo map
42  */
43 InterfacePseudoMap::InterfacePseudoMap(std::string name, std::string type,
44  std::string keytype, std::string comment)
45 {
46  __name = name;
47  __type = type;
48  __keytype = keytype;
49  __comment = comment;
50 }
51 
52 
53 /** Get name of field.
54  * @return name of field.
55  */
56 std::string
58 {
59  return __name;
60 }
61 
62 
63 /** Get type of field.
64  * @return type of field.
65  */
66 std::string
68 {
69  return __type;
70 }
71 
72 
73 /** Get comment of field.
74  * @return comment of field.
75  */
76 std::string
78 {
79  return __comment;
80 }
81 
82 
83 /** Get type of key value.
84  * @return type of key
85  */
86 std::string
88 {
89  return __keytype + "_t";
90 }
91 
92 
93 
94 /** Assert validity.
95  * Calling valid() acts like an assertion. An Exception is thrown if something is wrong.
96  * @exception InterfaceGeneratorInvalidTypeException thrown if InterfaceDataTypeChecker
97  * reports invalid type.
98  * @exception InterfaceGeneratorInvalidValueException thrown if any supplied value is
99  * illegal.
100  * @exception InterfaceGeneratorInvalidFlagException thrown if invalid flag has been
101  * supplied.
102  */
103 void
105 {
106  if ( (__name.length() == 0) || (__name.find(" ") != std::string::npos) ) {
107  throw InterfaceGeneratorInvalidValueException("name", "string", "name must neither be empty nor contain spaces");
108  }
109  if (__type.length() == 0) {
110  throw InterfaceGeneratorInvalidValueException("type", "string", "type must not be empty");
111  }
112  if ( (__keytype != "int8") && (__keytype != "int16") &&
113  (__keytype != "int32") && (__keytype != "int64") &&
114  (__keytype != "uint8") && (__keytype != "uint16") &&
115  (__keytype != "uint32") && (__keytype != "uint64") ) {
116  throw InterfaceGeneratorInvalidValueException("keytype", "string", "Pseudo map keys can only be of a numeric type");
117  }
118  if (__keytype.length() == 0) {
119  throw InterfaceGeneratorInvalidValueException("keytype", "string", "key type must not be empty");
120  }
121 }
122 
123 
124 /** Add reference.
125  * @param fieldname name of the field that is referenced
126  * @param key key of the field in the pseudo map
127  */
128 void
129 InterfacePseudoMap::addRef(std::string fieldname, std::string key)
130 {
131  __parefs.push_back(make_pair(fieldname, key));
132 }
133 
134 
135 /** Get reference list.
136  * @return reference list
137  */
140 {
141  return __parefs;
142 }
std::string getName() const
Get name of field.
Definition: pseudomap.cpp:57
Thrown if illegal value is supplied.
Definition: exceptions.h:90
std::string getComment() const
Get comment of field.
Definition: pseudomap.cpp:77
RefList & getRefList()
Get reference list.
Definition: pseudomap.cpp:139
std::list< std::pair< std::string, std::string > > RefList
Reference list.
Definition: pseudomap.h:35
std::string getKeyType() const
Get type of key value.
Definition: pseudomap.cpp:87
void addRef(std::string fieldname, std::string key)
Add reference.
Definition: pseudomap.cpp:129
void valid()
Assert validity.
Definition: pseudomap.cpp:104
InterfacePseudoMap(std::string name, std::string type, std::string keytype, std::string comment)
Constructor.
Definition: pseudomap.cpp:43
std::string getType() const
Get type of field.
Definition: pseudomap.cpp:67