Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-27 09:43:42

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   NCollection_Iterator()
0031       : myCur(typename Container::iterator()),
0032         myLast(typename Container::iterator())
0033   {
0034   }
0035 
0036   NCollection_Iterator(const NCollection_Iterator& theOther)
0037       : myCur(theOther.myCur),
0038         myLast(theOther.myLast)
0039   {
0040   }
0041 
0042   NCollection_Iterator(const Container& theList)
0043       : myCur(const_cast<Container&>(theList).begin()),
0044         myLast(const_cast<Container&>(theList).end())
0045   {
0046   }
0047 
0048   NCollection_Iterator(const Container& theList, const typename Container::iterator& theOther)
0049       : myCur(theOther),
0050         myLast(const_cast<Container&>(theList).end())
0051   {
0052   }
0053 
0054   NCollection_Iterator(const Container& theList, typename Container::iterator&& theOther)
0055       : myCur(theOther),
0056         myLast(const_cast<Container&>(theList).end())
0057   {
0058   }
0059 
0060   ~NCollection_Iterator() {}
0061 
0062   void Init(Container& theList)
0063   {
0064     myCur  = theList.begin();
0065     myLast = theList.end();
0066   }
0067 
0068   void Init(const Container& theList) { Init(const_cast<Container&>(theList)); }
0069 
0070   virtual bool More() const { return myCur != myLast; }
0071 
0072   void Initialize(Container& theList) { Init(theList); }
0073 
0074   void Initialize(const Container& theList) { Init(theList); }
0075 
0076   const typename Container::iterator& ValueIter() const { return myCur; }
0077 
0078   typename Container::iterator& ChangeValueIter() { return myCur; }
0079 
0080   const typename Container::iterator& EndIter() const { return myLast; }
0081 
0082   typename Container::iterator& ChangeEndIter() { return myLast; }
0083 
0084   virtual void Next() { ++(myCur); }
0085 
0086   const typename Container::const_reference Value() const { return *myCur; }
0087 
0088   const typename Container::reference ChangeValue() { return *myCur; }
0089 
0090   bool operator==(const NCollection_Iterator& theOther)
0091   {
0092     return myLast == theOther.myLast && myCur == theOther.myCur;
0093   }
0094 
0095   bool operator!=(const NCollection_Iterator& theOther)
0096   {
0097     return myLast != theOther.myLast || myCur != theOther.myCur;
0098   }
0099 
0100   NCollection_Iterator& operator=(const NCollection_Iterator& theOther)
0101   {
0102     if (this != &theOther)
0103     {
0104       myLast = theOther.myLast;
0105       myCur  = theOther.myCur;
0106     }
0107     return *this;
0108   }
0109 
0110   NCollection_Iterator& operator=(NCollection_Iterator&& theOther)
0111   {
0112     if (this != &theOther)
0113     {
0114       myLast = std::move(theOther.myLast);
0115       myCur  = std::move(theOther.myCur);
0116     }
0117     return *this;
0118   }
0119 
0120 private:
0121   typename Container::iterator myCur;
0122   typename Container::iterator myLast;
0123 };
0124 
0125 #endif // NCollection_Iterator_HeaderFile