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