SourceXtractorPlusPlus  0.11
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SourceGroupInterface.h
Go to the documentation of this file.
1 
17 /*
18  * @file SourceGroupInterface.h
19  * @author nikoapos
20  */
21 
22 #ifndef _SEFRAMEWORK_SOURCEGROUPINTERFACE_H
23 #define _SEFRAMEWORK_SOURCEGROUPINTERFACE_H
24 
26 
27 namespace SourceXtractor {
28 
38 
39  template <typename Collection>
41 
42  // This is used to determine if a type is a kind of std::shared_ptr
43  template <class T>
45  template <class T>
46  struct is_shared_ptr<std::shared_ptr<T>> : std::true_type {};
47 
48 public:
49 
50  class SourceWrapper : public SourceInterface {
51  public:
52 
54 
55  SourceWrapper(const SourceWrapper& source) : m_source(source.m_source) {}
56 
57  const Property& getProperty(const PropertyId& property_id) const override {
58  return m_source->getProperty(property_id);
59  }
60 
61  void setProperty(std::unique_ptr<Property> property, const PropertyId& property_id) override {
62  m_source->setProperty(std::move(property), property_id);
63  }
64 
65  bool operator<(const SourceWrapper& other) const {
66  return this->m_source < other.m_source;
67  }
68 
70  return *m_source;
71  }
72 
76 
77  private:
79  };
80 
83 
84  virtual iterator begin() = 0;
85  virtual iterator end() = 0;
86  virtual const_iterator cbegin() = 0;
87  virtual const_iterator cend() = 0;
88  virtual const_iterator begin() const = 0;
89  virtual const_iterator end() const = 0;
90 
91  virtual void addSource(std::shared_ptr<SourceInterface> source) = 0;
92  virtual iterator removeSource(iterator pos) = 0;
93  virtual void merge(const SourceGroupInterface& other) = 0;
94  virtual unsigned int size() const = 0;
95 
97  template <typename SourceCollection>
98  void addAllSources(const SourceCollection& sources) {
99  static_assert(is_shared_ptr<CollectionType<SourceCollection>>::value,
100  "SourceCollection must be a collection of std::shared_ptr");
102  "SourceCollection must be a collection of std::shared_ptr to SourceInterface or a type that inherits from it");
103  for (auto& source : sources) {
104  addSource(source);
105  }
106  }
107 
108  // We introduce the get/setProperty methods from the SourceInterface in the
109  // public symbols so they become part of the SourceGroupInterface. The group
110  // implementations must implement the methods with the PropertyId
111  // in their signature.
115 
116 }; // end of SourceGroupInterface class
117 
118 } /* namespace SourceXtractor */
119 
120 #endif /* _SEFRAMEWORK_SOURCEGROUPINTERFACE_H */
121 
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
virtual const_iterator cend()=0
void setProperty(std::unique_ptr< Property > property, const PropertyId &property_id) override
std::list< SourceWrapper >::iterator iterator
virtual const_iterator cbegin()=0
const Property & getProperty(const PropertyId &property_id) const override
SourceWrapper(std::shared_ptr< SourceInterface > source)
void setIndexedProperty(std::size_t index, Args...args)
Convenience template method to call setProperty() with a more user-friendly syntax.
bool operator<(const SourceWrapper &other) const
virtual void addSource(std::shared_ptr< SourceInterface > source)=0
Base class for all Properties. (has no actual content)
Definition: Property.h:33
virtual void merge(const SourceGroupInterface &other)=0
STL class.
T move(T...args)
Defines the interface used to group sources.
typename std::iterator_traits< typename Collection::iterator >::value_type CollectionType
void addAllSources(const SourceCollection &sources)
Convenient method to add all the sources of a collection.
STL class.
Identifier used to set and retrieve properties.
Definition: PropertyId.h:40
std::list< SourceWrapper >::const_iterator const_iterator
virtual iterator removeSource(iterator pos)=0
The SourceInterface is an abstract &quot;source&quot; that has properties attached to it.
virtual unsigned int size() const =0