SUMOSAXAttributesImpl_Xerces.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Encapsulated Xerces-SAX-attributes
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 
00020 
00021 // ===========================================================================
00022 // included modules
00023 // ===========================================================================
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029 
00030 #include <cassert>
00031 #include <xercesc/sax2/Attributes.hpp>
00032 #include <xercesc/sax2/DefaultHandler.hpp>
00033 #include "SUMOSAXAttributesImpl_Xerces.h"
00034 #include <utils/common/TplConvert.h>
00035 #include <utils/common/TplConvertSec.h>
00036 
00037 #ifdef CHECK_MEMORY_LEAKS
00038 #include <foreign/nvwa/debug_new.h>
00039 #endif // CHECK_MEMORY_LEAKS
00040 
00041 
00042 // ===========================================================================
00043 // class definitions
00044 // ===========================================================================
00045 SUMOSAXAttributesImpl_Xerces::SUMOSAXAttributesImpl_Xerces(const Attributes &attrs,
00046         const std::map<SumoXMLAttr, XMLCh*> &predefinedTags,
00047         const std::map<SumoXMLAttr, std::string> &predefinedTagsMML) throw()
00048         : myAttrs(attrs), myPredefinedTags(predefinedTags),
00049         myPredefinedTagsMML(predefinedTagsMML) { }
00050 
00051 
00052 
00053 SUMOSAXAttributesImpl_Xerces::~SUMOSAXAttributesImpl_Xerces() throw() {
00054 }
00055 
00056 bool
00057 SUMOSAXAttributesImpl_Xerces::hasAttribute(SumoXMLAttr id) const throw() {
00058     AttrMap::const_iterator i=myPredefinedTags.find(id);
00059     if (i==myPredefinedTags.end()) {
00060         return false;
00061     }
00062     return myAttrs.getIndex((*i).second)>=0;
00063 }
00064 
00065 
00066 bool
00067 SUMOSAXAttributesImpl_Xerces::getBool(SumoXMLAttr id) const throw(EmptyData, BoolFormatException) {
00068     return TplConvert<XMLCh>::_2bool(getAttributeValueSecure(id));
00069 }
00070 
00071 
00072 bool
00073 SUMOSAXAttributesImpl_Xerces::getBoolSecure(SumoXMLAttr id, bool val) const throw(EmptyData) {
00074     return TplConvertSec<XMLCh>::_2boolSec(getAttributeValueSecure(id), val);
00075 }
00076 
00077 
00078 int
00079 SUMOSAXAttributesImpl_Xerces::getInt(SumoXMLAttr id) const throw(EmptyData, NumberFormatException) {
00080     return TplConvert<XMLCh>::_2int(getAttributeValueSecure(id));
00081 }
00082 
00083 
00084 int
00085 SUMOSAXAttributesImpl_Xerces::getIntSecure(SumoXMLAttr id,
00086         int def) const throw(EmptyData, NumberFormatException) {
00087     return TplConvertSec<XMLCh>::_2intSec(getAttributeValueSecure(id), def);
00088 }
00089 
00090 
00091 std::string
00092 SUMOSAXAttributesImpl_Xerces::getString(SumoXMLAttr id) const throw(EmptyData) {
00093     return TplConvert<XMLCh>::_2str(getAttributeValueSecure(id));
00094 }
00095 
00096 
00097 std::string
00098 SUMOSAXAttributesImpl_Xerces::getStringSecure(SumoXMLAttr id,
00099         const std::string &str) const throw(EmptyData) {
00100     return TplConvertSec<XMLCh>::_2strSec(getAttributeValueSecure(id), str);
00101 }
00102 
00103 
00104 SUMOReal
00105 SUMOSAXAttributesImpl_Xerces::getFloat(SumoXMLAttr id) const throw(EmptyData, NumberFormatException) {
00106     return TplConvert<XMLCh>::_2SUMOReal(getAttributeValueSecure(id));
00107 }
00108 
00109 
00110 SUMOReal
00111 SUMOSAXAttributesImpl_Xerces::getFloatSecure(SumoXMLAttr id,
00112         SUMOReal def) const throw(EmptyData, NumberFormatException) {
00113     return TplConvertSec<XMLCh>::_2SUMORealSec(getAttributeValueSecure(id), def);
00114 }
00115 
00116 
00117 const XMLCh *
00118 SUMOSAXAttributesImpl_Xerces::getAttributeValueSecure(SumoXMLAttr id) const throw() {
00119     AttrMap::const_iterator i=myPredefinedTags.find(id);
00120     assert(i!=myPredefinedTags.end());
00121     return myAttrs.getValue((*i).second);
00122 }
00123 
00124 
00125 SUMOReal
00126 SUMOSAXAttributesImpl_Xerces::getFloat(const std::string &id) const throw(EmptyData, NumberFormatException) {
00127     XMLCh *t = XMLString::transcode(id.c_str());
00128     return TplConvert<XMLCh>::_2SUMOReal(myAttrs.getValue(t));
00129 }
00130 
00131 
00132 bool
00133 SUMOSAXAttributesImpl_Xerces::hasAttribute(const std::string &id) const throw() {
00134     XMLCh *t = XMLString::transcode(id.c_str());
00135     return myAttrs.getIndex(t)>=0;
00136 }
00137 
00138 
00139 std::string
00140 SUMOSAXAttributesImpl_Xerces::getStringSecure(const std::string &id,
00141         const std::string &str) const throw() {
00142     XMLCh *t = XMLString::transcode(id.c_str());
00143     return TplConvertSec<XMLCh>::_2strSec(myAttrs.getValue(t), str);
00144 }
00145 
00146 
00147 std::string
00148 SUMOSAXAttributesImpl_Xerces::getName(SumoXMLAttr attr) const throw() {
00149     if (myPredefinedTagsMML.find(attr)==myPredefinedTagsMML.end()) {
00150         return "?";
00151     }
00152     return myPredefinedTagsMML.find(attr)->second;
00153 }
00154 
00155 
00156 /****************************************************************************/
00157 

Generated on Wed May 5 00:06:36 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6