ShapesFactory.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_SERIALIZE_SHAPESFACTORY_H
17 #define SURGSIM_SERIALIZE_SHAPESFACTORY_H
18 
19 #include "SurgSim/Math/Shape.h"
20 #include <boost/function.hpp>
21 #include <boost/functional/factory.hpp>
22 
23 namespace SurgSim
24 {
25 namespace Serialize
26 {
27 
30 {
31 public:
33  ShapesFactory();
34 
36  virtual ~ShapesFactory();
37 
41  template <class Derived>
42  void registerShape(const std::string& className);
43 
47  std::shared_ptr<SurgSim::Math::Shape> createShape(const std::string& className);
48 
49 private:
51  typedef boost::function<std::shared_ptr<SurgSim::Math::Shape> ()> ShapesFactoryFunction;
52 
54  std::map<std::string, ShapesFactoryFunction> m_registerDirectory;
55 
56 };
57 
58 
59 }
60 }
61 
63 
64 #endif // SURGSIM_SERIALIZE_SHAPESFACTORY_H
Shape.h
SurgSim::Serialize::ShapesFactory::ShapesFactory
ShapesFactory()
Constructor.
Definition: ShapesFactory.cpp:24
ShapesFactory-inl.h
SurgSim::Serialize::ShapesFactory::~ShapesFactory
virtual ~ShapesFactory()
Destructor.
Definition: ShapesFactory.cpp:29
SurgSim::Serialize::ShapesFactory
A factory implementation for shapes.
Definition: ShapesFactory.h:30
SurgSim
Definition: CompoundShapeToGraphics.cpp:30
SurgSim::Serialize::ShapesFactory::registerShape
void registerShape(const std::string &className)
Template version to register a shape into the internal directory.
Definition: ShapesFactory-inl.h:27
SurgSim::Serialize::ShapesFactory::ShapesFactoryFunction
boost::function< std::shared_ptr< SurgSim::Math::Shape >)> ShapesFactoryFunction
A wrapper of function object.
Definition: ShapesFactory.h:51
SurgSim::Serialize::ShapesFactory::m_registerDirectory
std::map< std::string, ShapesFactoryFunction > m_registerDirectory
Look up table for shapes factory.
Definition: ShapesFactory.h:54
SurgSim::Serialize::ShapesFactory::createShape
std::shared_ptr< SurgSim::Math::Shape > createShape(const std::string &className)
Create an instance of derived rigid shape based on the specific class name.
Definition: ShapesFactory.cpp:34
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38