17 #ifndef IGNITION_SENSORS_SENSORFACTORY_HH_ 18 #define IGNITION_SENSORS_SENSORFACTORY_HH_ 22 #include <type_traits> 25 #include <ignition/common/Console.hh> 26 #include <ignition/common/SuppressWarning.hh> 28 #include <ignition/sensors/config.hh> 29 #include <ignition/sensors/Export.hh> 38 inline namespace IGNITION_SENSORS_VERSION_NAMESPACE {
40 class SensorFactoryPrivate;
49 public:
virtual Sensor IGN_DEPRECATED(6) * New() = 0;
56 template<
class SensorType>
60 public: SensorType IGN_DEPRECATED(6) *
New()
override 62 return new SensorType();
85 public:
template<
typename SensorType>
88 auto sensor = std::make_unique<SensorType>();
90 if (
nullptr == sensor)
92 ignerr <<
"Failed to create sensor [" << _sdf.Name()
93 <<
"] of type[" << _sdf.TypeStr() <<
"]" <<
std::endl;
97 if (!sensor->Load(_sdf))
99 ignerr <<
"Failed to load sensor [" << _sdf.Name()
100 <<
"] of type[" << _sdf.TypeStr() <<
"]" <<
std::endl;
106 ignerr <<
"Failed to initialize sensor [" << _sdf.Name()
107 <<
"] of type[" << _sdf.TypeStr() <<
"]" <<
std::endl;
120 public:
template<
typename SensorType>
125 ignerr <<
"Failed to create sensor, received null SDF " 130 auto sensor = std::make_unique<SensorType>();
135 if (
nullptr == sensor)
137 ignerr <<
"Failed to create sensor [" << name
138 <<
"] of type[" << type <<
"]" <<
std::endl;
142 if (!sensor->Load(_sdf))
144 ignerr <<
"Failed to load sensor [" << name
145 <<
"] of type[" << type <<
"]" <<
std::endl;
151 ignerr <<
"Failed to initialize sensor [" << name
152 <<
"] of type[" << type <<
"]" <<
std::endl;
167 sdf::ElementPtr _sdf);
186 const sdf::Sensor &_sdf);
191 public:
void IGN_DEPRECATED(6) AddPluginPaths(
const std::string &_path);
193 IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
196 IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
A factory class for creating sensors This class instantiates sensor objects based on the sensor type ...
Definition: SensorFactory.hh:72
a base sensor class
Definition: Sensor.hh:59
SensorType * New() override
Instantiate new sensor.
Definition: SensorFactory.hh:60
std::unique_ptr< SensorType > CreateSensor(const sdf::Sensor &_sdf)
Create a sensor from a SDF DOM object with a known sensor type.
Definition: SensorFactory.hh:86
Base sensor plugin interface.
Definition: SensorFactory.hh:45
Templated class for instantiating sensors of the specified type.
Definition: SensorFactory.hh:57
std::unique_ptr< SensorType > CreateSensor(sdf::ElementPtr _sdf)
Create a sensor from an SDF element with a known sensor type.
Definition: SensorFactory.hh:121
Definition: AirPressureSensor.hh:31