UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PtrAr.H
1 // PtrAr.H $Revision: 1.6 $ $Date: 2005/02/16 09:47:29 $
2 
3 // May be included many times
4 
5 #include <mix/DynAr.H>
6 
7 
8 /*************************************************************
9  * Dynamic Array of AnyType object (originally for pointers).
10  *
11  * This is macro-based template with two macro parameters.
12  *
13  * Example:
14  * #define PtrType your-type // void* for example
15  * #define PtrAr your-type-array // VoidPtrAr f.e.
16  * #include <mix/PtrAr.H> // generates class your-type-array and
17  * // defines all methods of it as inline
18  *
19  * Optional macros:
20  * #define PtrArQuant your-quant-of-growing
21  * #define PtrArVolume your-startup-volume
22  * #define PtrDestroyItem(item) free(item->pArray);
23  *
24  * Usage:
25  * 1) For a type you want to make array you must define
26  * two macros: PtrType and PtrAr as in example.
27  * 2) Include after definitions this header file.
28  *
29  * You can define this way in one source many array types by
30  * simple replication of usage rules. Do not worry about
31  * previous macro definitions: they are undefined in PtrAr.H
32  *************************************************************/
33 
34 #ifndef PtrArQuant
35 #define PtrArQuant DEFAULT_QUANT
36 #endif /* PtrArQuant */
37 
38 #ifndef PtrArVolume
39 #define PtrArVolume START_VOLUME
40 #endif /* PtrArVolume */
41 
42 
43 class PtrAr : public DynAr
44 {
45 public:
46 
47  PtrAr (const PtrAr& pArray)
48  :DynAr(pArray) {};
49  PtrAr (unsigned quant = PtrArQuant,
50  unsigned volume = PtrArVolume)
51  :DynAr(sizeof(PtrType), quant, volume) {};
52 
53  PtrType& fetch (unsigned i)
54  {return *(PtrType*)item_ptr(i);};
55  PtrType get (unsigned i) const
56  {return *(PtrType*)item_ptr(i);};
57 
58  void insert (unsigned i, const PtrType val)
59  {DynAr::insert(i, (const char*)&val);};
60 
61  void addh (const PtrType val) {DynAr::addh((const char*)&val);};
62  void addl (const PtrType val) {DynAr::addl((const char*)&val);};
63 
64  void addh (const PtrAr& pArray) {DynAr::addh(pArray);};
65  void addl (const PtrAr& pArray) {DynAr::addl(pArray);};
66 
67  PtrAr& assign (const PtrAr& pArray)
68  {DynAr::assign(pArray); return *this;};
69 
70  // Synonyms
71  PtrType& operator[] (unsigned i)
72  {return fetch(i);};
73  PtrType operator() (unsigned i) const
74  {return get(i);};
75  PtrAr& operator= (const PtrAr& pArray)
76  {return assign(pArray);};
77 
78 protected:
79 
80 #ifdef PtrDestroyItem
81  virtual void destruct_item (char* item){
82  PtrType p = (PtrType)item;
83  PtrDestroyItem(p);
84  };
85 #endif /* PtrDestroyItem */
86 
87 };
88 
89 #undef PtrType
90 #undef PtrAr
91 #undef PtrArVolume
92 #undef PtrArQuant
93 #undef PtrDestroyItem
Definition: PtrAr.H:43
Definition: DynAr.H:22