SourceXtractorPlusPlus  0.15
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SourceInterface.h
Go to the documentation of this file.
1 
23 #ifndef _SEFRAMEWORK_SOURCE_SOURCEINTERFACE_H
24 #define _SEFRAMEWORK_SOURCE_SOURCEINTERFACE_H
25 
26 #include <memory>
27 #include <type_traits>
28 
32 
33 namespace SourceXtractor {
34 
47 
48 public:
49 
53  virtual ~SourceInterface() = default;
54 
56  template<typename PropertyType>
57  const PropertyType& getProperty(unsigned int index = 0) const {
58  static_assert(std::is_base_of<Property, PropertyType>::value, "PropertyType must inherit from SourceXtractor::Property");
59  return dynamic_cast<const PropertyType&>(getProperty(PropertyId::create<PropertyType>(index)));
60  }
61 
63  template<typename PropertyType, typename ... Args>
64  void setIndexedProperty(std::size_t index, Args... args) {
65  static_assert(std::is_base_of<Property, PropertyType>::value, "PropertyType must inherit from SourceXtractor::Property");
66  static_assert(std::is_constructible<PropertyType, Args...>::value, "PropertyType must be constructible from args");
67  setProperty(std::unique_ptr<PropertyType>{new PropertyType(std::forward<Args>(args)...)},
68  PropertyId::create<PropertyType>(index));
69  }
70 
71  template<typename PropertyType, typename ... Args>
72  void setProperty(Args... args) {
73  setIndexedProperty<PropertyType>(0, std::forward<Args>(args)...);
74  }
75 
78  virtual const Property& getProperty(const PropertyId& property_id) const = 0;
79  virtual void setProperty(std::unique_ptr<Property> property, const PropertyId& property_id) = 0;
80 
81 }; /* End of SourceInterface class */
82 
83 } /* namespace SourceXtractor */
84 
85 
86 #endif
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
void setIndexedProperty(std::size_t index, Args...args)
Convenience template method to call setProperty() with a more user-friendly syntax.
virtual ~SourceInterface()=default
Destructor.
Base class for all Properties. (has no actual content)
Definition: Property.h:33
STL class.
Identifier used to set and retrieve properties.
Definition: PropertyId.h:40
The SourceInterface is an abstract &quot;source&quot; that has properties attached to it.