C++ main module for mmsd 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  tVectorIndex n=cpy.getSize();
28  mVector.resize(n);
29  typename vector<boost::shared_ptr<T> >::iterator iVector=mVector.begin();
30  typename vector<boost::shared_ptr<Q> >::const_iterator iCpy=cpy.getIterator();
31  typename vector<boost::shared_ptr<Q> >::const_iterator eCpy=cpy.getEndIterator();
32  while (iCpy!=eCpy) {
33  *iVector=*iCpy;
34  iCpy++;
35  iVector++;
36  }
37 }
38 
39 
40 template<class T>
42  typename vector<boost::shared_ptr<T> >::const_iterator iVector=mVector.begin();
43  while (iVector!=mVector.end()) {
44  if ((*iVector).get()==&obj) return true;
45  iVector++;
46  }
47  return false;
48 };
49 
50 template<class T>
52  tBoolean exists=false;
53  typename vector<boost::shared_ptr<T> >::iterator iVector=mVector.begin();
54  while (iVector!=mVector.end()){
55  if ((*iVector).get()==&obj) {
56  iVector=mVector.erase(iVector);
57  exists=true;
58  } else {
59  iVector++;
60  }
61  }
62  return exists;
63 }
64 
65 template<class T>
67  if (index>=size()) return false;
68  if (index<0) return false;
69  typename vector<boost::shared_ptr<T> >::iterator p=mVector.begin()+index;
70  mVector.erase(p);
71  return true;
72 }
73 
74 template<class T>
76  typename vector<boost::shared_ptr<T> >::iterator pi=mVector.begin()+i;
77  typename vector<boost::shared_ptr<T> >::iterator pj=mVector.begin()+j;
78 
79  boost::shared_ptr<T> temp=*pi;
80  *pi=*pj;
81  *pj=temp;
82 }
83 
84 
85 template<class T>
86 tBoolean CORE_SharedPointersList<T>::insert(const tVectorIndex& index,boost::shared_ptr<T> obj) {
87  if (mVector.size()==index) add(obj);
88  else {
89  typename vector<boost::shared_ptr<T> >::iterator p=mVector.begin()+index;
90  if (index>size()) return false;
91  mVector.insert(p,obj);
92  }
93  return true;
94 }
95 
96 template<class T>
97 tBoolean CORE_SharedPointersList<T>::set(const tVectorIndex & index,boost::shared_ptr<T> obj) {
98  if (index>=size()) {
99  mVector.resize(index+1);
100  }
101  mVector[index]=obj;
102  return true;
103 }
104 
105 
106 template<class T>
108  typename vector<boost::shared_ptr<T> >::iterator pE=mVector.end();
109  typename vector<boost::shared_ptr<T> >::iterator pB=mVector.begin();
110  tVectorIndex i,n=getSize();
111  for (i=0;i<n/2;i++) {
112  pE--;
113  boost::shared_ptr<T> &temp=*pB;
114  *pB=*pE;
115  *pE=temp;
116  pB++;
117  }
118 }
119 
120 template<class T>
121 template<class Q>
123  tVectorIndex oldSize=getSize();
124  tVectorIndex n=array.size();
125  setSize(oldSize+n);
126  typename vector<boost::shared_ptr<T> >::iterator p=mVector.begin()+oldSize;
127  typename vector<boost::shared_ptr<Q> >::const_iterator q=array.getIterator();
128  typename vector<boost::shared_ptr<Q> >::const_iterator eq=array.getEndIterator();
129  while (q!=eq) {
130  *p=*q;
131  p++;
132  q++;
133  }
134 }
135 
136 template<class T>
138 
139  tVectorIndex n=getSize();
140  vs.resize(n);
141  typename vector<T*>::iterator ivs=vs.begin();
142  typename vector<boost::shared_ptr<T> >::iterator p=mVector.begin();
143  while (p!=mVector.end()) {
144  *ivs=(*p).get();
145  ivs++;
146  p++;
147  }
148 }
149 
150 
151 template<class T>
152 void CORE_SharedPointersList<T>::getValues(vector<const T*>& vs) const {
153  tVectorIndex n=getSize();
154  vs.resize(n);
155  typename vector<const T*>::iterator ivs=vs.begin();
156  typename vector<boost::shared_ptr<T> >::const_iterator p=mVector.begin();
157  while (p!=mVector.end()) {
158  *ivs=(*p).get();
159  ivs++;
160  p++;
161  }
162 }
163 
164 
165 #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
tBoolean set(const tVectorIndex &i, boost::shared_ptr< T > obj)
set the pointer at the index i
Definition: CORE_SharedPointersList.hpp:97
#define tVectorIndex
Definition: types.h:42
#define tBoolean
Definition: types.h:48
void merge(const CORE_SharedPointersList< Q > &array)
merge the array in this
Definition: CORE_SharedPointersList.hpp:122
virtual ~CORE_SharedPointersList()
destroy an array of T*
Definition: CORE_SharedPointersList.hpp:19
void reverse()
reverse the vector
Definition: CORE_SharedPointersList.hpp:107
tBoolean removeAtIndex(const tVectorIndex &i)
remove the pointer at index i
Definition: CORE_SharedPointersList.hpp:66
void getValues(vector< T * > &vs)
get values
Definition: CORE_SharedPointersList.hpp:137
CORE_SharedPointersList()
internal constructor of a shared pointers list
Definition: CORE_SharedPointersList.hpp:7
vector< boost::shared_ptr< T > >::const_iterator getIterator() const
get iterator
Definition: CORE_SharedPointersList.h:287
tBoolean insert(const tVectorIndex &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:86
tBoolean remove()
remove the last pointer
Definition: CORE_SharedPointersList.h:199
abstract base class for most classes.
Definition: CORE_Object.h:30
void permute(const tVectorIndex &i, const tVectorIndex &j)
permute
Definition: CORE_SharedPointersList.hpp:75
vector< boost::shared_ptr< T > >::const_iterator getEndIterator() const
get iterator
Definition: CORE_SharedPointersList.h:297
tBoolean exists(boost::shared_ptr< T > obj) const
exists
Definition: CORE_SharedPointersList.h:250
tVectorIndex size() const
return the size of the array
Definition: CORE_SharedPointersList.h:242
tVectorIndex getSize() const
return the size of the array
Definition: CORE_SharedPointersList.h:245