xc
ModelComponentContainer.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 //ModelComponentContainer.h
28 
29 #ifndef ModelComponentContainer_H
30 #define ModelComponentContainer_H
31 
32 #include "preprocessor/multi_block_topology/ModelComponentContainerBase.h"
33 #include <map>
34 #include "boost/python/list.hpp"
35 
36 namespace XC {
37 
39 //
41 template <class T>
42  class ModelComponentContainer: public ModelComponentContainerBase, public std::map<ModelComponentContainerBase::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 
51 
52  T * busca(const Indice &);
53  const T * busca(const Indice &) const;
54  bool exists(const Indice &) const;
55  T * get(const Indice &);
56  boost::python::list getKeys(void) const;
57 
58  void clearAll(void);
59  virtual ~ModelComponentContainer(void);
60  };
61 
63 template <class T>
66 
68 template <class T>
69 T * ModelComponentContainer<T>::busca(const Indice &id)
70  { T * retval= nullptr;
71  iterator i= this->find(id);
72  if(i!= this->end()) //Entity exists.
73  retval= (*i).second;
74  return retval;
75  }
76 
78 template <class T>
79 const T * ModelComponentContainer<T>::busca(const Indice &id) const
80  {
81  const T * retval= nullptr;
82  const_iterator i= this->find(id);
83  if(i!= this->end()) //Entity exists.
84  retval= (*i).second;
85  return retval;
86  }
87 
89 template <class T>
90 bool ModelComponentContainer<T>::exists(const Indice &id) const
91  { return (busca(id)!=nullptr); }
92 
93 
95 template <class T>
96 T * ModelComponentContainer<T>::get(const size_t &iEnt)
97  {
98  T *retval= busca(iEnt);
99  if(!retval)
100  std::cerr << getClassName() << "::" << __FUNCTION__
101  << "; entity: '"
102  << iEnt << "' not found.\n";
103  return retval;
104  }
105 
107 template <class T>
109  {
110  for(iterator i=this->begin();i!=this->end();i++)
111  {
112  T * tmp= (*i).second;
113  if(tmp)
114  delete tmp;
115  tmp= nullptr;
116  }
117  this->clear();
118  }
119 
121 template <class T>
122 boost::python::list ModelComponentContainer<T>::getKeys(void) const
123  {
124  boost::python::list retval;
125  for(const_iterator i=this->begin();i!=this->end();i++)
126  retval.append((*i).first);
127  return retval;
128  }
129 
131 template <class T>
133  { clearAll(); }
134 
135 } //end of XC namespace
136 #endif
virtual ~ModelComponentContainer(void)
Destructor.
Definition: ModelComponentContainer.h:132
Model geometry manager.
Definition: MultiBlockTopology.h:68
boost::python::list getKeys(void) const
Return the container&#39;s keys.
Definition: ModelComponentContainer.h:122
void clearAll(void)
Erase all the entities.
Definition: ModelComponentContainer.h:108
Base class for model component containers.
Definition: ModelComponentContainerBase.h:42
bool exists(const Indice &) const
Return true if the entity already exists.
Definition: ModelComponentContainer.h:90
ModelComponentContainer(MultiBlockTopology *mbt=nullptr)
Constructor.
Definition: ModelComponentContainer.h:64
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:34
Container for model entities.
Definition: ModelComponentContainer.h:42
T * busca(const Indice &)
Return a pointer to the geometry entity whose identifier is passed as parameter.
Definition: ModelComponentContainer.h:69