ShapesFactory.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_SERIALIZE_SHAPESFACTORY_H
#define SURGSIM_SERIALIZE_SHAPESFACTORY_H
#include "SurgSim/Math/Shape.h"
#include <boost/function.hpp>
#include <boost/functional/factory.hpp>
namespace SurgSim
{
namespace Serialize
{
class ShapesFactory
{
public:
ShapesFactory();
virtual ~ShapesFactory();
template <class Derived>
void registerShape(const std::string& className);
std::shared_ptr<SurgSim::Math::Shape> createShape(const std::string& className);
private:
typedef boost::function<std::shared_ptr<SurgSim::Math::Shape> ()> ShapesFactoryFunction;
std::map<std::string, ShapesFactoryFunction> m_registerDirectory;
};
}
}
#include "SurgSim/Serialize/ShapesFactory-inl.h"
#endif // SURGSIM_SERIALIZE_SHAPESFACTORY_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
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::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::~ShapesFactory
virtual ~ShapesFactory()
Destructor.
Definition: ShapesFactory.cpp:29
ShapesFactory-inl.h
SurgSim::Serialize::ShapesFactory::ShapesFactory
ShapesFactory()
Constructor.
Definition: ShapesFactory.cpp:24
Shape.h
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
A factory implementation for shapes.
Definition: ShapesFactory.h:29
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