Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-17 09:21:21

0001 // Created on: 2002-04-10
0002 // Created by: Alexander KARTOMIN (akm)
0003 // Copyright (c) 2002-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef NCollection_BaseSequence_HeaderFile
0017 #define NCollection_BaseSequence_HeaderFile
0018 
0019 #include <Standard.hxx>
0020 #include <NCollection_BaseAllocator.hxx>
0021 #include <NCollection_DefineAlloc.hxx>
0022 
0023 // **************************************** Class SeqNode ********************
0024 
0025 class NCollection_SeqNode
0026 {
0027 public:
0028   // define new operator for use with NCollection allocators
0029   DEFINE_NCOLLECTION_ALLOC
0030 public:
0031   NCollection_SeqNode() noexcept
0032       : myNext(nullptr),
0033         myPrevious(nullptr)
0034   {
0035   }
0036 
0037   NCollection_SeqNode* Next() const noexcept { return myNext; }
0038 
0039   NCollection_SeqNode* Previous() const noexcept { return myPrevious; }
0040 
0041   void SetNext(NCollection_SeqNode* theNext) noexcept { myNext = theNext; }
0042 
0043   void SetPrevious(NCollection_SeqNode* thePrev) noexcept { myPrevious = thePrev; }
0044 
0045 private:
0046   NCollection_SeqNode* myNext;
0047   NCollection_SeqNode* myPrevious;
0048 };
0049 
0050 typedef void (*NCollection_DelSeqNode)(NCollection_SeqNode*,
0051                                        occ::handle<NCollection_BaseAllocator>& theAl);
0052 
0053 /**
0054  * Purpose:     This  is  a base  class  for  the  Sequence.  It  deals with
0055  *              an indexed bidirectional list of NCollection_SeqNode's.
0056  */
0057 class NCollection_BaseSequence
0058 {
0059 public:
0060   //! Memory allocation
0061   DEFINE_STANDARD_ALLOC
0062   DEFINE_NCOLLECTION_ALLOC
0063 
0064 public:
0065   class Iterator
0066   {
0067   public:
0068     //! Empty constructor
0069     Iterator() noexcept
0070         : myCurrent(nullptr),
0071           myPrevious(nullptr)
0072     {
0073     }
0074 
0075     //! Constructor with initialisation
0076     Iterator(const NCollection_BaseSequence& theSeq, const bool isStart) noexcept
0077     {
0078       Init(theSeq, isStart);
0079     }
0080 
0081     //! Initialisation
0082     void Init(const NCollection_BaseSequence& theSeq, const bool isStart = true) noexcept
0083     {
0084       myCurrent  = (isStart ? theSeq.myFirstItem : nullptr);
0085       myPrevious = (isStart ? nullptr : theSeq.myLastItem);
0086     }
0087 
0088     //! Switch to previous element; note that it will reset
0089     void Previous() noexcept
0090     {
0091       myCurrent = myPrevious;
0092       if (myCurrent)
0093         myPrevious = myCurrent->Previous();
0094     }
0095 
0096   protected:
0097     NCollection_SeqNode* myCurrent;  //!< Pointer to the current node
0098     NCollection_SeqNode* myPrevious; //!< Pointer to the previous node
0099     friend class NCollection_BaseSequence;
0100   };
0101 
0102 public:
0103   // Methods PUBLIC
0104   //
0105   bool IsEmpty() const noexcept { return (mySize == 0); }
0106 
0107   //! Number of items (legacy int-returning API).
0108   int Length() const noexcept { return static_cast<int>(mySize); }
0109 
0110   //! Size - number of items.
0111   size_t Size() const noexcept { return mySize; }
0112 
0113   //! Returns attached allocator
0114   const occ::handle<NCollection_BaseAllocator>& Allocator() const noexcept { return myAllocator; }
0115 
0116 protected:
0117   // Methods PROTECTED
0118   //
0119   NCollection_BaseSequence(const occ::handle<NCollection_BaseAllocator>& theAllocator)
0120       : myFirstItem(nullptr),
0121         myLastItem(nullptr),
0122         myCurrentItem(nullptr),
0123         myCurrentIndex(0),
0124         mySize(0)
0125   {
0126     myAllocator =
0127       (theAllocator.IsNull() ? NCollection_BaseAllocator::CommonBaseAllocator() : theAllocator);
0128   }
0129 
0130   //! Destructor
0131   virtual ~NCollection_BaseSequence() = default;
0132 
0133   Standard_EXPORT void ClearSeq(NCollection_DelSeqNode fDel);
0134   Standard_EXPORT void PAppend(NCollection_SeqNode*);
0135   Standard_EXPORT void PAppend(NCollection_BaseSequence& S);
0136   Standard_EXPORT void PPrepend(NCollection_SeqNode*);
0137   Standard_EXPORT void PPrepend(NCollection_BaseSequence& S);
0138   Standard_EXPORT void PInsertAfter(Iterator& thePosition, NCollection_SeqNode*);
0139   Standard_EXPORT void PInsertAfter(const size_t Index, NCollection_SeqNode*);
0140   Standard_EXPORT void PInsertAfter(const size_t Index, NCollection_BaseSequence& S);
0141   Standard_EXPORT void PSplit(const size_t Index, NCollection_BaseSequence& Sub);
0142   Standard_EXPORT void RemoveSeq(Iterator& thePosition, NCollection_DelSeqNode fDel);
0143   Standard_EXPORT void RemoveSeq(const size_t Index, NCollection_DelSeqNode fDel);
0144   Standard_EXPORT void RemoveSeq(const size_t From, const size_t To, NCollection_DelSeqNode fDel);
0145   Standard_EXPORT void PReverse() noexcept;
0146   Standard_EXPORT void PExchange(const size_t I, const size_t J);
0147   Standard_EXPORT NCollection_SeqNode* Find(const size_t) const noexcept;
0148 
0149 protected:
0150   // Fields PROTECTED
0151   //
0152   occ::handle<NCollection_BaseAllocator> myAllocator;
0153   NCollection_SeqNode*                   myFirstItem;
0154   NCollection_SeqNode*                   myLastItem;
0155   NCollection_SeqNode*                   myCurrentItem;
0156   size_t                                 myCurrentIndex;
0157   size_t                                 mySize;
0158 
0159 private:
0160   // Methods PRIVATE
0161   //
0162   NCollection_BaseSequence(const NCollection_BaseSequence& Other) = delete;
0163 
0164   void Nullify() noexcept
0165   {
0166     myFirstItem = myLastItem = myCurrentItem = nullptr;
0167     myCurrentIndex = mySize = 0;
0168   }
0169 
0170   friend class Iterator;
0171 };
0172 
0173 #endif