/******************************************************************************* * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * * version 0.1 * * Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg * * * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * * * Web site: http://cgogn.u-strasbg.fr/ * * Contact information: cgogn@unistra.fr * * * *******************************************************************************/ namespace CGoGN { template void AttributeHandler::registerInMap() { m_map->attributeHandlers.insert(std::pair(m_attrib, this)) ; } template void AttributeHandler::unregisterFromMap() { typedef std::multimap::iterator IT ; std::pair bounds = m_map->attributeHandlers.equal_range(m_attrib) ; for(IT i = bounds.first; i != bounds.second; ++i) { if((*i).second == this) { m_map->attributeHandlers.erase(i) ; return ; } } assert(false || !"Should not get here") ; } // ================================================================= template AttributeHandler::AttributeHandler() : AttributeHandlerGen(NULL, false), m_attrib(NULL) {} template AttributeHandler::AttributeHandler(GenericMap* m, AttributeMultiVector* amv) : AttributeHandlerGen(m, false), m_attrib(amv) { if(amv != NULL && amv->getIndex() != AttributeContainer::UNKNOWN) { valid = true ; registerInMap() ; } else valid = false ; } template AttributeHandler::AttributeHandler(const AttributeHandler& ta) : AttributeHandlerGen(ta.m_map, ta.valid), m_attrib(ta.m_attrib) { if(valid) registerInMap() ; } template inline void AttributeHandler::operator=(const AttributeHandler& ta) { if(valid) unregisterFromMap() ; m_map = ta.m_map ; m_attrib = ta.m_attrib ; valid = ta.valid ; if(valid) registerInMap() ; } template AttributeHandler::~AttributeHandler() { if(valid) unregisterFromMap() ; } template AttributeMultiVector* AttributeHandler::getDataVector() const { return m_attrib ; } template unsigned int AttributeHandler::getOrbit() const { return m_attrib->getOrbit() ; } template unsigned int AttributeHandler::getIndex() const { return m_attrib->getIndex() ; } template const std::string& AttributeHandler::name() const { return m_attrib->getName() ; } template inline T& AttributeHandler::operator[](Dart d) { assert(valid || !"Invalid AttributeHandler") ; unsigned int orbit = m_attrib->getOrbit() ; unsigned int a = m_map->getEmbedding(orbit, d) ; if (a == EMBNULL) a = m_map->embedNewCell(orbit, d) ; return m_attrib->operator[](a) ; } template inline const T& AttributeHandler::operator[](Dart d) const { assert(valid || !"Invalid AttributeHandler") ; unsigned int a = m_map->getEmbedding(m_attrib->getOrbit(), d) ; return m_attrib->operator[](a) ; } template inline T& AttributeHandler::operator[](unsigned int a) { assert(valid || !"Invalid AttributeHandler") ; return m_attrib->operator[](a) ; } template inline const T& AttributeHandler::operator[](unsigned int a) const { assert(valid || !"Invalid AttributeHandler") ; return m_attrib->operator[](a) ; } template inline unsigned int AttributeHandler::insert(const T& elt) { assert(valid || !"Invalid AttributeHandler") ; unsigned int idx = m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine() ; m_attrib->operator[](idx) = elt ; return idx ; } template inline unsigned int AttributeHandler::newElt() { assert(valid || !"Invalid AttributeHandler") ; unsigned int idx = m_map->getAttributeContainer(m_attrib->getOrbit()).insertLine() ; return idx ; } template inline void AttributeHandler::setAllValues(T& v) { for(unsigned int i = begin(); i != end(); next(i)) m_attrib->operator[](i) = v ; } template inline unsigned int AttributeHandler::begin() const { assert(valid || !"Invalid AttributeHandler") ; return m_map->getAttributeContainer(m_attrib->getOrbit()).begin() ; } template inline unsigned int AttributeHandler::end() const { assert(valid || !"Invalid AttributeHandler") ; return m_map->getAttributeContainer(m_attrib->getOrbit()).end() ; } template inline void AttributeHandler::next(unsigned int& iter) const { assert(valid || !"Invalid AttributeHandler") ; m_map->getAttributeContainer(m_attrib->getOrbit()).next(iter) ; } } //namespace CGoGN