Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * enum_constant.cpp - Interface generator enum constant representation 00004 * 00005 * Generated: Wed Oct 11 19:41:56 2006 00006 * Copyright 2006 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #include <interfaces/generator/enum_constant.h> 00024 #include <interfaces/generator/exceptions.h> 00025 00026 /** @class InterfaceEnumConstant interfaces/generator/enum_constant.h 00027 * Interface generator internal representation of a enum constant as parsed 00028 * from the XML template file. 00029 */ 00030 00031 00032 /** Constructor. 00033 * @param name name of enumeration constant 00034 * @param comment comment of enumeration constant. 00035 */ 00036 InterfaceEnumConstant::InterfaceEnumConstant(const std::string &name, 00037 const std::string &comment) 00038 { 00039 __name = name; 00040 __comment = comment; 00041 __items.clear(); 00042 } 00043 00044 00045 /** Get name of enum constant. 00046 * @return name of enum constant. 00047 */ 00048 std::string 00049 InterfaceEnumConstant::get_name() 00050 { 00051 return __name; 00052 } 00053 00054 00055 /** Get comment of enum constant. 00056 * @return comment of enum constant. 00057 */ 00058 std::string 00059 InterfaceEnumConstant::get_comment() 00060 { 00061 return __comment; 00062 } 00063 00064 00065 /** Get enumeration items. 00066 * @return vector of enum items. First item in pair contains item name, second item 00067 * the comment. 00068 */ 00069 std::vector<InterfaceEnumConstant::EnumItem> 00070 InterfaceEnumConstant::get_items() 00071 { 00072 return __items; 00073 } 00074 00075 00076 /** Add an item without custom value. 00077 * @param name name of item 00078 * @param comment comment of item. 00079 */ 00080 void 00081 InterfaceEnumConstant::add_item(std::string name, std::string comment) 00082 { 00083 std::vector<EnumItem>::iterator i; 00084 for (i = __items.begin(); i != __items.end(); ++i) { 00085 if (i->name == name) { 00086 throw InterfaceGeneratorAmbiguousNameException(name.c_str(), "enum item"); 00087 } 00088 } 00089 EnumItem p = {name, comment, false, 0}; 00090 __items.push_back(p); 00091 } 00092 00093 00094 /** Add an item with custom value. 00095 * @param name name of item 00096 * @param comment comment of item. 00097 * @param value custom value 00098 */ 00099 void 00100 InterfaceEnumConstant::add_item(std::string name, std::string comment, int value) 00101 { 00102 std::vector<EnumItem>::iterator i; 00103 for (i = __items.begin(); i != __items.end(); ++i) { 00104 if (i->name == name) { 00105 throw InterfaceGeneratorAmbiguousNameException(name.c_str(), "enum item"); 00106 } 00107 } 00108 EnumItem p = {name, comment, true, value}; 00109 __items.push_back(p); 00110 }