/* * Open BEAGLE * Copyright (C) 2001-2005 by Christian Gagne and Marc Parizeau * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact: * Laboratoire de Vision et Systemes Numeriques * Departement de genie electrique et de genie informatique * Universite Laval, Quebec, Canada, G1K 7P4 * http://vision.gel.ulaval.ca * */ /*! * \file beagle/src/Map.cpp * \brief Source code of class Map. * \author Christian Gagne * \author Marc Parizeau * $Revision: 1.9 $ * $Date: 2005/10/04 09:32:52 $ */ #include "beagle/Beagle.hpp" #include using namespace Beagle; /*! * \brief Compare equality of two maps. * \param inRightObj Map to compare to this. * \return True if maps are equals, false if not. * \throw Beagle::BadCastException If compared maps Objects are not of the same type. * \par Note: * Returns true if the range [ 0, min(end(),inRightObj.end()) ) * are identical when compared element-by-element, and otherwise returns false. */ bool Map::isEqual(const Object& inRightObj) const { Beagle_StackTraceBeginM(); const Map& lRightMap = castObjectT(inRightObj); Map::const_iterator lFirstIter1 = begin(); unsigned int lSizeCompared = ( (size()(inRightObj); Map::const_iterator lFirstIter1 = begin(); unsigned int lSizeCompared = ( (size()getType()!=PACC::XML::eData) || (inIter->getValue()!="Map")) throw Beagle_IOExceptionNodeM(*inIter, "tag expected!"); for(PACC::XML::ConstIterator lChild=inIter->getFirstChild(); lChild; ++lChild) { if((lChild->getType()==PACC::XML::eData) && (lChild->getValue()=="Entry")) { string lKey = lChild->getAttribute("key").c_str(); if(lKey.empty()) throw Beagle_IOExceptionNodeM(*lChild, "no key attribute for actual entry!"); if(find(lKey) == end()) { std::ostringstream lOSS; lOSS << "entry \"" << lKey << "\" doesn't exist in current map!" << std::flush; throw Beagle_IOExceptionNodeM(*lChild, lOSS.str().c_str()); } PACC::XML::ConstIterator lChild2 = lChild->getFirstChild(); (*this)[lKey]->read(lChild2); } } Beagle_StackTraceEndM("void Map::read(PACC::XML::ConstIterator inIter)"); } /*! * \brief Write a map into a XML streamer. * \param ioStreamer XML streamer to read the Map to. * \param inIndent Whether XML output should be indented. */ void Map::write(PACC::XML::Streamer& ioStreamer, bool inIndent) const { Beagle_StackTraceBeginM(); ioStreamer.openTag("Map", inIndent); for(const_iterator lIter = begin(); lIter != end(); ++lIter) { ioStreamer.openTag("Entry", inIndent); ioStreamer.insertAttribute("key", lIter->first); lIter->second->write(ioStreamer, inIndent); ioStreamer.closeTag(); } ioStreamer.closeTag(); Beagle_StackTraceEndM("void Map::write(PACC::XML::Streamer& ioStreamer, bool inIndent) const"); }