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