constant.cpp

00001  
00002 /***************************************************************************
00003  *  constant.cpp - Interface generator constant representation
00004  *
00005  *  Generated: Wed Oct 11 15:33:39 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/constant.h>
00024 #include <interfaces/generator/type_checker.h>
00025 #include <interfaces/generator/exceptions.h>
00026 
00027 /** @class InterfaceConstant interfaces/generator/constant.h
00028  * Interface generator internal representation of a constant as parsed from
00029  * the XML template file.
00030  */
00031 
00032 
00033 /** Constructor
00034  * @param name name of constant
00035  * @param type type of constant
00036  * @param value value of constant
00037  * @param comment comment of message
00038  * @exception InterfaceGeneratorInvalidTypeException thrown if InterfaceDataTypeChecker
00039  * reports an invalid type.
00040  * @exception InterfaceGeneratorInvalidValueException thrown if InterfaceDataTypeChecker
00041  * reports an illegal value for the given type.
00042  */
00043 InterfaceConstant::InterfaceConstant(const std::string &name, const std::string &type,
00044                                      const std::string &value, const std::string &comment)
00045 {
00046   if ( ! InterfaceDataTypeChecker::validType(type) ) {
00047     throw InterfaceGeneratorInvalidTypeException("constant", name.c_str(), type.c_str());
00048   }
00049   if ( ! InterfaceDataTypeChecker::validValue(type, value) ) {
00050     throw InterfaceGeneratorInvalidValueException(name.c_str(), type.c_str(), value.c_str());
00051   }
00052 
00053   this->name  = name;
00054   this->type  = type;
00055   if ( type == "string" ) {
00056     this->value = std::string("\"") + value + "\"";
00057   } else {
00058     this->value = value;
00059   }
00060   this->comment = comment;
00061 }
00062 
00063 
00064 /** Get name of constant.
00065  * @return name of constant.
00066  */
00067 std::string
00068 InterfaceConstant::getName()
00069 {
00070   return name;
00071 }
00072 
00073 
00074 /** Get value of constant.
00075  * @return value of constant.
00076  */
00077 std::string
00078 InterfaceConstant::getValue()
00079 {
00080   return value;
00081 }
00082 
00083 
00084 /** Get type of constant.
00085  * @return type of constnat.
00086  */
00087 std::string
00088 InterfaceConstant::getType()
00089 {
00090   if (type == "string") {
00091     return "char *";
00092   } else if (type == "byte") {
00093     return "uint8_t";
00094   } else if (type == "float" || type == "double" || type == "bool") {
00095     return type;
00096   } else {
00097     return type + "_t";
00098   }
00099 }
00100 
00101 
00102 /** Get comment of constant.
00103  * @return comment of constant.
00104  */
00105 std::string
00106 InterfaceConstant::getComment()
00107 {
00108   return comment;
00109 }

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