Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:19

0001 // Copyright (c) 2023 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef NCollection_Iterator_HeaderFile
0015 #define NCollection_Iterator_HeaderFile
0016 
0017 #include <Standard_Assert.hxx>
0018 #include <iterator>
0019 
0020 //! Helper class that allows to use NCollection iterators as STL iterators.
0021 //! NCollection iterator can be extended to STL iterator of any category by
0022 //! adding necessary methods: STL forward iterator requires IsEqual method,
0023 //! STL bidirectional iterator requires Previous method, and STL random access
0024 //! iterator requires Offset and Differ methods. See NCollection_Vector as
0025 //! example of declaring custom STL iterators.
0026 template<class Container>
0027 class NCollection_Iterator
0028 {
0029 public:
0030 
0031   NCollection_Iterator() : myCur(typename Container::iterator()), myLast(typename Container::iterator()) {}
0032 
0033   NCollection_Iterator(const NCollection_Iterator& theOther) : myCur(theOther.myCur), myLast(theOther.myLast) {}
0034 
0035   NCollection_Iterator(const Container& theList) : myCur(const_cast<Container&>(theList).begin()), myLast(const_cast<Container&>(theList).end()) {}
0036 
0037   NCollection_Iterator(const Container& theList, const typename Container::iterator& theOther)
0038     : myCur(theOther), myLast(const_cast<Container&>(theList).end()) {}
0039 
0040   NCollection_Iterator(const Container& theList, typename Container::iterator&& theOther)
0041     : myCur(theOther), myLast(const_cast<Container&>(theList).end())
0042   {}
0043 
0044   ~NCollection_Iterator() {}
0045 
0046   void Init(Container& theList)
0047   {
0048     myCur = theList.begin();
0049     myLast = theList.end();
0050   }
0051 
0052   void Init(const Container& theList)
0053   {
0054     Init(const_cast<Container&>(theList));
0055   }
0056 
0057   virtual bool More() const
0058   {
0059     return myCur != myLast;
0060   }
0061 
0062   void Initialize(Container& theList)
0063   {
0064     Init(theList);
0065   }
0066 
0067   void Initialize(const Container& theList)
0068   {
0069     Init(theList);
0070   }
0071 
0072   const typename Container::iterator& ValueIter() const
0073   {
0074     return myCur;
0075   }
0076 
0077   typename Container::iterator& ChangeValueIter()
0078   {
0079     return myCur;
0080   }
0081 
0082   const typename Container::iterator& EndIter() const
0083   {
0084     return myLast;
0085   }
0086 
0087   typename Container::iterator& ChangeEndIter()
0088   {
0089     return myLast;
0090   }
0091 
0092   virtual void Next()
0093   {
0094     ++(myCur);
0095   }
0096 
0097   const typename Container::const_reference Value() const
0098   {
0099     return *myCur;
0100   }
0101 
0102   const typename Container::reference ChangeValue()
0103   {
0104     return *myCur;
0105   }
0106 
0107   bool operator==(const NCollection_Iterator& theOther) { return myLast == theOther.myLast && myCur == theOther.myCur; }
0108 
0109   bool operator!=(const NCollection_Iterator& theOther) { return myLast != theOther.myLast || myCur != theOther.myCur; }
0110 
0111   NCollection_Iterator& operator=(const NCollection_Iterator& theOther)
0112   {
0113     if (this != &theOther)
0114     {
0115       myLast = theOther.myLast;
0116       myCur = theOther.myCur;
0117     }
0118     return *this;
0119   }
0120 
0121   NCollection_Iterator& operator=(NCollection_Iterator&& theOther)
0122   {
0123     if (this != &theOther)
0124     {
0125       myLast = std::move(theOther.myLast);
0126       myCur = std::move(theOther.myCur);
0127     }
0128     return *this;
0129   }
0130 
0131 private:
0132   typename Container::iterator myCur;
0133   typename Container::iterator myLast;
0134 };
0135 
0136 
0137 #endif // NCollection_Iterator_HeaderFile