SourceXtractorPlusPlus
0.8
Please provide a description of the project.
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
SEFramework
SEFramework
Source
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
25
#include "
SEFramework/Source/SourceInterface.h
"
26
27
namespace
SourceXtractor {
28
37
class
SourceGroupInterface
:
protected
SourceInterface
{
38
39
template
<
typename
Collection>
40
using
CollectionType
=
typename
std::iterator_traits<typename Collection::iterator>::value_type
;
41
42
// This is used to determine if a type is a kind of std::shared_ptr
43
template
<
class
T>
44
struct
is_shared_ptr
:
std::false_type
{};
45
template
<
class
T>
46
struct
is_shared_ptr
<std::
shared_ptr
<T>> :
std::true_type
{};
47
48
public
:
49
50
template
<
typename
T>
51
class
GroupIterator
;
52
using
iterator
=
GroupIterator<SourceInterface>
;
53
using
const_iterator
=
GroupIterator<const SourceInterface>
;
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"
);
72
static_assert(
std::is_base_of
<
SourceInterface
,
typename
CollectionType<SourceCollection>::element_type
>::value,
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.
83
using
SourceInterface::getProperty
;
84
using
SourceInterface::setProperty
;
85
using
SourceInterface::setIndexedProperty
;
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
:
105
GroupIterator
(
std::unique_ptr<IteratorImpl>
it) :
m_it
(std::
move
(it)) { }
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
:
118
std::shared_ptr<IteratorImpl>
m_it
;
119
};
// end of SourceGroupInterface::GroupIterator
120
121
}
/* namespace SourceXtractor */
122
123
#endif
/* _SEFRAMEWORK_SOURCEGROUPINTERFACE_H */
124
SourceXtractor::SourceGroupInterface::GroupIterator::operator->
T * operator->() const
Definition:
SourceGroupInterface.h:111
std::shared_ptr
SourceXtractor::SourceGroupInterface::is_shared_ptr
Definition:
SourceGroupInterface.h:44
SourceXtractor::SourceInterface::getProperty
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
Definition:
SourceInterface.h:57
SourceXtractor::SourceGroupInterface::cend
virtual const_iterator cend()=0
SourceXtractor::SourceGroupInterface::GroupIterator::getImpl
IteratorImpl & getImpl()
Definition:
SourceGroupInterface.h:116
SourceXtractor::SourceGroupInterface::cbegin
virtual const_iterator cbegin()=0
SourceXtractor::SourceGroupInterface::GroupIterator::GroupIterator
GroupIterator(std::unique_ptr< IteratorImpl > it)
Definition:
SourceGroupInterface.h:105
std::iterator
SourceXtractor::SourceGroupInterface::GroupIterator::operator==
bool operator==(const GroupIterator &other) const
Definition:
SourceGroupInterface.h:114
SourceXtractor::SourceInterface::setIndexedProperty
void setIndexedProperty(std::size_t index, Args...args)
Convenience template method to call setProperty() with a more user-friendly syntax.
Definition:
SourceInterface.h:64
SourceXtractor::SourceGroupInterface::addSource
virtual void addSource(std::shared_ptr< SourceInterface > source)=0
SourceXtractor::SourceGroupInterface::GroupIterator::m_it
std::shared_ptr< IteratorImpl > m_it
Definition:
SourceGroupInterface.h:118
SourceXtractor::SourceGroupInterface::GroupIterator::operator=
GroupIterator & operator=(const GroupIterator &other)
Definition:
SourceGroupInterface.h:108
SourceXtractor::SourceGroupInterface::IteratorImpl::dereference
virtual SourceInterface & dereference() const =0
SourceXtractor::SourceGroupInterface::merge
virtual void merge(const SourceGroupInterface &other)=0
SourceXtractor::SourceInterface::setProperty
void setProperty(Args...args)
Definition:
SourceInterface.h:72
SourceXtractor::SourceGroupInterface::GroupIterator
Definition:
SourceGroupInterface.h:51
SourceXtractor::SourceGroupInterface::GroupIterator::operator--
GroupIterator & operator--()
Definition:
SourceGroupInterface.h:113
std::iterator_traits
SourceXtractor::SourceGroupInterface::GroupIterator::operator!=
bool operator!=(const GroupIterator &other) const
Definition:
SourceGroupInterface.h:115
std::move
T move(T...args)
SourceXtractor::SourceGroupInterface::IteratorImpl::increment
virtual void increment()=0
SourceInterface.h
SourceXtractor::SourceGroupInterface
Defines the interface used to group sources.
Definition:
SourceGroupInterface.h:37
SourceXtractor::SourceGroupInterface::CollectionType
typename std::iterator_traits< typename Collection::iterator >::value_type CollectionType
Definition:
SourceGroupInterface.h:40
SourceXtractor::SourceGroupInterface::addAllSources
void addAllSources(const SourceCollection &sources)
Convenient method to add all the sources of a collection.
Definition:
SourceGroupInterface.h:69
std::unique_ptr
STL class.
SourceXtractor::SourceGroupInterface::GroupIterator::GroupIterator
GroupIterator(const GroupIterator &other)
Definition:
SourceGroupInterface.h:107
std::false_type
SourceXtractor::SourceGroupInterface::end
virtual iterator end()=0
std::is_base_of
SourceXtractor::SourceGroupInterface::IteratorImpl::equal
virtual bool equal(const IteratorImpl &other) const =0
SourceXtractor::SourceGroupInterface::begin
virtual iterator begin()=0
SourceXtractor::SourceGroupInterface::IteratorImpl::~IteratorImpl
virtual ~IteratorImpl()=default
SourceXtractor::SourceGroupInterface::IteratorImpl::decrement
virtual void decrement()=0
SourceXtractor::SourceGroupInterface::removeSource
virtual iterator removeSource(iterator pos)=0
SourceXtractor::SourceGroupInterface::GroupIterator::operator*
T & operator*() const
Definition:
SourceGroupInterface.h:110
SourceXtractor::SourceGroupInterface::GroupIterator::operator++
GroupIterator & operator++()
Definition:
SourceGroupInterface.h:112
SourceXtractor::SourceInterface
The SourceInterface is an abstract "source" that has properties attached to it.
Definition:
SourceInterface.h:46
SourceXtractor::SourceGroupInterface::size
virtual unsigned int size() const =0
SourceXtractor::SourceGroupInterface::IteratorImpl::clone
virtual std::shared_ptr< IteratorImpl > clone() const =0
SourceXtractor::SourceGroupInterface::IteratorImpl
Definition:
SourceGroupInterface.h:89
Generated by
1.8.5