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 
32 namespace 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 
60  public: static PhysicsEnginePtr NewPhysicsEngine(
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  }
86  }
88 }
89 #endif
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:89
Forward declarations for the common classes.
Definition: Animation.hh:33
The physics factory instantiates different physics engines.
Definition: PhysicsFactory.hh:45
default namespace for gazebo
boost::shared_ptr< PhysicsEngine > PhysicsEnginePtr
Definition: PhysicsTypes.hh:125
PhysicsEnginePtr(* PhysicsFactoryFn)(WorldPtr world)
Definition: PhysicsFactory.hh:41