1 #ifndef CORE_WeakPointersArray_CPP
2 #define CORE_WeakPointersArray_CPP
12 mValues=
new boost::weak_ptr<T>[mCapacity];
27 if (mValues!=
null)
delete[] mValues;
39 mValues[i]=boost::dynamic_pointer_cast<T>(cpy[i]);
46 if (cap<mCapacity)
return;
48 if (mCapacityFactor<=1) mCapacity=cap+1;
49 else while (mCapacity<=cap) mCapacity*=mCapacityFactor;
51 boost::weak_ptr<T> *newValues=
null;
53 newValues=
new boost::weak_ptr<T>[mCapacity];
54 }
catch (std::exception e) {
55 cout << e.what()<<
"\n";
57 "CORE_WeakPointersArray<T>::resize(cap)",
58 "not enought memory to allocate new array");
63 const boost::weak_ptr<T> *cValues=&(*this)[0];
65 *newValues=boost::dynamic_pointer_cast<T>(*cValues);
71 if (mValues!=
null)
delete[] mValues;
80 if (mSize+1==mCapacity)
return;
84 boost::shared_ptr<T> *newValues=
null;
86 newValues =
new boost::weak_ptr<T>[mCapacity];
87 }
catch (std::exception e) {
88 cout << e.what()<<
"\n";
89 throw CORE_Exception(
"common/core",
"CORE_WeakPointersArray<T>::resize(cap)",
90 "not enought memory to allocate new array");
94 const boost::weak_ptr<T> *cValues=&(*this)[0];
96 *newValues=boost::dynamic_pointer_cast<T>(*cValues);
102 if (mValues!=
null)
delete[] mValues;
120 if (index>=mSize) add(obj);
123 boost::weak_ptr<T> *pValues=&(*this)[mSize];
124 const boost::weak_ptr<T> *cValues=
null;
126 cValues=&(*this)[mSize-1];
141 if (mSize==0)
return false;
143 boost::weak_ptr<T> *pValues=&(*this)[i];
144 if ((*pValues).lock().get()==obj) removeAtIndex(i);
148 if ((*pValues).lock().get()==obj) {
165 if ((i<0) || (i>=mSize))
return false;
168 boost::weak_ptr<T> *pValues=&(*this)[i];
170 const boost::weak_ptr<T> *cValues=
null;
193 if (mSize==0)
return false;
194 const boost::weak_ptr<T> *pValues=&(*this)[0];
196 if ((*pValues).lock().get()==obj)
return true;
tBoolean remove()
remove the last pointer
Definition: CORE_WeakPointersArray.h:199
#define tArrayIndex
Definition: types.h:39
tBoolean removeAtIndex(const tArrayIndex &i)
remove the pointer at index i
Definition: CORE_WeakPointersArray.hpp:163
void resize(const tArrayIndex &cap)
resize the array
Definition: CORE_WeakPointersArray.hpp:44
void copy(const CORE_WeakPointersArray< Q > &cpy)
New copy constructor of a weak pointers list.
Definition: CORE_WeakPointersArray.hpp:33
CORE_WeakPointersArray()
internal constructor of a weak pointers array
Definition: CORE_WeakPointersArray.hpp:8
const tArrayIndex & getSize() const
return the size of the array
Definition: CORE_WeakPointersArray.h:254
void set(const tArrayIndex &i, boost::shared_ptr< T > obj)
set the pointer at the index i
Definition: CORE_WeakPointersArray.hpp:111
#define tBoolean
Definition: types.h:48
#define null
Definition: types.h:13
virtual ~CORE_WeakPointersArray()
destroy an array of T*
Definition: CORE_WeakPointersArray.hpp:23
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:15
class CORE_WeakPointersArray is an array of weak pointers
Definition: CORE_WeakPointersArray.h:12
tBoolean exists(boost::shared_ptr< T > obj) const
exists
Definition: CORE_WeakPointersArray.h:261
void insert(const tArrayIndex &i, boost::shared_ptr< T > obj)
insert the pointer at index i the old element i become the element i+1
Definition: CORE_WeakPointersArray.hpp:119
abstract base class for most classes.
Definition: CORE_Object.h:30
void fit()
fit the capacity to size
Definition: CORE_WeakPointersArray.hpp:78