Overture  Version 25
ListOfCompositeGrid.h
Go to the documentation of this file.
1 #ifndef LISTOFCOMPOSITEGRID_H
2 #define LISTOFCOMPOSITEGRID_H "ListOfCompositeGrid.h"
3 // *wdh* for pgi: 110529
4 #ifdef __PGI
5  #include "GenericDataBase.h"
6 #endif
7 class CompositeGrid;
8 #include "OvertureTypes.h"
9 #include "ReferenceCounting.h"
10 
11 //==========================================================================
12 // ListOfCompositeGrid Class Template
13 //
14 // This is a template list class for holding items that are reference
15 // counted in the style of A++ arrays. In particular, any class CompositeGrid to
16 // be used with this list must have the following characteristics:
17 //
18 // There must be member functions:
19 // CompositeGrid::reference( const CompositeGrid & t )
20 // CompositeGrid::breakReference()
21 // that behave in the same way as A++ arrays.
22 // In addition the assignment operator "=" must be deep copy.
23 //
24 // This class keeps an array of pointers to objects of class CompositeGrid.
25 // The array is dynamic so that only
26 // memory and time limit the number of objects stored on the list.
27 //
28 // Reference Counting
29 // This class supports two types of reference counting. The suggested
30 // way to do reference counting is to use the reference and breakReference
31 // member functions as shown in the examples below. If instead you want
32 // to keep pointers to ListOfReferenceObjects then you can use the
33 // incrementReferenceCount(), decrementReferenceCount() and
34 // getReferenceCount() member functions (derived from the ReferenceCounting
35 // in order to mange references). It is up to you to call delete when
36 // the reference count reaches zero.
37 //
38 // Typical Usage:
39 //
40 // floatArray a(10),b(5);
41 // ListOfCompositeGrid<floatArray> list,list2;
42 // list.addElement(); // add an element
43 // list[0].reference(a); // reference to array a
44 // list.addElement(b); // add element and reference to b in one step
45 // list[1]=b;
46 // list[0]=1.; // same as a=1.;
47 //
48 // list2.reference(list); // list2 and list are now the same
49 // list2[0]=2.; // same as list[0]=2.;
50 // list2.breakReference();
51 // list2[0]=5.; // does not change list[0]
52 //
53 //
54 // Authors: Jeff Saltzman and Bill Henshaw
55 //
56 //==========================================================================
57 
59 {
60 
61  public:
62 
63  // Default constructor.
65 
66  // Create a list with a given number of elements
67  ListOfCompositeGrid( const int numberOfElements );
68 
69  // Copy constructor, deep copy by default
71  const CopyType=DEEP );
72 
73  ~ListOfCompositeGrid(); // Destructor.
74 
75  // Assignment operator (deep copy)
77 
78  // ---------List Management Functions-------------
79 
80  void addElement( const int index ); // Add an object to the list
81 
82  void addElement(); // Add an object to the end of the list
83 
84  void addElement( const CompositeGrid & t, const int index ); // Add an object and reference to object t
85 
86  void addElement( const CompositeGrid & t ); // Add an object to the end, and reference to object t
87 
88  int getLength() const // Get length of list.
89  {return rcData->listLength;};
90 
91  CompositeGrid& operator[](const int index) const; // Reference the object at a given location.
92 
93  void deleteElement( const CompositeGrid & X ); // Find an element on the list and delete it.
94 
95  void deleteElement( const int index ); // Delete the element at the given index
96 
97  void deleteElement(); // Delete the element appearing last in the list
98 
99  void destroy(); // Destroy the list
100 
101  void swapElements( const int i, const int j ); // Swap two elements (for sorting)
102 
103  int getIndex(const CompositeGrid & X) const;
104 
105  // reference one list to another
106  void reference( const ListOfCompositeGrid & list );
107 
108  // break any references with this list
109  void breakReference();
110 
111  protected:
112 
113  void initialize();
114  void deleteStuff();
115 
116  // create space so a new element can be inserted
117  void openAPositionForAnElement( const int index );
118 
119  void checkRange( const int ) const; // Internal range check function.
120 
121 // private:
122  public:
123  int listLength() const
124  {return rcData->listLength;}; // Get length of list.
125 
126  class RCData : public ReferenceCounting // holds reference counted data except A++ arrays
127  {
128  friend class ListOfCompositeGrid;
129  RCData(){ }
130  ~RCData(){ }
131  int listLength; // Number of elements in the list.
132  int memAlloc; // Current amount of memory allocated for the list.
133  CompositeGrid **aList; // Pointer to a list of pointers to object CompositeGrid.
134  };
135 
137 
138  private:
139 //
140 // Virtual member functions used only through class ReferenceCounting:
141 //
143  { return operator=( (ListOfCompositeGrid &)x); }
144  virtual void reference( const ReferenceCounting& x)
145  { reference( (ListOfCompositeGrid &) x); }
146  virtual ReferenceCounting* virtualConstructor( const CopyType ct = DEEP ) const
147  { return ::new ListOfCompositeGrid(*this, ct); }
148 };
149 
150 #endif