xc
DqPtrs.h
1 //----------------------------------------------------------------------------
2 // XC program; finite element analysis code
3 // for structural analysis and design.
4 //
5 // Copyright (C) Luis Claudio Pérez Tato
6 //
7 // This program derives from OpenSees <http://opensees.berkeley.edu>
8 // developed by the «Pacific earthquake engineering research center».
9 //
10 // Except for the restrictions that may arise from the copyright
11 // of the original program (see copyright_opensees.txt)
12 // XC is free software: you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation, either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // This software is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program.
25 // If not, see <http://www.gnu.org/licenses/>.
26 //----------------------------------------------------------------------------
27 //DqPtrs.h
28 //deque de pointers (se emplear en la clase Set).
29 
30 
31 #ifndef DQPTRS_H
32 #define DQPTRS_H
33 
34 #include "xc_utils/src/kernel/CommandEntity.h"
35 #include <deque>
36 #include <set>
37 #include "utility/actor/actor/MovableID.h"
38 #include <boost/iterator/indirect_iterator.hpp>
39 
40 
41 
42 namespace XC {
43 
55 template <class T>
56 class DqPtrs: public CommandEntity, protected std::deque<T *>
57  {
58  public:
59  typedef typename std::deque<T *> lst_ptr;
60  typedef typename lst_ptr::const_iterator const_iterator;
61  typedef typename lst_ptr::iterator iterator;
62  typedef typename lst_ptr::reference reference;
63  typedef typename lst_ptr::const_reference const_reference;
64  typedef typename lst_ptr::size_type size_type;
65  typedef boost::indirect_iterator<iterator> indIterator;
66  public:
67  DqPtrs(CommandEntity *owr= nullptr);
68  DqPtrs(const DqPtrs &);
69  explicit DqPtrs(const std::deque<T *> &ts);
70  explicit DqPtrs(const std::set<const T *> &ts);
71  DqPtrs &operator=(const DqPtrs &);
72  DqPtrs &operator+=(const DqPtrs &);
73  void extend(const DqPtrs &);
74  //void extend_cond(const DqPtrs &,const std::string &cond);
75  bool push_back(T *);
76  bool push_front(T *);
77  inline bool empty(void) const
78  { return lst_ptr::empty(); }
79  inline iterator begin(void)
80  { return lst_ptr::begin(); }
81  const_iterator begin(void) const
82  { return lst_ptr::begin(); }
83  iterator end(void)
84  { return lst_ptr::end(); }
85  const_iterator end(void) const
86  { return lst_ptr::end(); }
87  inline indIterator indBegin(void)
88  { return indIterator(lst_ptr::begin()); }
89  inline indIterator indEnd(void)
90  { return indIterator(lst_ptr::end()); }
91  const T &get(const size_t &i) const;
92  void clear(void);
93  void clearAll(void);
94  inline size_type size(void) const
95  { return lst_ptr::size(); }
96  bool in(const T *) const;
97  //void sort_on_prop(const std::string &cod,const bool &ascending= true);
98 
99  const ID &getTags(void) const;
100  template <class InputIterator>
101  void insert(iterator pos, InputIterator f, InputIterator l)
102  { lst_ptr::insert(pos,f,l); }
103 
104 
105  int sendTags(int posSz,int posDbTag,DbTagData &dt,CommParameters &cp);
106  const ID &receiveTags(int posSz,int pDbTg,DbTagData &dt,const CommParameters &cp);
107 
108  };
109 
111 template <class T>
112 DqPtrs<T>::DqPtrs(CommandEntity *owr)
113  : CommandEntity(owr),lst_ptr() {}
114 
116 template <class T>
118  : CommandEntity(other), lst_ptr(other)
119  {}
120 
122 template <class T>
123 DqPtrs<T>::DqPtrs(const std::deque<T *> &ts)
124  : CommandEntity(), lst_ptr(ts)
125  {}
126 
128 template <class T>
129 DqPtrs<T>::DqPtrs(const std::set<const T *> &st)
130  : CommandEntity(), lst_ptr()
131  {
132  typename std::set<const T *>::const_iterator k;
133  k= st.begin();
134  for(;k!=st.end();k++)
135  lst_ptr::push_back(const_cast<T *>(*k));
136  }
137 
139 template <class T>
141  {
142  CommandEntity::operator=(other);
143  lst_ptr::operator=(other);
144  return *this;
145  }
146 
148 template <class T>
150  {
151  extend(other);
152  return *this;
153  }
154 
155 
158 template <class T>
159 void DqPtrs<T>::extend(const DqPtrs &other)
160  {
161  for(register const_iterator i= other.begin();i!=other.end();i++)
162  push_back(*i);
163  }
164 
166 template<class T>
168  { lst_ptr::clear(); }
169 
171 template<class T>
173  {
174  clear();
175  CommandEntity::clearPyProps();
176  }
177 
179 template<class T>
180 const T &DqPtrs<T>::get(const size_t &i) const
181  {
182  const T *ptr= lst_ptr::at(i);
183  return *ptr;
184  }
185 
187 template<class T>
188 bool DqPtrs<T>::in(const T *ptr) const
189  {
190  bool retval= false;
191  for(const_iterator i= begin();i!= end();i++)
192  if(*i==ptr)
193  {
194  retval= true;
195  break;
196  }
197  return retval;
198  }
199 
200 
201 template <class T>
202 bool DqPtrs<T>::push_back(T *t)
203  {
204  bool retval= false;
205  if(t)
206  {
207  if(find(begin(),end(),t) == end()) //It's a new element.
208  {
209  lst_ptr::push_back(t);
210  retval= true;
211  }
212  }
213  else
214  std::cerr << getClassName() << "::" << __FUNCTION__
215  << "; attempt to insert a null pointer." << std::endl;
216  return retval;
217  }
218 
219 template <class T>
220 bool DqPtrs<T>::push_front(T *t)
221  {
222  bool retval= false;
223  if(t)
224  {
225  if(find(begin(),end(),t) == end()) //New element.
226  {
227  lst_ptr::push_front(t);
228  retval= true;
229  }
230  }
231  else
232  std::cerr << getClassName() << "::" << __FUNCTION__
233  << "; attempt to insert a null pointer." << std::endl;
234  return retval;
235  }
236 
238 template <class T>
239 const ID &DqPtrs<T>::getTags(void) const
240  {
241  static ID retval;
242  const int sz= size();
243  if(sz>0)
244  {
245  retval.resize(sz);
246  int loc =0;
247  // loop over objs in deque adding their dbTag to the ID
248  for(const_iterator i= begin();i!=end();i++)
249  {
250  retval(loc)= (*i)->getTag();
251  loc++;
252  }
253  }
254  return retval;
255  }
256 
258 template <class T>
259 int DqPtrs<T>::sendTags(int posSz,int posDbTag,DbTagData &dt,CommParameters &cp)
260  {
261  const int sz= size();
262  int res= cp.sendInt(sz,dt,CommMetaData(posSz));
263  if(sz>0)
264  {
265  const ID &tags= getTags();
266  res+= cp.sendID(tags,dt,CommMetaData(posDbTag));
267  }
268  if(res<0)
269  std::cerr << "DqPtrs<T>::sendDbTags - failed to send the IDs.\n";
270  return res;
271  }
272 
274 template <class T>
275 const ID &DqPtrs<T>::receiveTags(int posSz,int posDbTag,DbTagData &dt,const CommParameters &cp)
276  {
277  static ID retval;
278  int sz= 0;
279  int res= cp.receiveInt(sz,dt,CommMetaData(posSz));
280  if(sz>0)
281  {
282  retval.resize(sz);
283  res= cp.receiveID(retval,dt,CommMetaData(posDbTag));
284  }
285  if(res<0)
286  std::cerr << "DqPtrs<T>::receiveTags - failed to receive the IDs.\n";
287  return retval;
288  }
289 
290 } //end of XC namespace
291 
292 
293 #endif
294 
DqPtrs & operator=(const DqPtrs &)
Assignment operator.
Definition: DqPtrs.h:140
Vector that stores the dbTags of the class members.
Definition: DbTagData.h:43
Vector of integers.
Definition: ID.h:93
Data about the index, size,,...
Definition: CommMetaData.h:38
DqPtrs(CommandEntity *owr=nullptr)
Constructor.
Definition: DqPtrs.h:112
int receiveID(ID &v, const int &) const
Receives el vector.
Definition: CommParameters.cc:79
int receiveInt(int &, DbTagData &, const CommMetaData &) const
Receives the integers through the channel being passed as parameter.
Definition: CommParameters.cc:857
DqPtrs & operator+=(const DqPtrs &)
+= (union) operator.
Definition: DqPtrs.h:149
const ID & getTags(void) const
Returns the tags of the objects.
Definition: DqPtrs.h:239
const ID & receiveTags(int posSz, int pDbTg, DbTagData &dt, const CommParameters &cp)
Sends the dbTags of the sets through the channel being passed as parameter.
Definition: DqPtrs.h:275
int sendInt(const int &, DbTagData &, const CommMetaData &)
Sends the integer through the channel being passed as parameter.
Definition: CommParameters.cc:803
int sendTags(int posSz, int posDbTag, DbTagData &dt, CommParameters &cp)
Sends the dbTags of the sets trough the channel being passed as parameter.
Definition: DqPtrs.h:259
void clearAll(void)
Clears out the list of pointers and erases the properties of the object (if any). ...
Definition: DqPtrs.h:172
int sendID(const ID &, const int &)
Sends vector.
Definition: CommParameters.cc:72
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:34
Communication parameters between processes.
Definition: CommParameters.h:65
void clear(void)
Clears out the list of pointers.
Definition: DqPtrs.h:167
Pointer to (nodes, elements, points, lines,...) container.
Definition: DqPtrs.h:56
bool in(const T *) const
Returns true if the pointer is in the container.
Definition: DqPtrs.h:188
void extend(const DqPtrs &)
Extend this container with the pointers from the container being passed as parameter.
Definition: DqPtrs.h:159