Files Classes Functions Hierarchy
#include <dumbarray.h>
Public Member Functions | |
| dumbarray (dumbarray< T > const &x) | |
| Copy without passing ownership of xi. | |
| dumbarray () | |
| Default - do something later constructor. | |
| dumbarray (T **xi_, uintc N_, boolc memoryManaged_) | |
| The client initializes xi and can pass ownership to this class. | |
| ~dumbarray () | |
| Cleanup if requested. | |
| dumbarray (uintc N_) | |
| Create a N dimensional array of T* pointers. | |
| void | create (uintc N_) |
| Create a N dimensional array of T* pointers. | |
| void | clean () |
| If memory allocated delete it. | |
| void | operator= (dumbarray< T > const &x) |
| Memory ownership of xi is not transfered. | |
| T & | operator[] (uintc i) |
| Access an element and can modify value. | |
| T const | operator[] (uintc i) const |
| Access an element. | |
| T *& | operator() (uint i) |
| Access a pointer to an element and can modify the pointers value. | |
Public Attributes | |
| T ** | xi |
| Array of pointers. | |
| uint | N |
| The number of dimensions. | |
| bool | memoryManaged |
| Is this class managing the xi array? | |
The direct analogy is an array of pointers to the objects. However there is no need for contiguous memory.
It is a smart pointer for a few reasons, however I call it a dumb array because each element access de references a pointer as compared with the usual array access on contiguous memory. Roughly doubling the access time.
The client can manage the memory directly. Assignment does not pass control of xi because in the end someone has to clean the memory up and there can only be one de allocation point. (This is a more primitive technique than reference counting and can have dangling pointers)
dumbarray<double> vi(3); cout << "Set the pointers" << endl; vi(0) = & a; vi(1) = & b; vi(2) = & c; ... cout << "Access an element" << endl; vi[2] = 2.5; // c=2.5 cout << "Have multiple arrays to same array" << endl; dumbarray<double> v2(); v2 = vi; y= v2[1]; // y=b
Definition at line 40 of file dumbarray.h.
Copy without passing ownership of xi.
Definition at line 130 of file dumbarray.h.
References dumbarray< T >::memoryManaged, dumbarray< T >::N, and dumbarray< T >::xi.
00131 { 00132 xi = x.xi; 00133 N = x.N; 00134 memoryManaged = false; 00135 }
Default - do something later constructor.
Definition at line 59 of file dumbarray.h.
00060 : xi(0), N(0), memoryManaged(false) {}
| dumbarray< T >::dumbarray | ( | T ** | xi_, | |
| uintc | N_, | |||
| boolc | memoryManaged_ | |||
| ) | [inline] |
The client initializes xi and can pass ownership to this class.
Definition at line 65 of file dumbarray.h.
00070 : xi(xi_), N(N_), memoryManaged(memoryManaged_) {}
Cleanup if requested.
Definition at line 116 of file dumbarray.h.
References dumbarray< T >::clean().
00117 { 00118 clean(); 00119 }
Create a N dimensional array of T* pointers.
Definition at line 123 of file dumbarray.h.
References dumbarray< T >::create().
00124 : xi(0), memoryManaged(false) 00125 { 00126 create(N_); 00127 }
If memory allocated delete it.
Definition at line 153 of file dumbarray.h.
References dumbarray< T >::memoryManaged, dumbarray< T >::N, and dumbarray< T >::xi.
Referenced by dumbarray< T >::create(), dumbarray< T >::operator=(), and dumbarray< T >::~dumbarray().
00154 { 00155 if (memoryManaged) 00156 delete[] xi; 00157 xi=0; 00158 N=0; 00159 }
Create a N dimensional array of T* pointers.
Definition at line 107 of file dumbarray.h.
References dumbarray< T >::clean(), dumbarray< T >::memoryManaged, dumbarray< T >::N, and dumbarray< T >::xi.
Referenced by dumbarray< T >::dumbarray().
Access a pointer to an element and can modify the pointers value.
Definition at line 97 of file dumbarray.h.
00098 { return xi[i]; }
Memory ownership of xi is not transfered.
Definition at line 138 of file dumbarray.h.
References dumbarray< T >::clean(), dumbarray< T >::memoryManaged, dumbarray< T >::N, and dumbarray< T >::xi.
00139 { 00140 if (&x==this) 00141 return; 00142 00143 clean(); 00144 00145 xi = x.xi; 00146 N = x.N; 00147 memoryManaged = false; 00148 }
Access an element and can modify value.
Definition at line 89 of file dumbarray.h.
00090 { return *xi[i]; }
| bool dumbarray< T >::memoryManaged |
Is this class managing the xi array?
Definition at line 53 of file dumbarray.h.
Referenced by dumbarray< T >::clean(), dumbarray< T >::create(), dumbarray< T >::dumbarray(), and dumbarray< T >::operator=().
The number of dimensions.
Definition at line 50 of file dumbarray.h.
Referenced by dumbarray< T >::clean(), dumbarray< T >::create(), dumbarray< T >::dumbarray(), and dumbarray< T >::operator=().
Array of pointers.
To modify the pointer the client writes to xi. To modify the value use the [] operator.
Definition at line 47 of file dumbarray.h.
Referenced by dumbarray< T >::clean(), dumbarray< T >::create(), dumbarray< T >::dumbarray(), dumbarray< double >::operator()(), dumbarray< T >::operator=(), and dumbarray< double >::operator[]().
1.5.8