Back to home page

EIC code displayed by LXR

 
 

    


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

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 () : myNext (NULL), myPrevious (NULL) {}
0032   NCollection_SeqNode * Next      () const { return myNext; }
0033   NCollection_SeqNode * Previous  () const { return myPrevious; }
0034   void SetNext     (NCollection_SeqNode * theNext) { myNext = theNext; }
0035   void SetPrevious (NCollection_SeqNode * thePrev) { myPrevious = thePrev; }
0036   
0037  private:
0038   NCollection_SeqNode* myNext;
0039   NCollection_SeqNode* myPrevious;
0040 };
0041 
0042 typedef void (* NCollection_DelSeqNode) 
0043      (NCollection_SeqNode*, Handle(NCollection_BaseAllocator)& theAl);
0044 
0045 /**
0046  * Purpose:     This  is  a base  class  for  the  Sequence.  It  deals with
0047  *              an indexed bidirectional list of NCollection_SeqNode's.
0048  */              
0049 class NCollection_BaseSequence 
0050 {
0051 public:
0052   //! Memory allocation
0053   DEFINE_STANDARD_ALLOC
0054   DEFINE_NCOLLECTION_ALLOC
0055 
0056 public:
0057   class Iterator
0058   {
0059   public:
0060     //! Empty constructor
0061     Iterator (void) : myCurrent (NULL), myPrevious(NULL) {}
0062 
0063     //! Constructor with initialisation
0064     Iterator (const NCollection_BaseSequence& theSeq,
0065               const Standard_Boolean isStart)
0066     {
0067       Init (theSeq, isStart);
0068     }
0069 
0070      //! Initialisation
0071     void Init (const NCollection_BaseSequence& theSeq,
0072                const Standard_Boolean isStart = Standard_True)
0073     {
0074       myCurrent  = (isStart ? theSeq.myFirstItem : NULL);
0075       myPrevious = (isStart ? NULL : theSeq.myLastItem);
0076     }
0077 
0078     //! Switch to previous element; note that it will reset 
0079     void Previous()
0080     {
0081       myCurrent = myPrevious;
0082       if (myCurrent)
0083         myPrevious = myCurrent->Previous();
0084     }
0085       
0086   protected:
0087     NCollection_SeqNode* myCurrent;  //!< Pointer to the current node
0088     NCollection_SeqNode* myPrevious; //!< Pointer to the previous node
0089     friend class NCollection_BaseSequence;
0090   };
0091 
0092  public:
0093   // Methods PUBLIC
0094   // 
0095       Standard_Boolean   IsEmpty     () const {return (mySize == 0);}
0096       Standard_Integer   Length      () const {return mySize;}
0097 
0098       //! Returns attached allocator
0099       const Handle(NCollection_BaseAllocator)& Allocator() const
0100       { return myAllocator; }
0101 
0102  protected:
0103   // Methods PROTECTED
0104   // 
0105   NCollection_BaseSequence (const Handle(NCollection_BaseAllocator)& theAllocator) :
0106     myFirstItem        (NULL),
0107     myLastItem         (NULL),
0108     myCurrentItem      (NULL),
0109     myCurrentIndex     (0),
0110     mySize             (0)
0111   {
0112     myAllocator = (theAllocator.IsNull() ? NCollection_BaseAllocator::CommonBaseAllocator() : theAllocator);
0113   }
0114 
0115   //! Destructor
0116   virtual ~NCollection_BaseSequence() {}
0117 
0118   Standard_EXPORT void   ClearSeq    (NCollection_DelSeqNode fDel);
0119   Standard_EXPORT void   PAppend     (NCollection_SeqNode *);
0120   Standard_EXPORT void   PAppend     (NCollection_BaseSequence& S);
0121   Standard_EXPORT void   PPrepend    (NCollection_SeqNode *);
0122   Standard_EXPORT void   PPrepend    (NCollection_BaseSequence& S);
0123   Standard_EXPORT void   PInsertAfter(Iterator& thePosition,
0124                                       NCollection_SeqNode *);
0125   Standard_EXPORT void   PInsertAfter(const Standard_Integer Index,
0126                                       NCollection_SeqNode *);
0127   Standard_EXPORT void   PInsertAfter(const Standard_Integer Index,
0128                                       NCollection_BaseSequence& S);
0129   Standard_EXPORT void   PSplit      (const Standard_Integer Index,
0130                                       NCollection_BaseSequence& Sub);
0131   Standard_EXPORT void   RemoveSeq   (Iterator& thePosition,
0132                                       NCollection_DelSeqNode fDel);
0133   Standard_EXPORT void   RemoveSeq   (const Standard_Integer Index,
0134                                       NCollection_DelSeqNode fDel);
0135   Standard_EXPORT void   RemoveSeq   (const Standard_Integer From,
0136                                       const Standard_Integer To,
0137                                       NCollection_DelSeqNode fDel);
0138   Standard_EXPORT void   PReverse    ();
0139   Standard_EXPORT void   PExchange   (const Standard_Integer I,
0140                                       const Standard_Integer J) ;
0141   Standard_EXPORT NCollection_SeqNode *
0142                          Find        (const Standard_Integer) const;
0143 
0144  protected:
0145   // Fields PROTECTED
0146   //
0147   Handle(NCollection_BaseAllocator) myAllocator;
0148   NCollection_SeqNode* myFirstItem;
0149   NCollection_SeqNode* myLastItem;
0150   NCollection_SeqNode* myCurrentItem;
0151   Standard_Integer myCurrentIndex;
0152   Standard_Integer mySize;
0153 
0154  private: 
0155   // Methods PRIVATE
0156   // 
0157   Standard_EXPORT NCollection_BaseSequence
0158                            (const NCollection_BaseSequence& Other);
0159   void Nullify()
0160   {
0161     myFirstItem = myLastItem = myCurrentItem = NULL;
0162     myCurrentIndex = mySize = 0;
0163   }
0164 
0165   friend class Iterator;
0166 };
0167 
0168 #endif