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 2012 Nate Koenig
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 
30 #include "sensors/SensorTypes.hh"
31 
32 namespace gazebo
33 {
36  namespace sensors
37  {
40  typedef Sensor* (*SensorFactoryFn) ();
41 
47  {
56  public: static void RegisterAll();
57 
62  public: static void RegisterSensor(const std::string &_classname,
63  SensorFactoryFn _factoryfn);
64 
69  public: static SensorPtr NewSensor(const std::string &_classname);
70 
74  public: static void GetSensorTypes(std::vector<std::string> &_types);
75 
77  private: static std::map<std::string, SensorFactoryFn> sensorMap;
78  };
79 
80 
86  #define GZ_REGISTER_STATIC_SENSOR(name, classname) \
87  Sensor *New##classname() \
88  { \
89  return new gazebo::sensors::classname(); \
90  } \
91  void Register##classname() \
92  {\
93  SensorFactory::RegisterSensor(name, New##classname);\
94  }
95 
96  }
97 }
98 
99 #endif
100 
101