opensurgsim
SceneElement-inl.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013-2016, 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_SCENEELEMENT_INL_H
17 #define SURGSIM_FRAMEWORK_SCENEELEMENT_INL_H
18 
19 #include "SurgSim/Framework/Component.h"
20 
21 
22 namespace SurgSim
23 {
24 
25 namespace Framework
26 {
27 
30 template <class T>
31 std::vector<std::shared_ptr<T>> SceneElement::getComponents() const
32 {
33  std::vector<std::shared_ptr<T>> result;
34 
35  for (auto componentIt = m_components.begin(); componentIt != m_components.end(); ++componentIt)
36  {
37  std::shared_ptr<T> typedElement = std::dynamic_pointer_cast<T>(componentIt->second);
38  if (typedElement)
39  {
40  result.emplace_back(std::move(typedElement));
41  }
42  }
43  return result;
44 }
45 
46 template <class T>
47 T SceneElement::getValue(const std::string& component, const std::string& property) const
48 {
49  auto found = m_components.find(component);
50  SURGSIM_ASSERT(found != m_components.end())
51  << "Component named " << component << " not found in SceneElement named " << getName()
52  << ". Cannot get " << property << " property.";
53  return found->second->getValue<T>(property);
54 }
55 
56 template <class T>
57 bool SceneElement::getValue(const std::string& component, const std::string& property, T* value) const
58 {
59  bool result = false;
60  auto found = m_components.find(component);
61  if (found != m_components.end())
62  {
63  result = found->second->getValue(property, value);
64  }
65  return result;
66 }
67 
68 }; // namespace Framework
69 
70 }; // namespace SurgSim
71 
72 #endif
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
std::vector< std::shared_ptr< Component > > getComponents() const
Gets all the components of this SceneElement.
Definition: SceneElement.cpp:195
std::string getName() const
Return the name of this SceneElement.
Definition: SceneElement.cpp:175
T getValue(const std::string &component, const std::string &property) const
Retrieves the property value from a component.
Definition: SceneElement-inl.h:47
#define SURGSIM_ASSERT(condition)
Assert that condition is true.
Definition: Assert.h:77