All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FrameworkConvert.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_FRAMEWORKCONVERT_H
17 #define SURGSIM_FRAMEWORK_FRAMEWORKCONVERT_H
18 
19 #include <memory>
20 #include <unordered_map>
21 #include <yaml-cpp/yaml.h>
22 
23 
24 namespace SurgSim
25 {
26 namespace Framework
27 {
28 class Component;
29 class SceneElement;
30 class Scene;
31 }
32 }
33 
34 namespace YAML
35 {
36 
42 template <class T>
43 struct convert<std::shared_ptr<T>>
44 {
45  static YAML::Node encode(
46  const typename std::enable_if <std::is_base_of <SurgSim::Framework::Component, T>::value,
47  std::shared_ptr<T> >::type rhs);
48  static bool decode(
49  const Node& node,
50  typename std::enable_if <std::is_base_of<SurgSim::Framework::Component, T>::value,
51  std::shared_ptr<T> >::type& rhs);
52 };
53 
64 template <>
65 struct convert<std::shared_ptr<SurgSim::Framework::Component> >
66 {
67  static Node encode(const std::shared_ptr<SurgSim::Framework::Component> rhs);
68  static bool decode(const Node& node, std::shared_ptr<SurgSim::Framework::Component>& rhs);
69 
70 private:
71 
72  typedef std::unordered_map<std::string, std::shared_ptr<SurgSim::Framework::Component>> RegistryType;
73 
75  static RegistryType& getRegistry();
76 };
77 
78 
79 
80 
84 template<>
85 struct convert<SurgSim::Framework::Component>
86 {
87  static Node encode(const SurgSim::Framework::Component& rhs);
88 };
89 
90 template<>
91 struct convert<std::shared_ptr<SurgSim::Framework::SceneElement>>
92 {
93  static Node encode(const std::shared_ptr<SurgSim::Framework::SceneElement> rhs);
94  static bool decode(const Node& node, std::shared_ptr<SurgSim::Framework::SceneElement>& rhs);
95 };
96 
97 template<>
98 struct convert<SurgSim::Framework::SceneElement>
99 {
100  static Node encode(const SurgSim::Framework::SceneElement& rhs);
101 };
102 
103 template<>
104 struct convert<std::shared_ptr<SurgSim::Framework::Scene>>
105 {
106  static Node encode(const std::shared_ptr<SurgSim::Framework::Scene> rhs);
107  static bool decode(const Node& node, std::shared_ptr<SurgSim::Framework::Scene>& rhs);
108 };
109 
110 
111 
112 
113 };
114 
116 
117 #endif // SURGSIM_FRAMEWORK_FRAMEWORKCONVERT_H
std::unordered_map< std::string, std::shared_ptr< SurgSim::Framework::Component > > RegistryType
Definition: FrameworkConvert.h:72
Component is the main interface class to pass information to the system managers each will decide whe...
Definition: Component.h:43
SurgSim::Math::Matrix44f convert(boost::any val)
Specialization for convert() to correctly cast Matrix44d to Matrix44f, will throw if the val is no...
Definition: Accessible.cpp:180
SceneElement is the basic part of a scene, it is a container of components.
Definition: SceneElement.h:48