MAST
function_set_base.h
Go to the documentation of this file.
1 /*
2  * MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
3  * Copyright (C) 2013-2019 Manav Bhatia
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #ifndef __mast__function_set_base__
21 #define __mast__function_set_base__
22 
23 
24 // C++ includes
25 #include <vector>
26 #include <map>
27 
28 // MAST includes
29 #include "base/function_base.h"
30 
31 namespace MAST {
32 
37 
38  public:
40 
44  virtual ~FunctionSetBase();
45 
46 
50  bool contains(const std::string& nm) const;
51 
52 
56  void add(MAST::FunctionBase& f);
57 
58 
62  template <typename ValType>
63  const ValType&
64  get(const std::string& nm) const {
65 
66  std::map<std::string, MAST::FunctionBase*>::const_iterator it =
67  _properties.find(nm);
68 
69  // make sure that this funciton exists
70  if(it == _properties.end())
71  libmesh_error_msg("property not found for : " << nm );
72 
73  return dynamic_cast<const ValType&>(*(it->second));
74  }
75 
76 
80  template <typename ValType>
81  ValType&
82  get(const std::string& nm) {
83 
84  std::map<std::string, MAST::FunctionBase*>::iterator it =
85  _properties.find(nm);
86 
87  // make sure that this funciton exists
88  if(it == _properties.end())
89  libmesh_error_msg("property not found for : " << nm );
90 
91  return dynamic_cast<ValType&>(*(it->second));
92  }
93 
94 
98  virtual bool depends_on(const MAST::FunctionBase& f) const;
99 
100 
101  protected:
102 
106  std::map<std::string, MAST::FunctionBase*> _properties;
107  };
108 
109 }
110 
111 
112 #endif // __mast__function_set_base__
virtual ~FunctionSetBase()
destructor deletes the function pointers
void add(MAST::FunctionBase &f)
adds the function to this card and returns a reference to it.
virtual bool depends_on(const MAST::FunctionBase &f) const
returns true if the property card depends on the function f
provides a methods to store property values
std::map< std::string, MAST::FunctionBase * > _properties
map of the functions in this card
bool contains(const std::string &nm) const
checks if the card contains the specified property value