VR-Forces 5.0.2 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
libbdiobject_array_declaration_template.h
Go to the documentation of this file.
1 
2 /*********************************************************************
3  ** Copyright (c) 2019 VT MAK
4  ** All rights reserved.
5  *********************************************************************/
6 
10 
11 
12 class bdiDataTracker;
13 
14 #ifdef LIBBDIOBJECT_ARRAY_DECLSPEC_bdiutil
15 # include <declspec_bdiutil.h>
16 #else
17 # ifdef LIBBDIOBJECT_ARRAY_DECLSPEC_bdigraphics
18 # include <declspec_bdigraphics.h>
19 # endif
20 #endif
21 
22 #ifdef LIBBDIOBJECT_ARRAY_INLINE
23 #define BDI_INLINE inline
24 #else
25 #define BDI_INLINE
26 #endif
27 
28 namespace makVrv
29 {
30  /****************************************************************************/
31 /*l
32  ** This class implements an array of LIBBDIOBJECT_ARRAY_TYPE objects.
33  */
34 #ifdef LIBBDIOBJECT_ARRAY_DECLSPEC_bdiutil
35  class BDI_DECLSPEC_bdiutil LIBBDIOBJECT_ARRAY_CLASS_NAME
36 #else
37 # ifdef LIBBDIOBJECT_ARRAY_DECLSPEC_bdigraphics
38  class BDI_DECLSPEC_bdigraphics LIBBDIOBJECT_ARRAY_CLASS_NAME
39 # else
40  class LIBBDIOBJECT_ARRAY_CLASS_NAME
41 # endif
42 #endif
43  {
44 
45  public:
46 
47  /*
48  *========================================
49  *2 Constructors
50  */
51 
52  /*l
53  ** Default constructor.
54  */
55  BDI_INLINE LIBBDIOBJECT_ARRAY_CLASS_NAME(int initial_size = 16,
56  int increment = 16);
57 
58  /*l
59  ** Virtual destructor.
60  */
61  BDI_INLINE virtual ~LIBBDIOBJECT_ARRAY_CLASS_NAME();
62 
63  /*
64  *========================================
65  *2 Class-specific Functions
66  */
67 
68  /*l
69  ** Adds the specified object to the front of the array.
70  **
71  *a object - pointer to object.
72  */
73  BDI_INLINE int push_front(LIBBDIOBJECT_ARRAY_TYPE* object);
74 
75  /*l
76  ** Removes the object at the front of the array, and returns it.
77  */
78  BDI_INLINE LIBBDIOBJECT_ARRAY_TYPE* pop_front(void);
79 
80  /*l
81  ** Adds the specified object to the end of the array.
82  **
83  *a object - pointer to object.
84  */
85  BDI_INLINE int push_back(LIBBDIOBJECT_ARRAY_TYPE* object);
86 
87  /*l
88  ** Removes the object at the end of the array, and returns
89  ** it.
90  */
91  BDI_INLINE LIBBDIOBJECT_ARRAY_TYPE* pop_back(void);
92 
93  /*l
94  ** Replaces the previous object at the specified index of the array
95  ** with the specified object. Returns the previous object at the index
96  ** or NULL if index is invalid. If NULL is returned, the object could
97  ** not be replaced. Does not delete the previous object.
98  **
99  *a index - index into objects array where object will be replaced
100  *a object_ptr - pointer to object to place in the array
101  */
102  BDI_INLINE LIBBDIOBJECT_ARRAY_TYPE* replace_at_index(int index, LIBBDIOBJECT_ARRAY_TYPE* object);
103 
104  /*l
105  ** Inserts the specified object at the specified index of the array.
106  **
107  *a index - index into objects array where object will be inserted
108  *a object_ptr - pointer to object
109  */
110  BDI_INLINE int insert_at_index(int index, LIBBDIOBJECT_ARRAY_TYPE* object);
111 
112  /*l
113  ** Removes the object at the specified index of the array, and returns it.
114  **
115  *a index - index into objects array where object will be removed
116  */
117  BDI_INLINE LIBBDIOBJECT_ARRAY_TYPE* remove_at_index(int index);
118 
119  /*l
120  ** Removes the object with the given pointer, and returns it.
121  **
122  *a object - pointer to object that will be removed
123  */
125 
126  /*l
127  ** Removes all objects in the array. Unlike other remove functions,
128  ** objects will be deleted if the array owns its objects.
129  */
130  BDI_INLINE int remove_all(void);
131 
132  /*l
133  ** Removes and deletes the object at the specified index of the array.
134  **
135  *a index - index into objects array where object will be deleted
136  */
137  BDI_INLINE int delete_at_index(int index);
138 
139  /*l
140  ** Gets the object at the specified index of the array and returns it.
141  **
142  *a index - index into objects array
143  *a returns - pointer to the object; NULL if index invalid
144  */
145  BDI_INLINE LIBBDIOBJECT_ARRAY_TYPE* get_at_index(int index) const;
146 
147  /*l
148  ** Gets the object at the specified index of the array and returns it.
149  **
150  *a index - index into objects array
151  *a returns - pointer to the object; NULL if index invalid
152  */
153  BDI_INLINE LIBBDIOBJECT_ARRAY_TYPE* operator [] (int index) const;
154 
155  /*l
156  ** Finds the passed object in the array, if it's there, and returns its index.
157  **
158  *a object - pointer to object that to be checked
159  *a returns - index of the object, -1 if not found
160  */
161  BDI_INLINE int get_index(LIBBDIOBJECT_ARRAY_TYPE* object) const;
162 
163  /*l
164  ** Perform multiple get_index calls.
165  ** The length of indexes must be at least src->size() long.
166  ** If items in `src' are not found in `this', then -1 is filled in.
167  */
168  BDI_INLINE void get_indices(int* indices, const LIBBDIOBJECT_ARRAY_CLASS_NAME& src) const;
169 
170  /*l
171  ** Same as above, but use unsigned shorts for indices.
172  */
173  BDI_INLINE void get_ushort_indices(unsigned short* indices, const LIBBDIOBJECT_ARRAY_CLASS_NAME& src) const;
174 
175  /*l
176  ** Returns the number of objects currently in the array.
177  */
178  BDI_INLINE int size(void) const { return m_num_objects; }
179 
180  /*l
181  ** Resizes the number of objects currently allocated for the array.
182  ** Note that no new objects will be added to the array if the new
183  ** allocation if larger (size() will return the same value), but some
184  ** may be removed if the new allocation is smaller.
185  */
186  BDI_INLINE int resize_allocation(int num_objects);
187 
188  /*l
189  ** Returns the flag determining whether the array owns the objects.
190  ** If the array owns the object and the array is deleted, the object is
191  ** deleted as well.
192  **
193  ** Default value is 0.
194  */
195  BDI_INLINE int get_own_objects(void) const { return m_own_objects; }
196 
197  /*l
198  ** Sets the flag determining whether the array owns the objects.
199  ** See get_own_objects().
200  */
201  BDI_INLINE void set_own_objects(int own_objects) { m_own_objects = own_objects; }
202 
203  /*l
204  ** Returns the flag determining whether the objects in the array
205  ** are pointers to arrays, in which case delete[] rather than delete
206  ** should be called to destroy the objects.
207  **
208  ** Default value is 0.
209  */
210  BDI_INLINE int get_array_delete(void) const { return m_array_delete; }
211 
212  /*l
213  ** Returns the flag determining whether the objects in the array
214  ** are pointers to arrays. See get_array_delete().
215  */
216  BDI_INLINE void set_array_delete(int array_delete) { m_array_delete = array_delete; }
217 
218  /*l
219  ** Returns the flag determining whether the array will be cleared
220  ** by successive pop_back() calls, or whether a more optimized
221  ** method can be used. This should be set to 1 if, when objects in
222  ** the array are deleted, they remove themselves from the array
223  ** automatically.
224  **
225  ** Default value is 0.
226  */
227  BDI_INLINE int get_pop_back_delete(void) { return m_pop_back_delete; }
228 
229  /*l
230  ** Returns the flag determining whether the objects in the array
231  ** will be cleared by successive pop_back() calls. See
232  ** get_pop_back_delete().
233  */
234  BDI_INLINE void set_pop_back_delete(int pop_back_delete) { m_pop_back_delete = pop_back_delete; }
235 
236  /*l
237  ** Sets the name of the array.
238  **
239  *a name - The passed string is copied. If NULL is passed, the name will
240  *a be set to the character string "" (0 length string).
241  */
242  BDI_INLINE void set_name(const char* name);
243 
244  /*l
245  ** Returns the name of the array. The char pointer returned will never
246  ** be NULL; if the object has no name, the pointer will point to the
247  ** character string "" (0 length string).
248  */
249  BDI_INLINE const char* get_name(void) const;
250 
251  /*l
252  ** Returns if we are using a geometric growth pattern
253  */
254  BDI_INLINE int get_geometric_growth() const { return m_geometric_growth; }
255 
256  /*l
257  ** set if we are using a geometric growth pattern
258  */
259  BDI_INLINE void set_geometric_growth(const int growth) { m_geometric_growth = growth; }
260 
261  /*l
262  ** use with caution
263  */
264  LIBBDIOBJECT_ARRAY_TYPE** get_array_data() { return m_objects; }
265 
266  virtual size_t get_memory_usage();
267  virtual size_t get_children_memory_usage();
268 
269 #ifdef LIBBDIOBJECT_ARRAY_DEEP_COPY
270 
271  /*l
272  ** use with caution
273  */
274  BDI_INLINE void deep_copy(const LIBBDIOBJECT_ARRAY_CLASS_NAME & rhs);
275 
276 #endif
277 
278 #ifdef LIBBDIOBJECT_ARRAY_PACKABLE
279 
280  BDI_INLINE bdiCfgEntry * create_cfg_entry(bdiCfgEntry *e, const char * array_name);
281  BDI_INLINE void parse_cfg_entry(bdiCfgEntry *e);
282 
283 #endif
284 
285 #ifdef LIBBDIOBJECT_ARRAY_PACKABLE_SUBENTRIES
286 
287  BDI_INLINE bdiCfgEntry * create_cfg_entry(bdiCfgEntry *e, const char * array_name);
288  BDI_INLINE void parse_cfg_entry(bdiCfgEntry *e);
289 
290 #endif
291  /*l
292  ** Tracker object for keeping track of who needs to update, who doesn't.
293  */
294  bdiDataTracker* data_tracker;
295 
296  protected:
297 
298  /*l
299  ** Ensures that at least min_objects are allocated.
300  **
301  *a min_objects - minimum number of objects allocated
302  */
303  BDI_INLINE int check_object_allocation(int min_objects);
304 
305  /*
306  *========================================
307  *2 Data Members
308  */
309 
310  /*l
311  ** Number of objects currently in the array.
312  */
314 
315  /*l
316  ** Number of objects allocated in the array. Will be >= to m_num_objects.
317  */
319 
320  /*l
321  ** Array of object pointers. Grow the array by
322  ** calling check_object_allocation().
323  */
325 
326  /*l
327  ** Flag determining whether the array owns the objects.
328  ** See get_own_objects().
329  */
331 
332  /*l
333  ** Flag determining whether the objects in the array
334  ** are pointers to arrays. See get_array_delete().
335  */
337 
338  /*l
339  ** See get_pop_back_delete().
340  */
342 
343  /*l
344  ** Name of the array.
345  */
346  char* m_name;
347 
348  /*l
349  ** Amount by which array grows when more space is needed.
350  */
352 
353  /*l
354  ** weather or not the increment flag is ignored and a 2x growth method is used.
355  */
357 
358  private:
359 
360  /*l
361  ** The default copy constructor is disabled by declaring it private
362  */
363  LIBBDIOBJECT_ARRAY_CLASS_NAME(const LIBBDIOBJECT_ARRAY_CLASS_NAME &);
364 
365  /*l
366  ** The default assignment operator is disabled by declaring it private.
367  */
368  LIBBDIOBJECT_ARRAY_CLASS_NAME& operator= (const LIBBDIOBJECT_ARRAY_CLASS_NAME &);
369 
370  };
371 
372 #ifdef BDI_INLINE
373 #undef BDI_INLINE
374 #endif
375 
376 }
LIBBDIOBJECT_ARRAY_TYPE ** m_objects
Definition: libbdiobject_array_declaration_template.h:324
bdiDataTracker * data_tracker
Definition: libbdiobject_array_declaration_template.h:294
int m_geometric_growth
Definition: libbdiobject_array_declaration_template.h:356
BDI_INLINE void set_geometric_growth(const int growth)
Definition: libbdiobject_array_declaration_template.h:259
BDI_INLINE void set_own_objects(int own_objects)
Definition: libbdiobject_array_declaration_template.h:201
#define BDI_INLINE
Definition: libbdiobject_array_declaration_template.h:25
BDI_INLINE int size(void) const
Definition: libbdiobject_array_declaration_template.h:178
BDI_INLINE void set_pop_back_delete(int pop_back_delete)
Definition: libbdiobject_array_declaration_template.h:234
int m_pop_back_delete
Definition: libbdiobject_array_declaration_template.h:341
BDI_INLINE int get_array_delete(void) const
Definition: libbdiobject_array_declaration_template.h:210
#define LIBBDIOBJECT_ARRAY_CLASS_NAME
Definition: DtFxCollisionObject.h:139
LIBBDIOBJECT_ARRAY_TYPE ** get_array_data()
Definition: libbdiobject_array_declaration_template.h:264
#define LIBBDIOBJECT_ARRAY_TYPE
Definition: DtFxCollisionObject.h:138
char * m_name
Definition: libbdiobject_array_declaration_template.h:346
int m_num_objects_allocated
Definition: libbdiobject_array_declaration_template.h:318
BDI_INLINE int get_geometric_growth() const
Definition: libbdiobject_array_declaration_template.h:254
int m_num_objects
Definition: libbdiobject_array_declaration_template.h:313
int m_own_objects
Definition: libbdiobject_array_declaration_template.h:330
int m_increment
Definition: libbdiobject_array_declaration_template.h:351
int m_array_delete
Definition: libbdiobject_array_declaration_template.h:336
BDI_INLINE int get_own_objects(void) const
Definition: libbdiobject_array_declaration_template.h:195
BDI_INLINE void set_array_delete(int array_delete)
Definition: libbdiobject_array_declaration_template.h:216
BDI_INLINE int get_pop_back_delete(void)
Definition: libbdiobject_array_declaration_template.h:227

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)