PhysicsFactory.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012 Open Source Robotics Foundation
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*/
17/*
18 * Desc: Factory for creating physics engine
19 * Author: Nate Koenig
20 * Date: 21 May 2009
21 */
22
23#ifndef _PHYSICSFACTORY_HH_
24#define _PHYSICSFACTORY_HH_
25
26#include <string>
27#include <map>
28
30#include "gazebo/util/system.hh"
31
32namespace gazebo
33{
34 namespace physics
35 {
38
42
45 class GZ_PHYSICS_VISIBLE PhysicsFactory
46 {
48 public: static void RegisterAll();
49
54 public: static void RegisterPhysicsEngine(std::string _className,
55 PhysicsFactoryFn _factoryfn);
56
61 const std::string &_className, WorldPtr _world);
62
66 public: static bool IsRegistered(const std::string &_name);
67
69 private: static std::map<std::string, PhysicsFactoryFn> engines;
70 };
71
77 #define GZ_REGISTER_PHYSICS_ENGINE(name, classname) \
78 PhysicsEnginePtr New##classname(WorldPtr _world) \
79 { \
80 return PhysicsEnginePtr(new gazebo::physics::classname(_world)); \
81 } \
82 void Register##classname() \
83 {\
84 PhysicsFactory::RegisterPhysicsEngine(name, New##classname);\
85 }
87 }
88}
89#endif
default namespace for gazebo
The physics factory instantiates different physics engines.
Definition PhysicsFactory.hh:46
static PhysicsEnginePtr NewPhysicsEngine(const std::string &_className, WorldPtr _world)
Create a new instance of a physics engine.
static void RegisterPhysicsEngine(std::string _className, PhysicsFactoryFn _factoryfn)
Register a physics class.
static bool IsRegistered(const std::string &_name)
Check if a physics engine is registered.
static void RegisterAll()
Register everything.
PhysicsEnginePtr(* PhysicsFactoryFn)(WorldPtr world)
Definition PhysicsFactory.hh:41
boost::shared_ptr< PhysicsEngine > PhysicsEnginePtr
Definition PhysicsTypes.hh:125
boost::shared_ptr< World > WorldPtr
Definition PhysicsTypes.hh:89
Forward declarations for the common classes.
Definition Animation.hh:27