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/checker.h>
24#include <interfaces/generator/exceptions.h>
25#include <interfaces/generator/pseudomap.h>
26
27#include <cstdlib>
28
29/** @class InterfacePseudoMap "pseudomap.h"
30 * Interface generator internal representation of a pseudo map as parsed from
31 * the XML template file.
32 * @author Tim Niemueller
33 */
34
35/** Constructor.
36 * @param name name of the pseudo map
37 * @param type type of the values in the map
38 * @param keytype type of the keys
39 * @param comment comment of the pseudo map
40 */
42 std::string type,
43 std::string keytype,
44 std::string comment)
45{
46 name_ = name;
47 type_ = type;
48 keytype_ = keytype;
49 comment_ = comment;
50}
51
52/** Get name of field.
53 * @return name of field.
54 */
55std::string
57{
58 return name_;
59}
60
61/** Get type of field.
62 * @return type of field.
63 */
64std::string
66{
67 return type_;
68}
69
70/** Get comment of field.
71 * @return comment of field.
72 */
73std::string
75{
76 return comment_;
77}
78
79/** Get type of key value.
80 * @return type of key
81 */
82std::string
84{
85 return keytype_ + "_t";
86}
87
88/** Assert validity.
89 * Calling valid() acts like an assertion. An Exception is thrown if something is wrong.
90 * @exception InterfaceGeneratorInvalidTypeException thrown if InterfaceDataTypeChecker
91 * reports invalid type.
92 * @exception InterfaceGeneratorInvalidValueException thrown if any supplied value is
93 * illegal.
94 * @exception InterfaceGeneratorInvalidFlagException thrown if invalid flag has been
95 * supplied.
96 */
97void
99{
100 if ((name_.length() == 0) || (name_.find(" ") != std::string::npos)) {
102 "string",
103 "name must neither be empty nor contain spaces");
104 }
105 if (type_.length() == 0) {
106 throw InterfaceGeneratorInvalidValueException("type", "string", "type must not be empty");
107 }
108 if ((keytype_ != "int8") && (keytype_ != "int16") && (keytype_ != "int32")
109 && (keytype_ != "int64") && (keytype_ != "uint8") && (keytype_ != "uint16")
110 && (keytype_ != "uint32") && (keytype_ != "uint64")) {
112 "string",
113 "Pseudo map keys can only be of a numeric type");
114 }
115 if (keytype_.length() == 0) {
117 "string",
118 "key type must not be empty");
119 }
120}
121
122/** Add reference.
123 * @param fieldname name of the field that is referenced
124 * @param key key of the field in the pseudo map
125 */
126void
127InterfacePseudoMap::addRef(std::string fieldname, std::string key)
128{
129 parefs_.push_back(make_pair(fieldname, key));
130}
131
132/** Get reference list.
133 * @return reference list
134 */
137{
138 return parefs_;
139}
Thrown if illegal value is supplied.
Definition: exceptions.h:91
std::list< std::pair< std::string, std::string > > RefList
Reference list.
Definition: pseudomap.h:35
std::string getName() const
Get name of field.
Definition: pseudomap.cpp:56
InterfacePseudoMap(std::string name, std::string type, std::string keytype, std::string comment)
Constructor.
Definition: pseudomap.cpp:41
std::string getType() const
Get type of field.
Definition: pseudomap.cpp:65
std::string getKeyType() const
Get type of key value.
Definition: pseudomap.cpp:83
void addRef(std::string fieldname, std::string key)
Add reference.
Definition: pseudomap.cpp:127
std::string getComment() const
Get comment of field.
Definition: pseudomap.cpp:74
RefList & getRefList()
Get reference list.
Definition: pseudomap.cpp:136
void valid()
Assert validity.
Definition: pseudomap.cpp:98