//-------------------------------------------------------------------------- // File and Version Information: // $Id: AstNamedMapVector.cc,v 1.1.1.1 2005/03/29 16:49:05 steinke Exp $ // // Description: // Class AstNamedMapVector // Very simple class to provide an association between two // pointer types which don't obviously belong together in a class, // but need to go together for some reason. // // Environment: // Software developed for the BaBar Detector at the SLAC B-Factory. // // Author List: // Phil Strother Original author // // Copyright Information: // Copyright (C) 1999 LBNL // //------------------------------------------------------------------------ //----------------------- // This Class's Header -- //----------------------- #include "AstNamedMapVector.h" //------------- // C Headers -- //------------- extern "C" { } //--------------- // C++ Headers -- //--------------- #include #include //------------------------------- // Collaborating Class Headers -- //------------------------------- //----------------------------------------------------------------------- // Local Macros, Typedefs, Structures, Unions and Forward Declarations -- //----------------------------------------------------------------------- // ---------------------------------------- // -- Public Function Member Definitions -- // ---------------------------------------- //---------------- // Constructors -- //---------------- template AstNamedMapVector::AstNamedMapVector(const std::string &name): _myName(new std::string(name)), _vectorOne(new std::vector()), _vectorTwo(new std::vector()) {} template AstNamedMapVector::AstNamedMapVector(const std::string &name, unsigned (*fn1)(const T1&), unsigned (*fn2)(const T2&)): AstUniqMap2(fn1, fn2), _myName(new std::string(name)), _vectorOne(new std::vector()), _vectorTwo(new std::vector()) {} template AstNamedMapVector::AstNamedMapVector(const std::string &name, unsigned (*fn1)(const T1&), unsigned (*fn2)(const T2&), size_t buckets): AstUniqMap2(fn1, fn2, buckets), _myName(new std::string(name)), _vectorOne(new std::vector()), _vectorTwo(new std::vector()) { } // Copy constructor template AstNamedMapVector< T1, T2>::AstNamedMapVector(const AstNamedMapVector &other): AstUniqMap2(other) { _myName = new std::string(other.name()); _vectorOne = new std::vector(other.list1()); _vectorTwo = new std::vector(other.list2()); } //-------------- // Destructor -- //-------------- template AstNamedMapVector< T1, T2>::~AstNamedMapVector() { delete _myName; delete _vectorOne; delete _vectorTwo; } //------------- // Methods -- //------------- template bool AstNamedMapVector< T1, T2>::append(T1* theT1, T2* theT2){ if (!AstUniqMap2::append(theT1, theT2)) return false; _vectorOne->push_back(theT1); _vectorTwo->push_back(theT2); return true; } template T2* AstNamedMapVector< T1, T2>::remove1(const T1* theT1){ T2 *theT2 = AstUniqMap2::remove1(theT1); if (theT2 != 0){ typename std::vector::iterator posT1 = std::find( _vectorOne->begin(), _vectorOne->end(), theT1 ); typename std::vector::iterator posT2 = std::find( _vectorTwo->begin(), _vectorTwo->end(), theT2 ); if (posT1 != _vectorOne->end() && posT2 != _vectorTwo->end() ) { _vectorOne->erase(posT1); _vectorTwo->erase(posT2); } // _vectorOne->remove(theT1); // _vectorTwo->remove(theT2); } return theT2; } template T1* AstNamedMapVector< T1, T2>::remove2(const T2* theT2){ T1 *theT1 = AstUniqMap2::remove2(theT2); if (theT1 != 0){ typename std::vector::iterator posT1 = std::find( _vectorOne->begin(), _vectorOne->end(), theT1 ); typename std::vector::iterator posT2 = std::find( _vectorTwo->begin(), _vectorTwo->end(), theT2 ); if (posT1 != _vectorOne->end() && posT2 != _vectorTwo->end() ) { _vectorOne->erase(posT1); _vectorTwo->erase(posT2); } // _vectorOne->remove(theT1); // _vectorTwo->remove(theT2); } return theT1; } //------------- // Operators -- //------------- template AstNamedMapVector & AstNamedMapVector::operator=(const AstNamedMapVector &other) { if (this != &other){ AstUniqMap2::operator=(other); delete _myName; delete _vectorOne; delete _vectorTwo; _myName = new std::string(other.name()); _vectorOne = new std::vector(other.list1()); _vectorTwo = new std::vector(other.list2()); } return *this; } template bool AstNamedMapVector::operator==(const AstNamedMapVector &other) const { // May look overly simplistic. But the assumption is that the name // _uniquely_ identifies the map for a given T1, T2. return (_myName == other._myName); } template bool AstNamedMapVector::operator!=(const AstNamedMapVector &other) const { return (! (*this==other)); } //------------- // Selectors -- //------------- //------------- // Modifiers -- //------------- template void AstNamedMapVector::clear() { AstUniqMap2::clear(); _vectorOne->clear(); _vectorTwo->clear(); } template void AstNamedMapVector::clearAndDestroy() { AstUniqMap2::clearAndDestroy(); _vectorOne->clear(); _vectorTwo->clear(); } // ----------------------------------------------- // -- Static Data & Function Member Definitions -- // ----------------------------------------------- // ------------------------------------------- // -- Protected Function Member Definitions -- // ------------------------------------------- // ----------------------------------------- // -- Private Function Member Definitions -- // ----------------------------------------- // ----------------------------------- // -- Internal Function Definitions -- // -----------------------------------