C++ main module for gpm Package  1.0
CORE_WeakPointersList.hpp
Go to the documentation of this file.
1 #ifndef CORE_WeakPointersList_CPP
2 #define CORE_WeakPointersList_CPP
3 
5 
6 template<class T>
8 
9  mVector.resize(0);
10 }
11 
12 template<class T>
13 template<class Q>
15 
16  copy(cpy);
17 }
18 template<class T>
20  clear();
21 }
22 
23 
24 template<class T>
25 template<class Q>
27  int n=cpy.getSize();
28  mVector.resize(n);
29  for (int i=0;i<n;i++) mVector[i]=boost::dynamic_pointer_cast<T>(cpy[i]);
30 }
31 template<class T>
32 template<class Q>
34  int n=cpy.getSize();
35  mVector.resize(n);
36  for (int i=0;i<n;i++) mVector[i]=boost::dynamic_pointer_cast<T>(cpy[i]);
37 }
38 
39 template<class T>
40 tBoolean CORE_WeakPointersList<T>::exists(const boost::shared_ptr<T>& obj) const {
41  int n=(int) mVector.size();
42  for (int i=0;i<n;i++) {
43  boost::shared_ptr<T> v=mVector[i].lock();
44  if( (v==obj)) return true;
45  }
46  return false;
47 };
48 template<class T>
50  for (int i=0;i<mVector.size();i++) {
51  boost::shared_ptr<T> v=mVector[i].lock();
52  if( (v) && (v.get()==&obj)) return true;
53  }
54  return false;
55 };
56 template<class T>
58  for (int i=0;i<mVector.size();i++) {
59  boost::shared_ptr<T> v=mVector[i].lock();
60  if( (v) && (v.get()==&obj)) return true;
61  }
62  return false;
63 };
64 
65 
66 template<class T>
67 tBoolean CORE_WeakPointersList<T>::remove(const boost::shared_ptr<T>& obj) {
68  int n=mVector.size();
69  tBoolean exists=false;
70  boost::shared_ptr<T> temp;
71  for (int i=n-1;i>=0;i--) {
72  temp=mVector[i].lock();
73  if (temp==obj) {
74  removeAtIndex(i);
75  exists=true;
76  }
77  }
78  return exists;
79 }
80 
81 template<class T>
83  int n=mVector.size();
84  tBoolean exists=false;
85  boost::shared_ptr<T> temp;
86  for (int i=n-1;i>=0;i--) {
87  temp=mVector[i].lock();
88  if ((temp)&&(temp.get()==&obj)) {
89  removeAtIndex(i);
90  exists=true;
91  }
92  }
93  return exists;
94 }
95 template<class T>
97  int n=mVector.size();
98  tBoolean exists=false;
99  boost::weak_ptr<T> temp;
100  for (int i=n-1;i>=0;i--) {
101  temp=mVector[i].lock();
102  if ((temp)&&(temp.get()==*obj)) {
103  removeAtIndex(i);
104  exists=true;
105  }
106  }
107  return exists;
108 }
109 
110 
111 template<class T>
113  if (index>=size()) return false;
114  if (index<0) return false;
115  typename vector<boost::weak_ptr<T> >::iterator p=mVector.begin()+index;
116  mVector.erase(p);
117  return true;
118 }
119 
120 template<class T>
121 void CORE_WeakPointersList<T>::permute(const int& i,const int& j) {
122  boost::weak_ptr<T> temp=mVector[i];
123  mVector[i]=mVector[j];
124  mVector[j]=temp;
125 }
126 
127 
128 template<class T>
129 tBoolean CORE_WeakPointersList<T>::insert(int index,const boost::shared_ptr<T>& obj) {
130  if (((int)mVector.size())==index) add(obj);
131  else {
132  int i=(int) index;
133  if (index<0) return false;
134  typename vector<boost::shared_ptr<T> >::iterator p=mVector.begin()+i;
135  if (i>size()) return false;
136  boost::weak_ptr<T> wobj=obj;
137  mVector.insert(p,wobj);
138  }
139  return true;
140 }
141 
142 template<class T>
143 tBoolean CORE_WeakPointersList<T>::set(int index,const boost::shared_ptr<T>& obj) {
144  int i=(int) index;
145  int p=size();
146  if (i>=p) {
147  mVector.resize(i+1);
148  }
149  boost::weak_ptr<T> wobj=obj;
150  mVector[i]=wobj;
151  return true;
152 }
153 template<class T>
155  int k=getSize()-1;
156  int n=mVector.size();
157  for (int i=0;i<n/2;i++) {
158  boost::weak_ptr<T> &temp=mVector[i];
159  mVector[i]=mVector[k];
160  mVector[k]=temp;
161  k--;
162  }
163 }
164 
165 template<class T>
166 template<class Q>
168  int oldSize=getSize();
169  int n=array.size();
170  setSize(oldSize+n);
171  int newSize=getSize();
172  for (int i=oldSize;i<newSize;i++) set(i,boost::dynamic_pointer_cast<T>(array[i]));
173 }
174 
175 
176 #endif
int getSize() const
return the size of the array
Definition: CORE_WeakPointersList.h:215
class CORE_SharedPointersList is a list of shared pointers
Definition: CORE_SharedPointersList.h:11
tBoolean insert(int i, const boost::shared_ptr< T > &obj)
insert the pointer at index i the old element i become the element i+1
Definition: CORE_WeakPointersList.hpp:129
#define tBoolean
Definition: types.h:35
CORE_WeakPointersList()
internal constructor
Definition: CORE_WeakPointersList.hpp:7
tBoolean exists(const boost::shared_ptr< T > &obj) const
exists
Definition: CORE_WeakPointersList.hpp:40
void permute(const int &i, const int &j)
permute
Definition: CORE_WeakPointersList.hpp:121
tBoolean set(int i, const boost::shared_ptr< T > &obj)
set the pointer at the index i
Definition: CORE_WeakPointersList.hpp:143
virtual ~CORE_WeakPointersList()
destroy an array of T*
Definition: CORE_WeakPointersList.hpp:19
void reverse()
reverse the vector
Definition: CORE_WeakPointersList.hpp:154
int getSize() const
return the size of the array
Definition: CORE_SharedPointersList.h:250
class CORE_WeakPointersList is a list of weak shared pointers
Definition: CORE_WeakPointersList.h:11
int size() const
return the size of the array
Definition: CORE_WeakPointersList.h:212
abstract base class for most classes.
Definition: CORE_Object.h:30
tBoolean remove()
remove the last pointer
Definition: CORE_WeakPointersList.h:159
void copy(const CORE_WeakPointersList< Q > &cpy)
copy the weak pointers list cpy
Definition: CORE_WeakPointersList.hpp:26
tBoolean removeAtIndex(const int &i)
remove the pointer at index i
Definition: CORE_WeakPointersList.hpp:112
void merge(const CORE_WeakPointersList< Q > &array)
merge the array in this
Definition: CORE_WeakPointersList.hpp:167