XC Open source finite element analysis program
DqPtrsNmb.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 //DqPtrsNmb.h
28 //deque de pointers (se emplear en la clase Set).
29 
30 
31 #ifndef DQPTRSNMB_H
32 #define DQPTRSNMB_H
33 
34 #include "DqPtrs.h"
35 #include "xc_utils/src/geom/pos_vec/Pos3d.h"
36 
37 namespace XC {
38 
39 template <class T>
40 class DqPtrsNmb: public DqPtrs<T>
41  {
42  public:
43  typedef DqPtrs<T> dq_ptr;
44  typedef typename dq_ptr::const_iterator const_iterator;
45  typedef typename dq_ptr::iterator iterator;
46 
47  DqPtrsNmb(EntCmd *owr= nullptr)
48  : DqPtrs<T>(owr) {}
49  DqPtrsNmb(const DqPtrs<T> &otro)
50  : DqPtrs<T>(otro) {}
51  explicit DqPtrsNmb(const std::deque<T *> &ts)
52  : DqPtrs<T>(ts) {}
53  explicit DqPtrsNmb(const std::set<const T *> &ts)
54  : DqPtrs<T>(ts) {}
55 
56  T *BuscaNmb(const std::string &nmb);
57  T *getNearest(const Pos3d &p);
58  const T *getNearest(const Pos3d &p) const;
59 
60  };
61 
63 template <class T>
64 T *DqPtrsNmb<T>::BuscaNmb(const std::string &nmb)
65  {
66  for(const_iterator i= this->begin();i!=this->end();i++)
67  if((*i)->GetNombre()==nmb) return *i;
68  return nullptr;
69  }
70 
72 template <class T>
73 T *DqPtrsNmb<T>::getNearest(const Pos3d &p)
74  {
75  T *retval= nullptr;
76  if(!this->empty())
77  {
78  const_iterator i= this->begin();
79  double d2= (*i)->DistanciaA2(p);
80  retval= *i; i++;
81  double tmp;
82  for(;i!=this->end();i++)
83  {
84  tmp= (*i)->DistanciaA2(p);
85  if(tmp<d2)
86  {
87  d2= tmp;
88  retval= *i;
89  }
90  }
91  }
92  return retval;
93  }
94 
96 template <class T>
97 const T *DqPtrsNmb<T>::getNearest(const Pos3d &p) const
98  {
99  const T *retval= nullptr;
100  if(!this->empty())
101  {
102  const_iterator i= this->begin();
103  double d2= (*i)->DistanciaA2(p);
104  retval= *i; i++;
105  double tmp;
106  for(;i!=this->end();i++)
107  {
108  tmp= (*i)->DistanciaA2(p);
109  if(tmp<d2)
110  {
111  d2= tmp;
112  retval= *i;
113  }
114  }
115  }
116  return retval;
117  }
118 
119 } //end of XC namespace
120 
121 #endif
122 
Pointer to (nodes, elements, points, lines,...) container.
Definition: DqPtrs.h:57
T * getNearest(const Pos3d &p)
Returns the object closest to the position being passed as parameter.
Definition: DqPtrsNmb.h:73
T * BuscaNmb(const std::string &nmb)
Returns a pointer to the objeto cuyo nombre being passed as parameter.
Definition: DqPtrsNmb.h:64
================================================================================
Definition: ContinuaReprComponent.h:34
Definition: DqPtrsNmb.h:40