OWLNext
7.0
Borland's Object Windows Library for the modern age
Toggle main menu visibility
Loading...
Searching...
No Matches
contain.h
Go to the documentation of this file.
1
//------------------------------------------------------------------------------
2
// ObjectWindows
3
// Copyright (c) 1993, 1996 by Borland International, All Rights Reserved
4
//
5
/// \file
6
/// Definition of container classes used and made available by OWL
7
//------------------------------------------------------------------------------
8
9
#if !defined(OWL_CONTAIN_H)
10
#define OWL_CONTAIN_H
11
12
#include <
owl/private/defs.h
>
13
#if defined(BI_HAS_PRAGMA_ONCE)
14
# pragma once
15
#endif
16
17
#include <
owl/defs.h
>
18
#include <
owl/template.h
>
19
20
//class TStandardAllocator;
21
22
namespace
owl
{
23
24
//------------------------------------------------------------------------------
25
//class _OWLCLASS TStandardAllocator;
26
//template <class T, class T1> class TPtrArrayIterator;
27
//template <class T, class P, class A> class TTypedArray;
28
//template <class T, class T1> class TObjArrayIterator;
29
//template <class T> class TObjectArray;
30
//template <class T> class TSortedObjectArray;
31
//template <class T, class T1> class TMapNode;
32
33
typedef
TTypedArray<int,int,TStandardAllocator>
TIntArray
;
34
typedef
TPtrArrayIterator<int,TIntArray>
TIntArrayIterator
;
35
typedef
TTypedArray<uint32,uint32,TStandardAllocator>
TUint32Array
;
36
typedef
TPtrArrayIterator<uint32,TUint32Array>
TUint32ArrayIterator
;
37
typedef
TObjectArray<tstring>
TStringArray
;
38
typedef
TObjArrayIterator<tstring,TStringArray>
TStringArrayIterator
;
39
typedef
TSortedObjectArray<tstring>
TSortedStringArray
;
40
typedef
TObjArrayIterator<tstring, TSortedStringArray>
TSortedStringArrayIterator
;
41
typedef
int
TInt
;
// for portability
42
43
typedef
TTypedArray<LPARAM, LPARAM, TStandardAllocator>
TLParamArray
;
44
typedef
TPtrArrayIterator<LPARAM, TLParamArray>
TLParamArrayIterator
;
45
46
#if defined(_OWLDLL) || defined(BI_APP_DLL)
47
//
48
// Export templates when building ObjectWindows DLL and provide import
49
// declaration of DLL instance for users of the class.
50
//
51
//template class _OWLCLASS TMapNode<string,string>;
52
//template class _OWLCLASS TObjectArray< TMapNode<string,string> >;
53
//template class _OWLCLASS TSortedObjectArray< TMapNode<string,string> >;
54
#endif
// _OWLDLL || BI_APP_DLL
55
56
//------------------------------------------------------------------------------
57
58
//
59
/// Maximum number of entries in each Vector
60
//
61
const
uint
MAXENTRIES
=
uint
((
uint32
(UINT_MAX) -
sizeof
(
uint
))/
62
sizeof
(
void
*));
63
64
#include <
owl/preclass.h
>
65
//
66
/// \class TCollection
67
// ~~~~~ ~~~~~~~~~~~
68
/// Simple template holding pointers to Ts used internally by
69
/// ObjectWindows Controls
70
//
71
template
<
class
T>
class
TCollection
{
72
public
:
73
TCollection
(
uint
aLimit,
bool
shldDel =
true
);
74
~TCollection
();
75
76
T&
operator []
(
uint
index)
const
;
77
int
GetCount
()
const
;
78
79
int
Append
(T* item);
80
void
InsertAt
(
uint
index, T* item);
81
void
RemoveAt
(
uint
index);
82
void
RemoveAll
();
83
void
FreeAt
(
uint
index);
84
void
FreeAll
();
85
86
protected
:
87
void
SetLimit
(
uint
aLimit);
88
89
private
:
90
TCollection
(
const
TCollection
&);
91
TCollection
& operator =(
const
TCollection
&);
92
93
void
FreeItem(T* item);
94
T** items;
///< Pointer to array of T*
95
uint
count;
///< Number of items
96
uint
limit;
///< Size array is allocated for
97
bool
shouldDelete;
///< Should free in destructor
98
};
99
100
#include <
owl/posclass.h
>
101
102
103
//------------------------------------------------------------------------------
104
// Inline implementations
105
//
106
107
//
108
template
<
class
T>
109
TCollection<T>::TCollection
(
uint
aLimit,
bool
shldDel)
110
: items(0), count(0), limit(0), shouldDelete(shldDel)
111
{
112
SetLimit
(aLimit);
113
}
114
115
//
116
template
<
class
T>
117
TCollection<T>::~TCollection
()
118
{
119
if
(shouldDelete)
120
FreeAll
();
121
SetLimit
(0);
122
}
123
124
//
125
template
<
class
T>
126
int
TCollection<T>::GetCount
()
const
127
{
128
return
count;
129
}
130
131
//
132
template
<
class
T>
133
void
TCollection<T>::RemoveAll
()
134
{
135
count = 0;
136
}
137
138
//
139
template
<
class
T>
140
T&
TCollection<T>::operator[]
(
uint
index)
const
141
{
142
PRECONDITION
(index < count);
143
return
*items[index];
144
}
145
146
//
147
template
<
class
T>
148
int
TCollection<T>::Append
(T* item)
149
{
150
InsertAt
(count, item);
151
return
count-1;
152
}
153
154
//
155
template
<
class
T>
156
void
TCollection<T>::InsertAt
(
uint
index, T* item)
157
{
158
PRECONDITION
(index <= count);
159
if
(count == limit)
160
SetLimit
(count*2);
161
if
(count-index != 0)
162
memmove(
reinterpret_cast<
void
*
>
(&items[index+1]),
reinterpret_cast<
void
*
>
(&items[index]),
163
(count-index)*
sizeof
(T*));
164
items[index] = item;
165
count++;
166
}
167
168
//
169
template
<
class
T>
170
void
TCollection<T>::RemoveAt
(
uint
index)
171
{
172
PRECONDITION
(index < count);
173
if
(index != count-1)
174
memmove(
reinterpret_cast<
void
*
>
(&items[index]),
reinterpret_cast<
void
*
>
(&items[index+1]),
175
(count-(index+1))*
sizeof
(T*));
176
count--;
177
}
178
179
//
180
template
<
class
T>
181
void
TCollection<T>::FreeAt
(
uint
index)
182
{
183
T& item =
operator[]
(index);
184
RemoveAt
(index);
185
FreeItem(&item);
186
}
187
188
//
189
template
<
class
T>
190
void
TCollection<T>::FreeAll
()
191
{
192
for
(
uint
i = 0; i < count; i++)
193
FreeItem(&(
operator
[](i)));
194
count = 0;
195
}
196
197
//
198
template
<
class
T>
199
void
TCollection<T>::FreeItem(T* item)
200
{
201
delete
item;
202
}
203
204
//
205
template
<
class
T>
206
void
TCollection<T>::SetLimit
(
uint
aLimit)
207
{
208
if
(aLimit < count)
209
aLimit = count;
210
CHECK
(aLimit <=
MAXENTRIES
);
211
212
if
(aLimit != limit) {
213
T **aItems;
214
215
if
(aLimit == 0)
216
aItems = 0;
217
else
{
218
aItems =
new
T *[aLimit];
219
if
(count != 0)
220
memcpy(aItems, items, count*
sizeof
(T*));
221
}
222
delete
[] items;
223
items = aItems;
224
limit = aLimit;
225
}
226
}
227
228
229
}
// OWL namespace
230
231
232
#endif
// OWL_CONTAIN_H
CHECK
#define CHECK(condition)
Definition
checks.h:239
PRECONDITION
#define PRECONDITION(condition)
Definition
checks.h:227
owl::TCollection::RemoveAt
void RemoveAt(uint index)
Definition
contain.h:170
owl::TCollection::Append
int Append(T *item)
Definition
contain.h:148
owl::TCollection::FreeAt
void FreeAt(uint index)
Definition
contain.h:181
owl::TCollection::TCollection
TCollection(uint aLimit, bool shldDel=true)
Definition
contain.h:109
owl::TCollection::~TCollection
~TCollection()
Definition
contain.h:117
owl::TCollection::InsertAt
void InsertAt(uint index, T *item)
Definition
contain.h:156
owl::TCollection::SetLimit
void SetLimit(uint aLimit)
Definition
contain.h:206
owl::TCollection::operator[]
T & operator[](uint index) const
Definition
contain.h:140
owl::TCollection::RemoveAll
void RemoveAll()
Definition
contain.h:133
owl::TCollection::FreeAll
void FreeAll()
Definition
contain.h:190
owl::TCollection::GetCount
int GetCount() const
Definition
contain.h:126
owl::TObjArrayIterator
Iterator for TObjectContainer.
Definition
template.h:576
owl::TObjectArray
Definition
template.h:755
owl::TPtrArrayIterator
Iterator for Pointer Container.
Definition
template.h:602
owl::TSortedObjectArray
Definition
template.h:816
owl::TTypedArray
Stores pointer to object.
Definition
template.h:848
owl
Object Windows Library (OWLNext Core).
Definition
animctrl.h:22
owl::TIntArray
TTypedArray< int, int, TStandardAllocator > TIntArray
Definition
contain.h:33
owl::TStringArray
TObjectArray< tstring > TStringArray
Definition
contain.h:37
owl::TLParamArrayIterator
TPtrArrayIterator< LPARAM, TLParamArray > TLParamArrayIterator
Definition
contain.h:44
owl::TSortedStringArray
TSortedObjectArray< tstring > TSortedStringArray
Definition
contain.h:39
owl::TInt
int TInt
Definition
contain.h:41
owl::TUint32ArrayIterator
TPtrArrayIterator< uint32, TUint32Array > TUint32ArrayIterator
Definition
contain.h:36
owl::uint32
unsigned long uint32
Definition
number.h:34
owl::TUint32Array
TTypedArray< uint32, uint32, TStandardAllocator > TUint32Array
Definition
contain.h:35
owl::TSortedStringArrayIterator
TObjArrayIterator< tstring, TSortedStringArray > TSortedStringArrayIterator
Definition
contain.h:40
owl::TStringArrayIterator
TObjArrayIterator< tstring, TStringArray > TStringArrayIterator
Definition
contain.h:38
owl::TLParamArray
TTypedArray< LPARAM, LPARAM, TStandardAllocator > TLParamArray
Definition
contain.h:43
owl::TIntArrayIterator
TPtrArrayIterator< int, TIntArray > TIntArrayIterator
Definition
contain.h:34
owl::uint
unsigned int uint
Definition
number.h:25
owl::MAXENTRIES
const uint MAXENTRIES
Maximum number of entries in each Vector.
Definition
contain.h:61
defs.h
General definitions used by all ObjectWindows programs.
defs.h
posclass.h
preclass.h
template.h
Definition of container classes used and made available by OWL.
include
owl
contain.h
Generated by
1.18.0