All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SensorFactory.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 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 sensors
19  * Author: Andrew Howard
20  * Date: 18 May 2003
21  */
22 
23 #ifndef _SENSORFACTORY_HH_
24 #define _SENSORFACTORY_HH_
25 
26 #include <string>
27 #include <map>
28 #include <vector>
29 
31 #include "gazebo/util/system.hh"
32 
33 namespace gazebo
34 {
37  namespace sensors
38  {
41  typedef Sensor* (*SensorFactoryFn) ();
42 
48  {
59  public: static void RegisterAll();
60 
64  public: static void RegisterSensor(const std::string &_className,
65  SensorFactoryFn _factoryfn);
66 
71  public: static SensorPtr NewSensor(const std::string &_className);
72 
76  public: static void GetSensorTypes(std::vector<std::string> &_types);
77 
79  private: static std::map<std::string, SensorFactoryFn> sensorMap;
80  };
81 
82 
88  #define GZ_REGISTER_STATIC_SENSOR(name, classname) \
89  GAZEBO_VISIBLE Sensor *New##classname() \
90  { \
91  return new gazebo::sensors::classname(); \
92  } \
93  GAZEBO_VISIBLE \
94  void Register##classname() \
95  {\
96  SensorFactory::RegisterSensor(name, New##classname);\
97  }
98  }
100 }
101 
102 #endif
103 
104