SourceXtractorPlusPlus  0.8
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  template <typename T>
54 
55  virtual iterator begin() = 0;
56  virtual iterator end() = 0;
57  virtual const_iterator cbegin() = 0;
58  virtual const_iterator cend() = 0;
59  virtual const_iterator begin() const = 0;
60  virtual const_iterator end() const = 0;
61 
62  virtual void addSource(std::shared_ptr<SourceInterface> source) = 0;
63  virtual iterator removeSource(iterator pos) = 0;
64  virtual void merge(const SourceGroupInterface& other) = 0;
65  virtual unsigned int size() const = 0;
66 
68  template <typename SourceCollection>
69  void addAllSources(const SourceCollection& sources) {
70  static_assert(is_shared_ptr<CollectionType<SourceCollection>>::value,
71  "SourceCollection must be a collection of std::shared_ptr");
73  "SourceCollection must be a collection of std::shared_ptr to SourceInterface or a type that inherits from it");
74  for (auto& source : sources) {
75  addSource(source);
76  }
77  }
78 
79  // We introduce the get/setProperty methods from the SourceInterface in the
80  // public symbols so they become part of the SourceGroupInterface. The group
81  // implementations must implemented the protected methods with the PropertyId
82  // in their signature.
86 
87 protected:
88 
89  class IteratorImpl {
90  public:
91  virtual ~IteratorImpl() = default;
92  virtual SourceInterface& dereference() const = 0;
93  virtual void increment() = 0;
94  virtual void decrement() = 0;
95  virtual bool equal(const IteratorImpl& other) const = 0;
96  virtual std::shared_ptr<IteratorImpl> clone() const = 0;
97  };
98 
99 }; // end of SourceGroupInterface class
100 
101 
102 template <typename T>
103 class SourceGroupInterface::GroupIterator : public std::iterator<std::forward_iterator_tag, T> {
104 public:
106 
107  GroupIterator(const GroupIterator& other) : m_it(other.m_it->clone()) {}
108  GroupIterator& operator=(const GroupIterator& other) { m_it = other.m_it->clone(); return *this; }
109 
110  T& operator*() const { return m_it->dereference(); }
111  T* operator->() const { return &(m_it->dereference()); }
112  GroupIterator& operator++() { m_it->increment(); return *this; }
113  GroupIterator& operator--() { m_it->decrement(); return *this; }
114  bool operator==(const GroupIterator& other) const { return m_it->equal(*other.m_it); }
115  bool operator!=(const GroupIterator& other) const { return !m_it->equal(*other.m_it); }
116  IteratorImpl& getImpl() { return *m_it; }
117 private:
119 }; // end of SourceGroupInterface::GroupIterator
120 
121 } /* namespace SourceXtractor */
122 
123 #endif /* _SEFRAMEWORK_SOURCEGROUPINTERFACE_H */
124 
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
virtual const_iterator cbegin()=0
bool operator==(const GroupIterator &other) const
void setIndexedProperty(std::size_t index, Args...args)
Convenience template method to call setProperty() with a more user-friendly syntax.
virtual void addSource(std::shared_ptr< SourceInterface > source)=0
GroupIterator & operator=(const GroupIterator &other)
virtual SourceInterface & dereference() const =0
virtual void merge(const SourceGroupInterface &other)=0
bool operator!=(const GroupIterator &other) const
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.
virtual bool equal(const IteratorImpl &other) const =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
virtual std::shared_ptr< IteratorImpl > clone() const =0