Accessible-inl.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_FRAMEWORK_ACCESSIBLE_INL_H
17 #define SURGSIM_FRAMEWORK_ACCESSIBLE_INL_H
18 
20 
21 template <class T>
22 bool SurgSim::Framework::Accessible::getValue(const std::string& name, T* value) const
23 {
24  bool result = false;
25  auto functors = m_functors.find(name);
26  if (value != nullptr && functors != m_functors.end() && functors->second.getter != nullptr)
27  {
28  try
29  {
30  *value = boost::any_cast<T>(functors->second.getter());
31  result = true;
32  }
33  catch (boost::bad_any_cast exception)
34  {
35 
36  }
37  }
38  return result;
39 }
40 
41 template <class T>
43 {
44  T result;
45  try
46  {
47  result = boost::any_cast<T>(getValue(name));
48  }
49  catch (boost::bad_any_cast exception)
50  {
51  SURGSIM_FAILURE() << "Failure to cast to the given type. <" << exception.what() << ">";
52  return T();
53  }
54  return result;
55 }
56 
57 template <class T>
58 T SurgSim::Framework::convert(boost::any val)
59 {
60  return boost::any_cast<T>(val);
61 }
62 
63 #endif
Assert.h
The header that provides the assertion API.
SURGSIM_FAILURE
#define SURGSIM_FAILURE()
Report that something very bad has happened and abort program execution.
Definition: Assert.h:95
SurgSim::Framework::Accessible::m_functors
std::unordered_map< std::string, Functors > m_functors
Definition: Accessible.h:173
SurgSim::Framework::convert
SurgSim::Math::Matrix44f convert(boost::any val)
Wrap boost::any_cast to use in std::bind, for some reason it does not work by itself.
Definition: Accessible.cpp:210
SurgSim::Framework::Accessible::getValue
T getValue(const std::string &name) const
Retrieves the value with the name by executing the getter if it is found and tries to convert it to t...
Definition: Accessible-inl.h:42
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38