Fawkes API  Fawkes Development Version
enum_constant.cpp
1 
2 /***************************************************************************
3  * enum_constant.cpp - Interface generator enum constant representation
4  *
5  * Generated: Wed Oct 11 19:41:56 2006
6  * Copyright 2006 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/enum_constant.h>
24 #include <interfaces/generator/exceptions.h>
25 
26 /** @class InterfaceEnumConstant interfaces/generator/enum_constant.h
27  * Interface generator internal representation of a enum constant as parsed
28  * from the XML template file.
29  */
30 
31 
32 /** Constructor.
33  * @param name name of enumeration constant
34  * @param comment comment of enumeration constant.
35  */
37  const std::string &comment)
38 {
39  __name = name;
40  __comment = comment;
41  __items.clear();
42 }
43 
44 
45 /** Get name of enum constant.
46  * @return name of enum constant.
47  */
48 const std::string &
50 {
51  return __name;
52 }
53 
54 
55 /** Get comment of enum constant.
56  * @return comment of enum constant.
57  */
58 const std::string &
60 {
61  return __comment;
62 }
63 
64 
65 /** Get enumeration items.
66  * @return vector of enum items. First item in pair contains item name, second item
67  * the comment.
68  */
69 const std::vector<InterfaceEnumConstant::EnumItem> &
71 {
72  return __items;
73 }
74 
75 
76 /** Add an item without custom value.
77  * @param name name of item
78  * @param comment comment of item.
79  */
80 void
81 InterfaceEnumConstant::add_item(std::string name, std::string comment)
82 {
83  std::vector<EnumItem>::iterator i;
84  for (i = __items.begin(); i != __items.end(); ++i) {
85  if (i->name == name) {
86  throw InterfaceGeneratorAmbiguousNameException(name.c_str(), "enum item");
87  }
88  }
89  EnumItem p = {name, comment, false, 0};
90  __items.push_back(p);
91 }
92 
93 
94 /** Add an item with custom value.
95  * @param name name of item
96  * @param comment comment of item.
97  * @param value custom value
98  */
99 void
100 InterfaceEnumConstant::add_item(std::string name, std::string comment, int value)
101 {
102  std::vector<EnumItem>::iterator i;
103  for (i = __items.begin(); i != __items.end(); ++i) {
104  if (i->name == name) {
105  throw InterfaceGeneratorAmbiguousNameException(name.c_str(), "enum item");
106  }
107  }
108  EnumItem p = {name, comment, true, value};
109  __items.push_back(p);
110 }
const std::string & get_comment() const
Get comment of enum constant.
const std::vector< EnumItem > & get_items() const
Get enumeration items.
Thrown if name is ambiguous.
Definition: exceptions.h:158
InterfaceEnumConstant(const std::string &name, const std::string &comment)
Constructor.
void add_item(std::string name, std::string comment)
Add an item without custom value.
const std::string & get_name() const
Get name of enum constant.