X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FGeomAPI%2FGeomAPI_DataMapOfShapeMapOfShapes.cpp;h=a7497c0dc511501d449e667aa10c8c486263b47e;hb=3c3a34a6515ac15f7cb8a77e2f307d3835b72b78;hp=05a6b70945ba2897300e9dbb50362204cc5880c2;hpb=2532fb2df83ee1ddd9ff3e8b381d3788eaa15b69;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_DataMapOfShapeMapOfShapes.cpp b/src/GeomAPI/GeomAPI_DataMapOfShapeMapOfShapes.cpp index 05a6b7094..a7497c0dc 100644 --- a/src/GeomAPI/GeomAPI_DataMapOfShapeMapOfShapes.cpp +++ b/src/GeomAPI/GeomAPI_DataMapOfShapeMapOfShapes.cpp @@ -14,7 +14,8 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com // #include @@ -23,7 +24,8 @@ #include #include -#define MY_MAP implPtr > >() +typedef NCollection_DataMap > MAP; +#define MY_MAP implPtr() //================================================================================================= GeomAPI_DataMapOfShapeMapOfShapes::GeomAPI_DataMapOfShapeMapOfShapes() @@ -112,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()); +}