XC Open source finite element analysis program
MapCadMember.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 //MapCadMember.h
28 
29 #ifndef MAPCADMEMBER_H
30 #define MAPCADMEMBER_H
31 
32 #include "preprocessor/cad/MapCadMemberBase.h"
33 #include <map>
34 #include "boost/python/list.hpp"
35 
36 namespace XC {
37 
39 //
41 template <class T>
42  class MapCadMember: public MapCadMemberBase, public std::map<MapCadMemberBase::Indice,T *>
43  {
44  public:
45  typedef typename std::map<Indice,T *> map_base;
46  typedef typename std::pair<Indice,T *> pair;
47  typedef typename map_base::iterator iterator;
48  typedef typename map_base::const_iterator const_iterator;
49 
50  MapCadMember(Cad *cad= nullptr);
51 
52  T * busca(const Indice &);
53  const T * busca(const Indice &) const;
54  bool existe(const Indice &) const;
55  T * get(const Indice &);
56  boost::python::list getKeys(void) const;
57 
58  void clearAll(void);
59  virtual ~MapCadMember(void);
60 
61 
62  };
63 
65 template <class T>
67  : MapCadMemberBase(cad) {}
68 
70 template <class T>
71 T * MapCadMember<T>::busca(const Indice &id)
72  { T * retval= nullptr;
73  iterator i= this->find(id);
74  if(i!= this->end()) //La entidad existe.
75  retval= (*i).second;
76  return retval;
77  }
78 
80 template <class T>
81 const T * MapCadMember<T>::busca(const Indice &id) const
82  {
83  const T * retval= nullptr;
84  const_iterator i= this->find(id);
85  if(i!= this->end()) //La entidad existe.
86  retval= (*i).second;
87  return retval;
88  }
89 
91 template <class T>
92 bool MapCadMember<T>::existe(const Indice &id) const
93  { return (busca(id)!=nullptr); }
94 
95 
97 template <class T>
98 T * MapCadMember<T>::get(const size_t &iEnt)
99  {
100  T *retval= busca(iEnt);
101  if(!retval)
102  std::cerr << nombre_clase() << "::" << __FUNCTION__
103  << "; entity: '"
104  << iEnt << "' not found.\n";
105  return retval;
106  }
107 
109 template <class T>
111  {
112  for(iterator i=this->begin();i!=this->end();i++)
113  {
114  T * tmp= (*i).second;
115  if(tmp)
116  delete tmp;
117  tmp= nullptr;
118  }
119  this->clear();
120  }
121 
123 template <class T>
124 boost::python::list MapCadMember<T>::getKeys(void) const
125  {
126  boost::python::list retval;
127  for(const_iterator i=this->begin();i!=this->end();i++)
128  retval.append((*i).first);
129  return retval;
130  }
131 
133 template <class T>
135  { clearAll(); }
136 
137 } //end of XC namespace
138 #endif
T * busca(const Indice &)
Return a pointer to the geometry entity whose identifier is passed as parameter.
Definition: MapCadMember.h:71
virtual ~MapCadMember(void)
Destructor.
Definition: MapCadMember.h:134
Base class for entity containers of the model.
Definition: MapCadMemberBase.h:42
MapCadMember(Cad *cad=nullptr)
Constructor.
Definition: MapCadMember.h:66
boost::python::list getKeys(void) const
Return the container&#39;s keys.
Definition: MapCadMember.h:124
T * get(const Indice &)
Return the entity with tag iEnt.
Definition: MapCadMember.h:98
Container for model entities.
Definition: MapCadMember.h:42
Model geometry manager. Management of geometry entities: points, lines, surfaces, bodies...
Definition: Cad.h:69
bool existe(const Indice &) const
Return true if the entity already exists.
Definition: MapCadMember.h:92
void clearAll(void)
Erase all the entities.
Definition: MapCadMember.h:110
================================================================================
Definition: ContinuaReprComponent.h:34