C++ main module for emicrom 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  typename vector<boost::weak_ptr<T> >::iterator iVector=mVector.begin();
28  typename vector<boost::weak_ptr<Q> >::const_iterator iCpy=cpy.begin();
29  typename vector<boost::weak_ptr<Q> >::const_iterator eCpy=cpy.end();
30  while (iCpy!=eCpy) {
31  *iVector==boost::dynamic_pointer_cast<T>(*iCpy);
32  iCpy++;
33  iVector++;
34  }
35 }
36 
37 template<class T>
38 template<class Q>
40  typename vector<boost::weak_ptr<T> >::iterator iVector=mVector.begin();
41  typename vector<boost::shared_ptr<Q> >::const_iterator iCpy=cpy.begin();
42  typename vector<boost::shared_ptr<Q> >::const_iterator eCpy=cpy.end();
43  while (iCpy!=eCpy) {
44  *iVector==boost::dynamic_pointer_cast<T>(*iCpy);
45  iCpy++;
46  iVector++;
47  }
48 }
49 
50 template<class T>
52 
53  typename vector<boost::weak_ptr<T> >::const_iterator iVector=mVector.begin();
54  while (iVector!=mVector.end()) {
55  if ((*iVector).lock().get()==&obj) return true;
56  iVector++;
57  }
58  return false;
59 }
60 
61 
62 
63 template<class T>
65  tBoolean exists=false;
66  typename vector<boost::weak_ptr<T> >::iterator iVector=mVector.begin();
67  while (iVector!=mVector.end()){
68  if ((*iVector).lock().get()==&obj) {
69  iVector=mVector.erase(iVector);
70  exists=true;
71  } else {
72  iVector++;
73  }
74  }
75  return exists;
76 
77 }
78 
79 template<class T>
81  if (index>=size()) return false;
82  typename vector<boost::weak_ptr<T> >::iterator p=mVector.begin()+index;
83  mVector.erase(p);
84  return true;
85 }
86 
87 template<class T>
89  typename vector<boost::shared_ptr<T> >::iterator pi=mVector.begin()+i;
90  typename vector<boost::shared_ptr<T> >::iterator pj=mVector.begin()+j;
91  std::swap(*pi,*pj);
92 
93 }
94 
95 
96 template<class T>
97 tBoolean CORE_WeakPointersList<T>::insert(const tUIndex& index,const boost::shared_ptr<T>& obj) {
98  if (mVector.size()==index) add(obj);
99  else {
100  typename vector<boost::weak_ptr<T> >::iterator p=mVector.begin()+index;
101  if (index>size()) return false;
102  boost::weak_ptr<T> wobj=obj;
103  mVector.insert(p,wobj);
104 
105  return true;
106  }
107 }
108 
109 
110 template<class T>
112  const boost::shared_ptr<T>& obj) {
113 
114  if (index>=size()) {
115  mVector.resize(index+1);
116  }
117  boost::weak_ptr<T> wobj=obj;
118  mVector[index]=wobj;
119  return true;
120 }
121 
122 template<class T>
124  typename vector<boost::weak_ptr<T> >::iterator ei=mVector.end();
125  typename vector<boost::weak_ptr<T> >::iterator bi=mVector.begin();
126  while (bi<ei) {
127  ei--;
128  std::swap(*ei,*bi);
129  bi++;
130  }
131 }
132 
133 template<class T>
134 template<class Q>
136  tUIndex oldSize=getSize();
137  tUIndex n=array.size();
138  setSize(oldSize+n);
139  typename vector<boost::weak_ptr<T> >::iterator p=mVector.begin()+oldSize;
140  typename vector<boost::weak_ptr<Q> >::const_iterator q=array.begin();
141  typename vector<boost::weak_ptr<Q> >::const_iterator eq=array.end();
142  while (q!=eq) {
143  *p=*q;
144  p++;
145  q++;
146  }
147 }
148 
149 
150 #endif
class CORE_SharedPointersList is a list of shared pointers
Definition: CORE_SharedPointersList.h:11
void permute(const tUIndex &i, const tUIndex &j)
permute
Definition: CORE_WeakPointersList.hpp:88
tBoolean set(const tUIndex &i, const boost::shared_ptr< T > &obj)
set the pointer at the index i
Definition: CORE_WeakPointersList.hpp:111
vector< boost::shared_ptr< T > >::const_iterator end() const
get iterator
Definition: CORE_SharedPointersList.h:311
tBoolean removeAtIndex(const tUIndex &i)
remove the pointer at index i
Definition: CORE_WeakPointersList.hpp:80
vector< boost::weak_ptr< T > >::const_iterator end() const
get iterator
Definition: CORE_WeakPointersList.h:271
#define tBoolean
Definition: types.h:139
vector< boost::weak_ptr< T > > mVector
Definition: CORE_WeakPointersList.h:16
CORE_WeakPointersList()
internal constructor
Definition: CORE_WeakPointersList.hpp:7
vector< boost::shared_ptr< T > >::const_iterator begin() const
get iterator
Definition: CORE_SharedPointersList.h:300
tUIndex size() const
return the size of the array
Definition: CORE_WeakPointersList.h:213
virtual ~CORE_WeakPointersList()
destroy an array of T*
Definition: CORE_WeakPointersList.hpp:19
void add(const boost::shared_ptr< T > &obj)
add an element at the end
Definition: CORE_WeakPointersList.h:104
void setSize(const int &n)
set the size of the weak pointer list
Definition: CORE_WeakPointersList.h:88
tUIndex getSize() const
return the size of the array
Definition: CORE_WeakPointersList.h:216
void reverse()
reverse the vector
Definition: CORE_WeakPointersList.hpp:123
tBoolean insert(const tUIndex &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:97
#define tUIndex
Definition: types.h:126
class CORE_WeakPointersList is a list of weak shared pointers
Definition: CORE_WeakPointersList.h:11
abstract base class for most classes.
Definition: CORE_Object.h:53
tBoolean remove()
remove the last pointer
Definition: CORE_WeakPointersList.h:161
void clear()
clear the array
Definition: CORE_WeakPointersList.h:167
void copy(const CORE_WeakPointersList< Q > &cpy)
copy the weak pointers list cpy
Definition: CORE_WeakPointersList.hpp:26
tBoolean exists(const boost::shared_ptr< T > &obj) const
exists
Definition: CORE_WeakPointersList.h:221
vector< boost::weak_ptr< T > >::const_iterator begin() const
get iterator
Definition: CORE_WeakPointersList.h:260
void merge(const CORE_WeakPointersList< Q > &array)
merge the array in this
Definition: CORE_WeakPointersList.hpp:135