SensorFactory.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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 
std::shared_ptr< Sensor > SensorPtr
Definition: SensorTypes.hh:63
Forward declarations for the common classes.
Definition: Animation.hh:33
Sensor *(* SensorFactoryFn)()
Definition: SensorFactory.hh:41
Forward declarations and typedefs for sensors.
Base class for sensors.
Definition: Sensor.hh:50
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:59
Definition: SensorFactory.hh:47