OOFILE  1.9
oofarray.h
Go to the documentation of this file.
1 #ifndef H_OOFARRAY
2 #define H_OOFARRAY
3 
4 // COPYRIGHT 1997 A.D. Software, All rights reserved
5 
6 // array classes for OOFILE database
7 
8 // NOTE inline definitions included at end of this header file
9 
10 #ifndef H_OOF0
11  #include "oof0.h"
12 #endif
13 #if !defined(OOF_NO_STDLIB) && !defined(H_OOFIOS)
14  #include "oofios.h" // just to provide ostream for OOF_ExpandableLongArray::describe(std::ostream&)
15 #endif
16 
21 class OOFILE_EXPORT OOF_ExpandableLongArray { // this would be a good candidate to template-ize
22 public:
23  OOF_ExpandableLongArray(unsigned long defaultValue=0, unsigned long numSlots=0, unsigned int expandBySlots=4);
25  virtual ~OOF_ExpandableLongArray();
26 
28 #ifndef OOF_NO_STDLIB
29  void describe(std::ostream&) const;
30 #endif
31 
32 // access protocol
33  void append(unsigned long);
34  void deleteItem(unsigned long index);
35  void deleteFirstMatching(unsigned long value);
36  void deleteAllMatching(unsigned long value);
37  void deleteAllCells(bool alwaysDeleteStorage=false);
38  bool contains(unsigned long value) const;
39  bool find(unsigned long value, unsigned long& foundAt) const;
40  unsigned long& operator[](unsigned long index);
41  unsigned long value(unsigned long index) const;
42  unsigned long& item(unsigned long index);
43 
44 
45  // iterator protocol
46  void start();
47  bool more() const;
48  void next();
49  unsigned long count() const;
50  unsigned long index() const;
51  unsigned long countOccurrences(unsigned long) const;
52  unsigned long& operator()();
53 
54 protected:
55  bool Invariant() const;
56  void ExpandToInclude(unsigned long indexToCover);
57  void DeleteBits();
58  void CopyBits(const OOF_ExpandableLongArray& rhs); // used in copy constructor & operator=
59 
60 // data storage
61  unsigned long* mBits; // owned
62  unsigned long mDefaultValue;
63  unsigned long mNextFreeEntry, mNumSlots, mInternalIter;
64  unsigned int mExpansionChunk;
65 
66 };
68 
69 
77 public:
78  oofArray(unsigned long slotSize, unsigned long numSlots=0, unsigned int expandBySlots=4);
79  oofArray(const oofArray& rhs);
80  virtual ~oofArray();
81  // to invoke your DeleteBits must override dtor and
82  // set mBits to 0 to avoid double-delete
83 
84  oofArray& operator=(const oofArray&);
85 
86  // iterator protocol
87  void start();
88  bool more() const;
89  void next();
90  unsigned long count() const;
91 
92 protected:
93  bool Invariant() const;
94  unsigned long AllocSlot();
95  void ExpandToInclude(unsigned long indexToCover);
96 
97 // user overrides
98  virtual void* AllocBits(unsigned long) const=0;
99  virtual void DeleteBits(bool becauseExpanding)=0;
100  virtual void* CloneBits() const; // has default implementation based on bit-level copy
101 
102 // data storage
103  void** mUserStorage; // optional so user can have typed pointer
104  void* mBits; // owned
105  unsigned long mNextFreeEntry, mNumSlots, mInternalIter, mSlotSize;
106  unsigned int mExpansionChunk;
107 
108 };
109 
110 // -------------------------------------------------------
111 // O O F _ E x p a n d a b l e L o n g A r r a y
112 // -------------------------------------------------------
113 
118 inline bool
120 {
121  return (mBits==0 || (mNumSlots>0 && mNextFreeEntry <= mNumSlots));
122 }
123 
124 
125 inline unsigned long
127 {
128  return mNextFreeEntry;
129 }
130 
131 
132 inline unsigned long
134 {
135  return mInternalIter;
136 }
137 
138 
139 inline void
141 {
142  mInternalIter = 0;
143 }
144 
145 
146 inline bool
148 {
149  return mInternalIter < mNextFreeEntry;
150 }
151 
152 
153 inline void
155 {
156  mInternalIter++;
157 }
158 
159 
160 inline unsigned long&
162 {
163  return operator[](mInternalIter);
164 }
165 
166 
167 inline unsigned long&
168 OOF_ExpandableLongArray::item(unsigned long inIndex)
169 {
170  return operator[](inIndex);
171 }
172 
173 
174 
175 // -------------------------------------------------------
176 // o o f A r r a y
177 // -------------------------------------------------------
182 inline bool
184 {
185  return (mBits==0 || (mNumSlots>0 && mNextFreeEntry <= mNumSlots));
186 }
187 
188 
189 inline unsigned long
191 {
192  return mNextFreeEntry;
193 }
194 
195 
196 inline void
198 {
199  mInternalIter = 0;
200 }
201 
202 
203 inline bool
205 {
206  return mInternalIter < mNextFreeEntry;
207 }
208 
209 
210 inline void
212 {
213  mInternalIter++;
214 }
215 
216 
217 #endif
218 
unsigned long mInternalIter
Definition: oofarray.h:105
bool more() const
Definition: oofarray.h:204
unsigned long count() const
Definition: oofarray.h:190
unsigned long mDefaultValue
Definition: oofarray.h:62
OOF_ExpandableLongArray OOF_ULArray
Definition: oofarray.h:67
void ** mUserStorage
Definition: oofarray.h:103
Tries to hide the different platforms and version issues with standard IO.
Declare macros used by most of OOFILE.
unsigned long * mBits
Definition: oofarray.h:61
unsigned long count() const
Definition: oofarray.h:126
bool Invariant() const
Guarantee members managing storage are consistent.
Definition: oofarray.h:119
unsigned long mNextFreeEntry
Definition: oofarray.h:63
unsigned long & item(unsigned long index)
Definition: oofarray.h:168
unsigned long mNextFreeEntry
Definition: oofarray.h:105
void * mBits
Definition: oofarray.h:104
Array of longs which expands automatically as you write to cells.
Definition: oofarray.h:21
unsigned long & operator()()
Definition: oofarray.h:161
unsigned long mNumSlots
Definition: oofarray.h:105
unsigned long mNumSlots
Definition: oofarray.h:63
base class for user arrays.
Definition: oofarray.h:76
unsigned long mInternalIter
Definition: oofarray.h:63
unsigned int mExpansionChunk
Definition: oofarray.h:106
unsigned long mSlotSize
Definition: oofarray.h:105
void next()
Definition: oofarray.h:211
bool Invariant() const
Guarantee members managing storage are consistent.
Definition: oofarray.h:183
bool more() const
Definition: oofarray.h:147
#define OOFILE_EXPORT
Prefix for OOFILE database & general classes to enable optional DLL linking.
Definition: oof0.h:187
void start()
Definition: oofarray.h:197
unsigned long & operator[](unsigned long index)
Definition: oofarray.cpp:228
unsigned long index() const
Definition: oofarray.h:133
unsigned int mExpansionChunk
Definition: oofarray.h:64