C++ main module for emicrom 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  tUIndex 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.begin();
31  typename vector<boost::shared_ptr<Q> >::const_iterator eCpy=cpy.end();
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  typename vector<boost::shared_ptr<T> >::iterator p=mVector.begin()+index;
69  mVector.erase(p);
70  return true;
71 }
72 
73 
74 
75 template<class T>
77  typename vector<boost::shared_ptr<T> >::iterator pi=mVector.begin()+i;
78  typename vector<boost::shared_ptr<T> >::iterator pj=mVector.begin()+j;
79  std::swap(*pi,*pj);
80 }
81 
82 
83 template<class T>
84 tBoolean CORE_SharedPointersList<T>::insert(const tUIndex& index,boost::shared_ptr<T> obj) {
85  if (mVector.size()==index) add(obj);
86  else {
87  typename vector<boost::shared_ptr<T> >::iterator p=mVector.begin()+index;
88  if (index>size()) return false;
89  mVector.insert(p,obj);
90  }
91  return true;
92 }
93 
94 template<class T>
95 tBoolean CORE_SharedPointersList<T>::set(const tUIndex & index,boost::shared_ptr<T> obj) {
96  if (index>=size()) {
97  mVector.resize(index+1);
98  }
99  mVector[index]=obj;
100  return true;
101 }
102 
103 
104 template<class T>
106  typename vector<boost::shared_ptr<T> >::iterator ei=mVector.end();
107  typename vector<boost::shared_ptr<T> >::iterator bi=mVector.begin();
108  while (bi<ei) {
109  ei--;
110  std::swap(*ei,*bi);
111  bi++;
112  }
113 
114 }
115 
116 template<class T>
117 template<class Q>
119  tUIndex oldSize=getSize();
120  tUIndex n=array.size();
121  setSize(oldSize+n);
122  typename vector<boost::shared_ptr<T> >::iterator p=mVector.begin()+oldSize;
123  typename vector<boost::shared_ptr<Q> >::const_iterator q=array.begin();
124  typename vector<boost::shared_ptr<Q> >::const_iterator eq=array.end();
125  while (q!=eq) {
126  *p=*q;
127  p++;
128  q++;
129  }
130 }
131 
132 template<class T>
134 
135  tUIndex n=getSize();
136  vs.resize(n);
137  typename vector<T*>::iterator ivs=vs.begin();
138  typename vector<boost::shared_ptr<T> >::iterator p=mVector.begin();
139  while (p!=mVector.end()) {
140  *ivs=(*p).get();
141  ivs++;
142  p++;
143  }
144 }
145 
146 
147 template<class T>
148 void CORE_SharedPointersList<T>::getValues(vector<const T*>& vs) const {
149  tUIndex n=getSize();
150  vs.resize(n);
151  typename vector<const T*>::iterator ivs=vs.begin();
152  typename vector<boost::shared_ptr<T> >::const_iterator p=mVector.begin();
153  while (p!=mVector.end()) {
154  *ivs=(*p).get();
155  ivs++;
156  p++;
157  }
158 }
159 
160 
161 #endif
void copy(const CORE_SharedPointersList< Q > &cpy)
New copy constructor of a shared pointers list.
Definition: CORE_SharedPointersList.hpp:26
tUIndex getSize() const
return the size of the array
Definition: CORE_SharedPointersList.h:258
vector< boost::shared_ptr< T > > mVector
Definition: CORE_SharedPointersList.h:13
tBoolean set(const tUIndex &i, boost::shared_ptr< T > obj)
set the pointer at the index i
Definition: CORE_SharedPointersList.hpp:95
class CORE_SharedPointersList is a list of shared pointers
Definition: CORE_SharedPointersList.h:11
void clear()
clear the array
Definition: CORE_SharedPointersList.h:221
tBoolean removeAtIndex(const tUIndex &i)
remove the pointer at index i
Definition: CORE_SharedPointersList.hpp:66
vector< boost::shared_ptr< T > >::const_iterator end() const
get iterator
Definition: CORE_SharedPointersList.h:311
void add(boost::shared_ptr< T > obj)
add an element at the end
Definition: CORE_SharedPointersList.h:134
tBoolean insert(const tUIndex &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:84
#define tBoolean
Definition: types.h:139
void merge(const CORE_SharedPointersList< Q > &array)
merge the array in this
Definition: CORE_SharedPointersList.hpp:118
virtual ~CORE_SharedPointersList()
destroy an array of T*
Definition: CORE_SharedPointersList.hpp:19
vector< boost::shared_ptr< T > >::const_iterator begin() const
get iterator
Definition: CORE_SharedPointersList.h:300
void reverse()
reverse the vector
Definition: CORE_SharedPointersList.hpp:105
void permute(const tUIndex &i, const tUIndex &j)
permute
Definition: CORE_SharedPointersList.hpp:76
CORE_SharedPointersList()
internal constructor of a shared pointers list
Definition: CORE_SharedPointersList.hpp:7
void getValues(vector< T *> &vs)
get values
Definition: CORE_SharedPointersList.hpp:133
tBoolean remove()
remove the last pointer
Definition: CORE_SharedPointersList.h:199
#define tUIndex
Definition: types.h:126
tBoolean exists(boost::shared_ptr< T > obj) const
exists
Definition: CORE_SharedPointersList.h:263
abstract base class for most classes.
Definition: CORE_Object.h:53
tUIndex size() const
return the size of the array
Definition: CORE_SharedPointersList.h:255
void setSize(const tUIndex &n)
set the size of the shared pointers list
Definition: CORE_SharedPointersList.h:87