enum_constant.cpp

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   this->name  = name;
00040   this->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::getName()
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::getComment()
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< std::pair< std::string,std::string > >
00070 InterfaceEnumConstant::getItems()
00071 {
00072   return items;
00073 }
00074 
00075 
00076 /** Add an item.
00077  * @param name name of item
00078  * @param comment comment of item.
00079  */
00080 void
00081 InterfaceEnumConstant::addItem(std::string name, std::string comment)
00082 {
00083   for ( std::vector< std::pair< std::string, std::string > >::iterator i = items.begin(); i != items.end(); ++i) {
00084     if ( (*i).first == name ) {
00085       throw InterfaceGeneratorAmbiguousNameException(name.c_str(), "enum item");
00086     }
00087   }
00088   std::pair< std::string, std::string > p(name, comment);
00089   items.push_back(p);
00090 }

Generated on Tue Feb 22 13:32:24 2011 for Fawkes API by  doxygen 1.4.7