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 Asset;
29 class Component;
30 class SceneElement;
31 class Scene;
32 }
33 }
34 
35 namespace YAML
36 {
37 
43 template <class T>
44 struct convert<std::shared_ptr<T>>
45 {
46  static YAML::Node encode(
47  const typename std::enable_if <std::is_base_of <SurgSim::Framework::Component, T>::value,
48  std::shared_ptr<T>>::type rhs);
49  static bool decode(
50  const Node& node,
51  typename std::enable_if <std::is_base_of<SurgSim::Framework::Component, T>::value,
52  std::shared_ptr<T>>::type& rhs); //NOLINT
53 };
54 
55 
66 template <>
67 struct convert<std::shared_ptr<SurgSim::Framework::Component>>
68 {
69  static Node encode(const std::shared_ptr<SurgSim::Framework::Component> rhs);
70  static bool decode(const Node& node, std::shared_ptr<SurgSim::Framework::Component>& rhs); //NOLINT
71 
72  typedef std::unordered_map<std::string, std::shared_ptr<SurgSim::Framework::Component>> RegistryType;
73 
75  static RegistryType& getRegistry();
76 };
77 
81 template<>
82 struct convert<SurgSim::Framework::Component>
83 {
84  static Node encode(const SurgSim::Framework::Component& rhs);
85 };
86 
87 template<>
88 struct convert<std::shared_ptr<SurgSim::Framework::SceneElement>>
89 {
90  static Node encode(const std::shared_ptr<SurgSim::Framework::SceneElement> rhs);
91  static bool decode(const Node& node, std::shared_ptr<SurgSim::Framework::SceneElement>& rhs); //NOLINT
92 };
93 
94 template<>
95 struct convert <std::vector<std::shared_ptr<SurgSim::Framework::SceneElement>>>
96 {
97 
98  static bool decode(const Node& node,
99  std::vector<std::shared_ptr<SurgSim::Framework::SceneElement>>& rhs, //NOLINT
100  std::vector<std::string>* stack = nullptr);
101 };
102 
103 
104 template<>
105 struct convert<SurgSim::Framework::SceneElement>
106 {
107  static Node encode(const SurgSim::Framework::SceneElement& rhs);
108 };
109 
110 template<>
111 struct convert<std::shared_ptr<SurgSim::Framework::Scene>>
112 {
113  static Node encode(const std::shared_ptr<SurgSim::Framework::Scene> rhs);
114  static bool decode(const Node& node, std::shared_ptr<SurgSim::Framework::Scene>& rhs); //NOLINT
115 };
116 
117 template<>
118 struct convert<std::shared_ptr<SurgSim::Framework::Asset>>
119 {
120  static Node encode(const std::shared_ptr<SurgSim::Framework::Asset> rhs);
121  static bool decode(const Node& node, std::shared_ptr<SurgSim::Framework::Asset>& rhs); //NOLINT
122 };
123 
124 
125 };
126 
128 
129 #endif // SURGSIM_FRAMEWORK_FRAMEWORKCONVERT_H
SurgSim::Framework::Component
Component is the main interface class to pass information to the system managers each will decide whe...
Definition: Component.h:42
YAML
Definition: DataStructuresConvert.h:28
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
YAML::convert< std::shared_ptr< SurgSim::Framework::Component > >::RegistryType
std::unordered_map< std::string, std::shared_ptr< SurgSim::Framework::Component > > RegistryType
Definition: FrameworkConvert.h:72
FrameworkConvert-inl.h
SurgSim::Framework::SceneElement
SceneElement is the basic part of a scene, it is a container of components.
Definition: SceneElement.h:51
SurgSim::Framework::convert
SurgSim::Math::Matrix44f convert(boost::any val)
Specialization for convert<T>() to correctly cast Matrix44d to Matrix44f, will throw if the val is no...
Definition: Accessible.cpp:210