Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Created on: 2002-04-17
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 // Purpose:     This is a base  class  for the  List, Set, Queue  and Stack
0017 //              collections. It offers operations on abstract lists (of the
0018 //              objects of class NCollection_ListNode).
0019 //              Apart from this class being  brand new (in TCollection said
0020 //              collections were independent, only using the same class for
0021 //              node representation),  here is an  important new  feature - 
0022 //              the  list  length is  continuously updated,  so the  method 
0023 //              Extent is quite quick.
0024 
0025 #ifndef NCollection_BaseList_HeaderFile
0026 #define NCollection_BaseList_HeaderFile
0027 
0028 #include <Standard_NoSuchObject.hxx>
0029 #include <NCollection_DefineAlloc.hxx>
0030 #include <NCollection_ListNode.hxx>
0031 
0032 typedef void (* NCollection_DelListNode) 
0033      (NCollection_ListNode*, Handle(NCollection_BaseAllocator)& theAl);
0034 
0035 // ********************************************************** BaseList class
0036 class NCollection_BaseList
0037 {
0038 public:
0039   //! Memory allocation
0040   DEFINE_STANDARD_ALLOC
0041   DEFINE_NCOLLECTION_ALLOC
0042 
0043 public:
0044   class Iterator
0045   {
0046   public:
0047     // ******** Empty constructor
0048     Iterator  (void) :
0049       myCurrent (NULL),
0050       myPrevious(NULL) {}
0051     // ******** Constructor with initialisation
0052     Iterator  (const NCollection_BaseList& theList) :
0053       myCurrent (theList.myFirst),
0054       myPrevious(NULL) {}
0055     // ******** Initialisation
0056     void Init (const NCollection_BaseList& theList)
0057     {
0058       myCurrent  = theList.myFirst;
0059       myPrevious = NULL;
0060     }
0061     // ******** Initialisation
0062     void Initialize (const NCollection_BaseList& theList)
0063     {
0064       Init(theList);
0065     }
0066     // ******** More
0067     Standard_Boolean More (void) const
0068     { return (myCurrent!=NULL); }
0069 
0070     // ******** Comparison operator
0071     Standard_Boolean operator== (const Iterator& theIt) const
0072     {
0073       return myCurrent == theIt.myCurrent;
0074     }
0075 
0076     //! Performs comparison of two iterators
0077     Standard_Boolean IsEqual (const Iterator& theOther) const
0078     {
0079       return *this == theOther;
0080     }
0081   protected:
0082     void Init (const NCollection_BaseList& theList,
0083                NCollection_ListNode * const thePrev)
0084     {
0085       myCurrent  = thePrev ? thePrev -> Next() :
0086                              (NCollection_ListNode *)theList.PLast();
0087       myPrevious = thePrev;
0088     }
0089   public:
0090     NCollection_ListNode * myCurrent; // Pointer to the current node
0091     NCollection_ListNode * myPrevious;// Pointer to the previous one
0092     friend class NCollection_BaseList;
0093   }; // End of nested class Iterator
0094 
0095  public:
0096   // ---------- PUBLIC METHODS ------------
0097   // ******** Extent
0098   // Purpose: Returns the number of nodes in the list
0099   Standard_Integer Extent (void) const
0100   { return myLength; }
0101 
0102   // ******** IsEmpty
0103   // Purpose: Query if the list is empty
0104   Standard_Boolean IsEmpty (void) const
0105   { return (myFirst == NULL); }
0106 
0107   // ******** Allocator
0108   //! Returns attached allocator
0109   const Handle(NCollection_BaseAllocator)& Allocator() const 
0110   { return myAllocator; }
0111 
0112   // ******** Destructor
0113   // Purpose: defines virtual interface
0114   virtual ~NCollection_BaseList (void)
0115   {}
0116 
0117  protected:
0118   // --------- PROTECTED METHODS ----------
0119 
0120   // ******** Constructor
0121   // Purpose: Initializes an empty list
0122   NCollection_BaseList (const Handle(NCollection_BaseAllocator)& theAllocator=0L) :
0123     myFirst(NULL),
0124     myLast(NULL),
0125     myLength(0)
0126   {
0127     myAllocator = (theAllocator.IsNull() ? NCollection_BaseAllocator::CommonBaseAllocator() : theAllocator);
0128   }
0129 
0130   // ******** PClear
0131   // Purpose: deletes all nodes
0132   Standard_EXPORT void PClear (NCollection_DelListNode fDel);
0133 
0134   // ******** PFirst
0135   // Purpose: Returns pointer to the first node
0136   const NCollection_ListNode* PFirst (void) const
0137   { return myFirst; }
0138 
0139   // ******** PLast
0140   // Purpose: Returns pointer to the last node
0141   const NCollection_ListNode* PLast (void) const
0142   { return myLast; }
0143 
0144   // ******** PAppend
0145   // Purpose: Appends theNode at the end
0146   Standard_EXPORT void PAppend (NCollection_ListNode* theNode);
0147 
0148   // ******** PAppend
0149   // Purpose: Appends theNode at the end, returns iterator to the previous
0150   void                 PAppend (NCollection_ListNode* theNode,
0151                                 Iterator&             theIt)
0152   {
0153     NCollection_ListNode * aPrev = myLast;
0154     PAppend (theNode);
0155     theIt.Init (* this, aPrev);
0156   }
0157 
0158   // ******** PAppend
0159   // Purpose: Appends theOther list at the end (clearing it)
0160   Standard_EXPORT void PAppend (NCollection_BaseList& theOther);
0161 
0162   // ******** PPrepend
0163   // Purpose: Prepends theNode at the beginning
0164   Standard_EXPORT void PPrepend (NCollection_ListNode* theNode);
0165 
0166   // ******** PPrepend
0167   // Purpose: Prepends theOther list at the beginning (clearing it)
0168   Standard_EXPORT void PPrepend (NCollection_BaseList& theOther);
0169 
0170   // ******** PRemoveFirst
0171   // Purpose: Removes first node
0172   Standard_EXPORT void PRemoveFirst 
0173     (NCollection_DelListNode fDel);
0174 
0175   // ******** PRemove
0176   // Purpose: Removes the node pointed by theIter[ator]
0177   Standard_EXPORT void PRemove 
0178     (Iterator& theIter,
0179      NCollection_DelListNode fDel);
0180 
0181   // ******** PInsertBefore
0182   // Purpose: Inserts theNode before one pointed by theIter[ator]
0183   Standard_EXPORT void PInsertBefore (NCollection_ListNode* theNode,
0184                                       Iterator& theIter);
0185 
0186   // ******** PInsertBefore
0187   // Purpose: Inserts theOther list before the node pointed by theIter[ator]
0188   Standard_EXPORT void PInsertBefore (NCollection_BaseList& theOther,
0189                                       Iterator& theIter);
0190 
0191   // ******** PInsertAfter
0192   // Purpose: Inserts theNode after one pointed by theIter[ator]
0193   Standard_EXPORT void PInsertAfter (NCollection_ListNode* theNode,
0194                                      Iterator& theIter);
0195 
0196   // ******** PInsertAfter
0197   // Purpose: Inserts theOther list after the node pointed by theIter[ator]
0198   Standard_EXPORT void PInsertAfter (NCollection_BaseList& theOther,
0199                                      Iterator& theIter);
0200 
0201   // ******** PReverse
0202   // Purpose: Reverse the list
0203   Standard_EXPORT void PReverse     ();
0204 
0205  protected:
0206   // ------------ PROTECTED FIELDS ------------
0207   Handle(NCollection_BaseAllocator) myAllocator;
0208   NCollection_ListNode * myFirst;  // Pointer to the head
0209   NCollection_ListNode * myLast;   // Pointer to the tail
0210   Standard_Integer       myLength; // Actual length
0211 
0212   // ------------ FRIEND CLASSES ------------
0213   friend class Iterator;
0214 };
0215 
0216 #endif