pseudomap.cpp

00001  
00002 /***************************************************************************
00003  *  pseudomap.cpp - Interface generator pseudo representation
00004  *
00005  *  Created: Thu Nov 20 15:09:23 2008
00006  *  Copyright  2006-2008  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/pseudomap.h>
00024 #include <interfaces/generator/type_checker.h>
00025 #include <interfaces/generator/exceptions.h>
00026 
00027 #include <cstdlib>
00028 
00029 
00030 /** @class InterfacePseudoMap "pseudomap.h"
00031  * Interface generator internal representation of a pseudo map as parsed from
00032  * the XML template file.
00033  * @author Tim Niemueller
00034  */
00035 
00036 
00037 /** Constructor.
00038  * @param name name of the pseudo map
00039  * @param type type of the values in the map
00040  * @param keytype type of the keys
00041  * @param comment comment of the pseudo map
00042  */
00043 InterfacePseudoMap::InterfacePseudoMap(std::string name, std::string type,
00044                                        std::string keytype, std::string comment)
00045 {
00046   __name = name;
00047   __type = type;
00048   __keytype = keytype;
00049   __comment = comment;
00050 }
00051 
00052 
00053 /** Get name of field.
00054  * @return name of field.
00055  */
00056 std::string
00057 InterfacePseudoMap::getName() const
00058 {
00059   return __name;
00060 }
00061 
00062 
00063 /** Get type of field.
00064  * @return type of field.
00065  */
00066 std::string
00067 InterfacePseudoMap::getType() const
00068 {
00069     return __type;
00070 }
00071 
00072 
00073 /** Get comment of field.
00074  * @return comment of field.
00075  */
00076 std::string
00077 InterfacePseudoMap::getComment() const
00078 {
00079     return __comment;
00080 }
00081 
00082 
00083 /** Get type of key value.
00084  * @return type of key
00085  */
00086 std::string
00087 InterfacePseudoMap::getKeyType() const
00088 {
00089   return __keytype + "_t";
00090 }
00091 
00092 
00093 
00094 /** Assert validity.
00095  * Calling valid() acts like an assertion. An Exception is thrown if something is wrong.
00096  * @exception InterfaceGeneratorInvalidTypeException thrown if InterfaceDataTypeChecker
00097  * reports invalid type.
00098  * @exception InterfaceGeneratorInvalidValueException thrown if any supplied value is
00099  * illegal.
00100  * @exception InterfaceGeneratorInvalidFlagException thrown if invalid flag has been
00101  * supplied.
00102  */
00103 void
00104 InterfacePseudoMap::valid()
00105 {
00106   if ( (__name.length() == 0) || (__name.find(" ") != std::string::npos) ) {
00107     throw InterfaceGeneratorInvalidValueException("name", "string", "name must neither be empty nor contain spaces");
00108   }
00109   if (__type.length() == 0) {
00110     throw InterfaceGeneratorInvalidValueException("type", "string", "type must not be empty");
00111   }
00112   if ( (__keytype != "int8") && (__keytype != "int16") &&
00113        (__keytype != "int32") && (__keytype != "int64") &&
00114        (__keytype != "uint8") && (__keytype != "uint16") &&
00115        (__keytype != "uint32") && (__keytype != "uint64") ) {
00116     throw InterfaceGeneratorInvalidValueException("keytype", "string", "Pseudo map keys can only be of a numeric type");
00117   }
00118   if (__keytype.length() == 0) {
00119     throw InterfaceGeneratorInvalidValueException("keytype", "string", "key type must not be empty");
00120   }
00121 }
00122 
00123 
00124 /** Add reference.
00125  * @param fieldname name of the field that is referenced
00126  * @param key key of the field in the pseudo map
00127  */
00128 void
00129 InterfacePseudoMap::addRef(std::string fieldname, std::string key)
00130 {
00131   __parefs.push_back(make_pair(fieldname, key));
00132 }
00133 
00134 
00135 /** Get reference list.
00136  * @return reference list
00137  */
00138 InterfacePseudoMap::RefList &
00139 InterfacePseudoMap::getRefList()
00140 {
00141   return __parefs;
00142 }

Generated on Tue Feb 22 13:31:23 2011 for Fawkes API by  doxygen 1.4.7