SALOME - SMESH
NCollection_BaseCollection.hxx
Go to the documentation of this file.
1 // Created on: 2002-04-09
2 // Created by: Alexander KARTOMIN (akm)
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15 
16 #ifndef NCollection_BaseCollection_HeaderFile
17 #define NCollection_BaseCollection_HeaderFile
18 
19 #include <NCollection_IncAllocator.hxx>
20 #include <NCollection_DefineAlloc.hxx>
21 
44 template<class TheItemType> class NCollection_BaseCollection
45 {
46  public:
47  // **************** The interface for iterating over collections
48  class Iterator
49  {
50  public:
52  virtual Standard_Boolean More(void) const=0;
54  virtual void Next(void)=0;
56  virtual const TheItemType& Value(void) const=0;
58  virtual TheItemType& ChangeValue(void) const=0;
59  public:
60  DEFINE_STANDARD_ALLOC
61  DEFINE_NCOLLECTION_ALLOC
62  protected:
64  Iterator (void) {}
66  virtual ~Iterator (void) {}
67  protected:
69  const Iterator& operator= (const Iterator&);
71  Iterator (const Iterator&) {}
72  }; // End of nested class Iterator
73 
74  public:
75  // ---------- PUBLIC METHODS ------------
76 
79  (const Handle(NCollection_BaseAllocator)& theAllocator=0L)
80  {
81  if (theAllocator.IsNull())
82  myAllocator = NCollection_BaseAllocator::CommonBaseAllocator();
83  else
84  myAllocator = theAllocator;
85  }
86 
88  virtual Standard_Integer Size(void) const = 0;
89 
91  virtual void Assign
92  (const NCollection_BaseCollection& theOther)=0;
93 
95  virtual Iterator& CreateIterator(void) const=0;
96 
98  virtual ~NCollection_BaseCollection (void) {}
99 
101  const Handle(NCollection_BaseAllocator)& Allocator() const { return myAllocator; }
102 
103  protected:
104  // --------- PROTECTED METHOD -----------
105  const Handle(NCollection_BaseAllocator)& IterAllocator(void) const
106  {
107  if (myIterAllocator.IsNull())
108  (Handle_NCollection_BaseAllocator&) myIterAllocator =
109  new NCollection_IncAllocator(64);
110  return myIterAllocator;
111  }
112 
115  {
116  std::swap (myAllocator, theOther.myAllocator);
117  std::swap (myIterAllocator, theOther.myIterAllocator);
118  }
119 
120  protected:
121  // --------- PROTECTED FIELDS -----------
122  Handle(NCollection_BaseAllocator) myAllocator;
123  private:
124  // ---------- PRIVATE FIELDS ------------
125  Handle(NCollection_BaseAllocator) myIterAllocator;
126 
127 };
128 
129 #endif
virtual ~Iterator(void)
Virtual destructor is necessary for classes with virtual methods.
NCollection_BaseCollection(const Handle(NCollection_BaseAllocator)&theAllocator=0L)
Common for all collections constructor takes care of theAllocator.
void exchangeAllocators(NCollection_BaseCollection &theOther)
Exchange allocators of two collections.
virtual Standard_Integer Size(void) const =0
Number of items.
Iterator(const Iterator &)
Copy constructor **.
virtual Standard_Boolean More(void) const =0
Query if the end of collection is reached by iterator.
const Handle(NCollection_BaseAllocator) &IterAllocator(void) const
virtual void Assign(const NCollection_BaseCollection &theOther)=0
Virtual assignment.
const Iterator & operator=(const Iterator &)
operator= is prohibited
Purpose: NCollection_BaseCollection is the base abstract class for all collection templates of this p...
const Handle(NCollection_BaseAllocator) &Allocator() const
Returns attached allocator.
virtual ~NCollection_BaseCollection(void)
Destructor - must be implemented to release the memory.
virtual TheItemType & ChangeValue(void) const =0
Value change access.
virtual const TheItemType & Value(void) const =0
Value inquiry.
virtual Iterator & CreateIterator(void) const =0
Method to create iterators for base collections.
virtual void Next(void)=0
Make a step along the collection.