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;
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 != "unsigned int") && (__keytype != "int") &&
00113        (__keytype != "long unsigned int") && (__keytype != "long int") ) {
00114     throw InterfaceGeneratorInvalidValueException("keytype", "string", "Pseudo map keyes can only be of a numeric type");
00115   }
00116   if (__keytype.length() == 0) {
00117     throw InterfaceGeneratorInvalidValueException("keytype", "string", "key type must not be empty");
00118   }
00119 }
00120
00121 
00122 /** Add reference.
00123  * @param fieldname name of the field that is referenced
00124  * @param key key of the field in the pseudo map
00125  */
00126 void
00127 InterfacePseudoMap::addRef(std::string fieldname, std::string key)
00128 {
00129   __parefs.push_back(make_pair(fieldname, key));
00130 }
00131
00132 
00133 /** Get reference list.
00134  * @return reference list
00135  */
00136 InterfacePseudoMap::RefList &
00137 InterfacePseudoMap::getRefList()
00138 {
00139   return __parefs;
00140 }