Overture
Version 25
Main Page
Namespaces
Classes
Files
File List
File Members
Overture.v25.d
include
ListOfMappedGrid.h
Go to the documentation of this file.
1
#ifndef LISTOFMAPPEDGRID_H
2
#define LISTOFMAPPEDGRID_H "ListOfMappedGrid.h"
3
// *wdh* for pgi: 110529
4
#ifdef __PGI
5
#include "
GenericDataBase.h
"
6
#endif
7
class
MappedGrid
;
8
#include "
OvertureTypes.h
"
9
#include "
ReferenceCounting.h
"
10
11
//==========================================================================
12
// ListOfMappedGrid 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 MappedGrid to
16
// be used with this list must have the following characteristics:
17
//
18
// There must be member functions:
19
// MappedGrid::reference( const MappedGrid & t )
20
// MappedGrid::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 MappedGrid.
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
// ListOfMappedGrid<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
58
class
ListOfMappedGrid
:
public
ReferenceCounting
59
{
60
61
public
:
62
63
// Default constructor.
64
ListOfMappedGrid
();
65
66
// Create a list with a given number of elements
67
ListOfMappedGrid
(
const
int
numberOfElements );
68
69
// Copy constructor, deep copy by default
70
ListOfMappedGrid
(
const
ListOfMappedGrid
&,
71
const
CopyType
=
DEEP
);
72
73
~ListOfMappedGrid
();
// Destructor.
74
75
// Assignment operator (deep copy)
76
ListOfMappedGrid
&
operator=
(
const
ListOfMappedGrid
&);
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
MappedGrid
& t,
const
int
index );
// Add an object and reference to object t
85
86
void
addElement
(
const
MappedGrid
& 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
MappedGrid
&
operator[]
(
const
int
index)
const
;
// Reference the object at a given location.
92
93
void
deleteElement
(
const
MappedGrid
& 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
MappedGrid
& X)
const
;
104
105
// reference one list to another
106
void
reference
(
const
ListOfMappedGrid
& 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
ListOfMappedGrid
;
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
MappedGrid
**aList;
// Pointer to a list of pointers to object MappedGrid.
134
};
135
136
RCData
*
rcData
;
137
138
private
:
139
//
140
// Virtual member functions used only through class ReferenceCounting:
141
//
142
virtual
ReferenceCounting
&
operator=
(
const
ReferenceCounting
& x)
143
{
return
operator=
( (
ListOfMappedGrid
&)x); }
144
virtual
void
reference
(
const
ReferenceCounting
& x)
145
{
reference
( (
ListOfMappedGrid
&) x); }
146
virtual
ReferenceCounting
* virtualConstructor(
const
CopyType
ct =
DEEP
)
const
147
{ return ::new
ListOfMappedGrid
(*
this
, ct); }
148
};
149
150
#endif
Generated on Fri Jan 4 2013 10:17:55 for Overture by
1.8.3