SensorFactory.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 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
33namespace gazebo
34{
37 namespace sensors
38 {
41 typedef Sensor* (*SensorFactoryFn) ();
42
48 {
59 public: GZ_SENSORS_VISIBLE static void RegisterAll();
60
64 public: GZ_SENSORS_VISIBLE static void RegisterSensor(
65 const std::string &_className, SensorFactoryFn _factoryfn);
66
71 public: GZ_SENSORS_VISIBLE static SensorPtr NewSensor(
72 const std::string &_className);
73
77 public: GZ_SENSORS_VISIBLE static void GetSensorTypes(
78 std::vector<std::string> &_types);
79
81 private: static std::map<std::string, SensorFactoryFn> sensorMap;
82 };
83
84
90 #define GZ_REGISTER_STATIC_SENSOR(name, classname) \
91 Sensor *New##classname() \
92 { \
93 return new gazebo::sensors::classname(); \
94 } \
95 \
96 void Register##classname() \
97 {\
98 SensorFactory::RegisterSensor(name, New##classname);\
99 }
101 }
102}
103
104#endif
105
106
sensors
Definition SensorManager.hh:35
Forward declarations and typedefs for sensors.
Definition SensorFactory.hh:48
static void GetSensorTypes(std::vector< std::string > &_types)
Get all the sensor types.
static void RegisterSensor(const std::string &_className, SensorFactoryFn _factoryfn)
Register a sensor class (called by sensor registration function).
static SensorPtr NewSensor(const std::string &_className)
Create a new instance of a sensor.
static void RegisterAll()
Register all known sensors.
Base class for sensors.
Definition Sensor.hh:53
Sensor *(* SensorFactoryFn)()
Definition SensorFactory.hh:41
std::shared_ptr< Sensor > SensorPtr
Definition SensorTypes.hh:64
Forward declarations for the common classes.
Definition Animation.hh:27