XC Open source finite element analysis program
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/nucleo/EntCmd.h"
35 #include "xc_utils/src/nucleo/EntPropSorter.h"
36 #include <deque>
37 #include <set>
38 #include "utility/actor/actor/MovableID.h"
39 #include <boost/iterator/indirect_iterator.hpp>
40 
41 
42 
43 namespace XC {
44 
56 template <class T>
57 class DqPtrs: public EntCmd, protected std::deque<T *>
58  {
59  public:
60  typedef typename std::deque<T *> lst_ptr;
61  typedef typename lst_ptr::const_iterator const_iterator;
62  typedef typename lst_ptr::iterator iterator;
63  typedef typename lst_ptr::reference reference;
64  typedef typename lst_ptr::const_reference const_reference;
65  typedef typename lst_ptr::size_type size_type;
66  typedef boost::indirect_iterator<iterator> indIterator;
67  public:
68  DqPtrs(EntCmd *owr= nullptr);
69  DqPtrs(const DqPtrs &otro);
70  explicit DqPtrs(const std::deque<T *> &ts);
71  explicit DqPtrs(const std::set<const T *> &ts);
72  DqPtrs &operator=(const DqPtrs &);
73  void extend(const DqPtrs &);
74  //void extend_cond(const DqPtrs &otro,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(EntCmd *owr)
113  : EntCmd(owr),lst_ptr() {}
114 
116 template <class T>
118  : EntCmd(otro), lst_ptr(otro)
119  {}
120 
122 template <class T>
123 DqPtrs<T>::DqPtrs(const std::deque<T *> &ts)
124  : EntCmd(), lst_ptr(ts)
125  {}
126 
128 template <class T>
129 DqPtrs<T>::DqPtrs(const std::set<const T *> &st)
130  : EntCmd(), 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  EntCmd::operator=(otro);
143  lst_ptr::operator=(otro);
144  return *this;
145  }
146 
149 template <class T>
150 void DqPtrs<T>::extend(const DqPtrs &otro)
151  {
152  for(register const_iterator i= otro.begin();i!=otro.end();i++)
153  push_back(*i);
154  }
155 
157 template<class T>
159  { lst_ptr::clear(); }
160 
162 template<class T>
164  {
165  clear();
166  EntCmd::clearPyProps();
167  }
168 
170 template<class T>
171 const T &DqPtrs<T>::get(const size_t &i) const
172  {
173  const T *ptr= lst_ptr::at(i);
174  return *ptr;
175  }
176 
178 template<class T>
179 bool DqPtrs<T>::in(const T *ptr) const
180  {
181  bool retval= false;
182  for(const_iterator i= begin();i!= end();i++)
183  if(*i==ptr)
184  {
185  retval= true;
186  break;
187  }
188  return retval;
189  }
190 
191 
192 template <class T>
193 bool DqPtrs<T>::push_back(T *t)
194  {
195  bool retval= false;
196  if(t)
197  {
198  if(find(begin(),end(),t) == end()) //It's a new element.
199  {
200  lst_ptr::push_back(t);
201  retval= true;
202  }
203  }
204  else
205  std::cerr << nombre_clase() << "::" << __FUNCTION__
206  << "; attempt to insert a null pointer." << std::endl;
207  return retval;
208  }
209 
210 template <class T>
211 bool DqPtrs<T>::push_front(T *t)
212  {
213  bool retval= false;
214  if(t)
215  {
216  if(find(begin(),end(),t) == end()) //New element.
217  {
218  lst_ptr::push_front(t);
219  retval= true;
220  }
221  }
222  else
223  std::cerr << nombre_clase() << "::" << __FUNCTION__
224  << "; attempt to insert a null pointer." << std::endl;
225  return retval;
226  }
227 
229 template <class T>
230 const ID &DqPtrs<T>::getTags(void) const
231  {
232  static ID retval;
233  const int sz= size();
234  if(sz>0)
235  {
236  retval.resize(sz);
237  int loc =0;
238  // loop over objs in deque adding their dbTag to the ID
239  for(const_iterator i= begin();i!=end();i++)
240  {
241  retval(loc)= (*i)->getTag();
242  loc++;
243  }
244  }
245  return retval;
246  }
247 
249 template <class T>
250 int DqPtrs<T>::sendTags(int posSz,int posDbTag,DbTagData &dt,CommParameters &cp)
251  {
252  const int sz= size();
253  int res= cp.sendInt(sz,dt,CommMetaData(posSz));
254  if(sz>0)
255  {
256  const ID &tags= getTags();
257  res+= cp.sendID(tags,dt,CommMetaData(posDbTag));
258  }
259  if(res<0)
260  std::cerr << "DqPtrs<T>::sendDbTags - failed to send the IDs.\n";
261  return res;
262  }
263 
265 template <class T>
266 const ID &DqPtrs<T>::receiveTags(int posSz,int posDbTag,DbTagData &dt,const CommParameters &cp)
267  {
268  static ID retval;
269  int sz= 0;
270  int res= cp.receiveInt(sz,dt,CommMetaData(posSz));
271  if(sz>0)
272  {
273  retval.resize(sz);
274  res= cp.receiveID(retval,dt,CommMetaData(posDbTag));
275  }
276  if(res<0)
277  std::cerr << "DqPtrs<T>::receiveTags - failed to receive the IDs.\n";
278  return retval;
279  }
280 
281 } //end of XC namespace
282 
283 
284 #endif
285 
Pointer to (nodes, elements, points, lines,...) container.
Definition: DqPtrs.h:57
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:266
DqPtrs(EntCmd *owr=nullptr)
Constructor.
Definition: DqPtrs.h:112
void clear(void)
Clears out the list of pointers.
Definition: DqPtrs.h:158
Vector que almacena los dbTags de los miembros de la clase.
Definition: DbTagData.h:43
int sendID(const ID &, const int &)
Sends vector.
Definition: CommParameters.cc:72
const ID & getTags(void) const
Returns the Tags de los objetos.
Definition: DqPtrs.h:230
DqPtrs & operator=(const DqPtrs &)
Assignment operator.
Definition: DqPtrs.h:140
int receiveID(ID &v, const int &) const
Recibe el vector.
Definition: CommParameters.cc:79
Definition: ID.h:77
int receiveInt(int &, DbTagData &, const CommMetaData &) const
Recibe the integers through the channel being passed as parameter.
Definition: CommParameters.cc:751
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:250
void clearAll(void)
Clears out the list of pointers and erases the properties of the object (if any). ...
Definition: DqPtrs.h:163
bool in(const T *) const
Returns true if the pointer is in the container.
Definition: DqPtrs.h:179
int sendInt(const int &, DbTagData &, const CommMetaData &)
Sends the integer through the channel being passed as parameter.
Definition: CommParameters.cc:697
void extend(const DqPtrs &)
Extend this container with the pointers from the container being passed as parameter.
Definition: DqPtrs.h:150
Communication parameters between processes.
Definition: CommParameters.h:65
================================================================================
Definition: ContinuaReprComponent.h:34
const T & get(const size_t &i) const
Access specified node with bounds checking.
Definition: DqPtrs.h:171
Data about the index, size,,... of the object to transmit.
Definition: CommMetaData.h:38