SourceXtractorPlusPlus  0.19
SourceXtractor++, the next generation SExtractor
 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 public:
43 
44  class SourceWrapper : public SourceInterface {
45  public:
46 
47  explicit SourceWrapper(std::unique_ptr<SourceInterface> source) : m_source(std::move(source)) {}
48 
49  SourceWrapper(const SourceWrapper& source) = delete;
50 
51  SourceWrapper(SourceWrapper&&) = default;
52 
53  const Property& getProperty(const PropertyId& property_id) const override {
54  return m_source->getProperty(property_id);
55  }
56 
57  void setProperty(std::unique_ptr<Property> property, const PropertyId& property_id) override {
58  m_source->setProperty(std::move(property), property_id);
59  }
60 
61  bool operator<(const SourceWrapper& other) const {
62  return this->m_source < other.m_source;
63  }
64 
66  return *m_source;
67  }
68 
72 
73  private:
75  };
76 
79 
80  virtual iterator begin() = 0;
81  virtual iterator end() = 0;
82  virtual const_iterator cbegin() const = 0;
83  virtual const_iterator cend() const = 0;
84  virtual const_iterator begin() const = 0;
85  virtual const_iterator end() const = 0;
86 
87  virtual void addSource(std::unique_ptr<SourceInterface> source) = 0;
88  virtual iterator removeSource(iterator pos) = 0;
89  virtual void merge(SourceGroupInterface&& other) = 0;
90  virtual unsigned int size() const = 0;
91 
93  template <typename SourceCollection>
94  void addAllSources(SourceCollection&& sources) {
96  "SourceCollection must be a collection of std::shared_ptr to SourceInterface or a type that inherits from it");
97  for (auto& source : sources) {
98  addSource(std::move(source));
99  }
100  sources.clear();
101  }
102 
103  // We introduce the get/setProperty methods from the SourceInterface in the
104  // public symbols so they become part of the SourceGroupInterface. The group
105  // implementations must implement the methods with the PropertyId
106  // in their signature.
110 
111 }; // end of SourceGroupInterface class
112 
113 } /* namespace SourceXtractor */
114 
115 #endif /* _SEFRAMEWORK_SOURCEGROUPINTERFACE_H */
116 
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
void setProperty(std::unique_ptr< Property > property, const PropertyId &property_id) override
std::list< SourceWrapper >::iterator iterator
const Property & getProperty(const PropertyId &property_id) const override
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 merge(SourceGroupInterface &&other)=0
Base class for all Properties. (has no actual content)
Definition: Property.h:33
void addAllSources(SourceCollection &&sources)
Convenient method to add all the sources of a collection.
STL class.
T move(T...args)
virtual const_iterator cbegin() const =0
Defines the interface used to group sources.
typename std::iterator_traits< typename Collection::iterator >::value_type CollectionType
STL class.
SourceWrapper(std::unique_ptr< SourceInterface > source)
Identifier used to set and retrieve properties.
Definition: PropertyId.h:40
std::list< SourceWrapper >::const_iterator const_iterator
virtual const_iterator cend() const =0
virtual void addSource(std::unique_ptr< SourceInterface > source)=0
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