X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAPI%2FGeomAPI_DataMapOfShapeMapOfShapes.cpp;h=a7497c0dc511501d449e667aa10c8c486263b47e;hb=696c11e9e4cb089e1c5496dac79420147d85496a;hp=d5132057c681ba2403233e98076ec0c0d364d2a4;hpb=87b6a30a3afb8fb32e7e43ade8d9c947d9eb1684;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_DataMapOfShapeMapOfShapes.cpp b/src/GeomAPI/GeomAPI_DataMapOfShapeMapOfShapes.cpp index d5132057c..a7497c0dc 100644 --- a/src/GeomAPI/GeomAPI_DataMapOfShapeMapOfShapes.cpp +++ b/src/GeomAPI/GeomAPI_DataMapOfShapeMapOfShapes.cpp @@ -24,7 +24,8 @@ #include #include -#define MY_MAP implPtr > >() +typedef NCollection_DataMap > MAP; +#define MY_MAP implPtr() //================================================================================================= GeomAPI_DataMapOfShapeMapOfShapes::GeomAPI_DataMapOfShapeMapOfShapes() @@ -113,3 +114,158 @@ int GeomAPI_DataMapOfShapeMapOfShapes::size() const { return MY_MAP->Size(); } + + +//================================================================================================= +// iterator implementation +//================================================================================================= + +class IteratorImpl : public GeomAPI_DataMapOfShapeMapOfShapes::iterator +{ +public: + IteratorImpl() {} + + IteratorImpl(const MAP::Iterator& theIterator) + : myIterator(theIterator) + {} + + IteratorImpl(const std::shared_ptr& theIterator) + { + mySelf = theIterator; + } + + bool operator==(const std::shared_ptr& theOther) const + { + if (theOther) + return theOther->myIterator.IsEqual(myIterator); + + // theOther is end iterator => check the current iterator is not at the end + return !myIterator.More(); + } + + virtual iterator& operator++() + { + myIterator.Next(); + return *this; + } + virtual iterator operator++(int) + { + std::shared_ptr aSelf = std::dynamic_pointer_cast(mySelf); + std::shared_ptr aCopy(new IteratorImpl(aSelf->myIterator)); + myIterator.Next(); + return IteratorImpl(aCopy); + } + + virtual key_type first() const + { + if (mySelf) + return iterator::first(); + + GeomShapePtr aShape(new GeomAPI_Shape); + aShape->setImpl(new TopoDS_Shape(myIterator.Key())); + return aShape; + } + + virtual mapped_type second() const + { + if (mySelf) + return iterator::second(); + + ListOfShape anItems; + const NCollection_Map& aMap = myIterator.Value(); + for(NCollection_Map::Iterator anIt(aMap); anIt.More(); anIt.Next()) { + std::shared_ptr aShape(new GeomAPI_Shape); + aShape->setImpl(new TopoDS_Shape(anIt.Value())); + anItems.push_back(aShape); + } + return anItems; + } + +private: + MAP::Iterator myIterator; +}; + + +GeomAPI_DataMapOfShapeMapOfShapes::iterator::iterator() +{ +} + +GeomAPI_DataMapOfShapeMapOfShapes::iterator::iterator( + const GeomAPI_DataMapOfShapeMapOfShapes::iterator& theOther) + : mySelf(theOther.mySelf) +{ +} + +const GeomAPI_DataMapOfShapeMapOfShapes::iterator& + GeomAPI_DataMapOfShapeMapOfShapes::iterator::operator=( + const GeomAPI_DataMapOfShapeMapOfShapes::iterator& theOther) +{ + mySelf = theOther.mySelf; + return *this; +} + +bool GeomAPI_DataMapOfShapeMapOfShapes::iterator::operator==(const iterator& theOther) const +{ + std::shared_ptr aSelf = std::dynamic_pointer_cast(mySelf); + std::shared_ptr aSelfOther = + std::dynamic_pointer_cast(theOther.mySelf); + + return aSelf ? aSelf->operator==(aSelfOther) + : (aSelfOther ? aSelfOther->operator==(aSelf) : true); +} + +bool GeomAPI_DataMapOfShapeMapOfShapes::iterator::operator!=(const iterator& theOther) const +{ + return !operator==(theOther); +} + +GeomAPI_DataMapOfShapeMapOfShapes::iterator& + GeomAPI_DataMapOfShapeMapOfShapes::iterator::operator++() +{ + mySelf->operator++(); + return *this; +} + +GeomAPI_DataMapOfShapeMapOfShapes::iterator + GeomAPI_DataMapOfShapeMapOfShapes::iterator::operator++(int) +{ + return ++(*mySelf); +} + +GeomAPI_DataMapOfShapeMapOfShapes::iterator::key_type + GeomAPI_DataMapOfShapeMapOfShapes::iterator::first() const +{ + return mySelf->first(); +} + +GeomAPI_DataMapOfShapeMapOfShapes::iterator::mapped_type + GeomAPI_DataMapOfShapeMapOfShapes::iterator::second() const +{ + return mySelf->second(); +} + + + +GeomAPI_DataMapOfShapeMapOfShapes::iterator GeomAPI_DataMapOfShapeMapOfShapes::begin() +{ + MAP::Iterator anIt(*MY_MAP); + std::shared_ptr anIter(new IteratorImpl(anIt)); + return IteratorImpl(anIter); +} + +GeomAPI_DataMapOfShapeMapOfShapes::const_iterator GeomAPI_DataMapOfShapeMapOfShapes::begin() const +{ + MAP::Iterator anIt(*MY_MAP); + std::shared_ptr anIter(new IteratorImpl(anIt)); + return IteratorImpl(anIter); +} + +GeomAPI_DataMapOfShapeMapOfShapes::iterator GeomAPI_DataMapOfShapeMapOfShapes::end() +{ + return IteratorImpl(std::shared_ptr()); +} + +GeomAPI_DataMapOfShapeMapOfShapes::const_iterator GeomAPI_DataMapOfShapeMapOfShapes::end() const +{ + return IteratorImpl(std::shared_ptr()); +}