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 
31 
32 namespace gazebo
33 {
36  namespace sensors
37  {
40  typedef Sensor* (*SensorFactoryFn) ();
41 
47  {
56  public: static void RegisterAll();
57 
61  public: static void RegisterSensor(const std::string &_className,
62  SensorFactoryFn _factoryfn);
63 
68  public: static SensorPtr NewSensor(const std::string &_className);
69 
73  public: static void GetSensorTypes(std::vector<std::string> &_types);
74 
76  private: static std::map<std::string, SensorFactoryFn> sensorMap;
77  };
78 
79 
85  #define GZ_REGISTER_STATIC_SENSOR(name, classname) \
86  Sensor *New##classname() \
87  { \
88  return new gazebo::sensors::classname(); \
89  } \
90  void Register##classname() \
91  {\
92  SensorFactory::RegisterSensor(name, New##classname);\
93  }
94 
95  }
96 }
97 
98 #endif
99 
100