SourceXtractorPlusPlus
0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SEFramework
src
lib
Source
EntangledSource.cpp
Go to the documentation of this file.
1
17
/*
18
* @file EntangledSource.cpp
19
* @author nikoapos
20
*/
21
22
#include "
SEFramework/Source/SourceGroupWithOnDemandProperties.h
"
23
#include "
SEFramework/Task/GroupTask.h
"
24
25
namespace
SourceXtractor
{
26
27
SourceGroupWithOnDemandProperties::EntangledSource::EntangledSource
(
std::shared_ptr<SourceInterface>
source
,
SourceGroupWithOnDemandProperties
&
group
)
28
: m_source(
source
), m_group(
group
) {
29
// Normally, it should not be possible that the given source is of type
30
// EntangledSource, because the entangled sources of a group can only be
31
// accessed via the iterator as references. Nevertheless, to be sure that
32
// future changes will not change the behavior, we do a check to the given
33
// source and if it is an EntangledSource we use its encapsulated source instead.
34
auto
entangled_ptr
=
std::dynamic_pointer_cast<EntangledSource>
(
m_source
);
35
if
(
entangled_ptr
!=
nullptr
) {
36
m_source
=
entangled_ptr
->m_source;
37
}
38
}
39
40
const
Property
&
SourceGroupWithOnDemandProperties::EntangledSource::getProperty
(
const
PropertyId
&
property_id
)
const
{
41
42
// If we already have the property stored in this object, returns it
43
if
(
m_property_holder
.
isPropertySet
(
property_id
)) {
44
return
m_property_holder
.
getProperty
(
property_id
);
45
}
46
47
// If the property is already stored in the group, we return it
48
if
(m_group.m_property_holder.isPropertySet(
property_id
)) {
49
return
m_group.getProperty(
property_id
);
50
}
51
52
try
{
53
// Try to get the the property from the encapsulated Source
54
// if it cannot provide it, this will throw a PropertyNotFoundException
55
return
m_source->getProperty(
property_id
);
56
}
catch
(
PropertyNotFoundException
& e) {
57
// Getting this exception means the property must be computed at the group level
58
59
// Get the group task
60
auto
group_task
= m_group.m_task_provider->getTask<
GroupTask
>(
property_id
);
61
if
(!
group_task
) {
62
// No task is available to make that property
63
throw
PropertyNotFoundException
(
property_id
);
64
}
65
66
// Use the task to make the property
67
group_task
->computeProperties(m_group);
68
69
// The property should now be available either in this object or in the group object
70
if
(
m_property_holder
.
isPropertySet
(
property_id
)) {
71
return
m_property_holder
.
getProperty
(
property_id
);
72
}
else
{
73
return
m_group.m_property_holder.getProperty(
property_id
);
74
}
75
}
76
77
}
// end of getProperty()
78
79
void
SourceGroupWithOnDemandProperties::EntangledSource::setProperty
(
std::unique_ptr<Property>
property
,
const
PropertyId
&
property_id
) {
80
m_property_holder
.
setProperty
(
std::move
(
property
),
property_id
);
81
}
82
83
bool
SourceGroupWithOnDemandProperties::EntangledSource::operator<
(
const
EntangledSource
&
other
)
const
{
84
return
this->m_source <
other
.m_source;
85
}
86
87
}
// SourceXtractor namespace
GroupTask.h
SourceGroupWithOnDemandProperties.h
SourceXtractor::GroupTask
A Task that acts on a SourceGroup to compute one or more properties.
Definition
GroupTask.h:36
SourceXtractor::PropertyHolder::isPropertySet
bool isPropertySet(const PropertyId &property_id) const
Returns true if the property is set.
Definition
PropertyHolder.cpp:44
SourceXtractor::PropertyHolder::getProperty
const Property & getProperty(const PropertyId &property_id) const
Returns a reference to a Property if it is set, if not throws a PropertyNotFoundException.
Definition
PropertyHolder.cpp:29
SourceXtractor::PropertyHolder::setProperty
void setProperty(std::unique_ptr< Property > property, const PropertyId &property_id)
Sets a property, overwriting it if necessary.
Definition
PropertyHolder.cpp:40
SourceXtractor::PropertyId
Identifier used to set and retrieve properties.
Definition
PropertyId.h:40
SourceXtractor::PropertyNotFoundException
An exception indicating that a Property was not available and could not be computed on demand.
Definition
PropertyNotFoundException.h:36
SourceXtractor::Property
Base class for all Properties. (has no actual content)
Definition
Property.h:33
SourceXtractor::SourceGroupWithOnDemandProperties::EntangledSource
Definition
SourceGroupWithOnDemandProperties.h:96
SourceXtractor::SourceGroupWithOnDemandProperties::EntangledSource::getProperty
const Property & getProperty(const PropertyId &property_id) const override
Definition
EntangledSource.cpp:40
SourceXtractor::SourceGroupWithOnDemandProperties::EntangledSource::operator<
bool operator<(const EntangledSource &other) const
Definition
EntangledSource.cpp:83
SourceXtractor::SourceGroupWithOnDemandProperties::EntangledSource::m_source
std::shared_ptr< SourceInterface > m_source
Definition
SourceGroupWithOnDemandProperties.h:113
SourceXtractor::SourceGroupWithOnDemandProperties::EntangledSource::setProperty
void setProperty(std::unique_ptr< Property > property, const PropertyId &property_id) override
Definition
EntangledSource.cpp:79
SourceXtractor::SourceGroupWithOnDemandProperties::EntangledSource::EntangledSource
EntangledSource(std::shared_ptr< SourceInterface > source, SourceGroupWithOnDemandProperties &group)
Definition
EntangledSource.cpp:27
SourceXtractor::SourceGroupWithOnDemandProperties
A SourceGroupInterface implementation which used a TaskProvider to compute missing properties.
Definition
SourceGroupWithOnDemandProperties.h:43
SourceXtractor::SourceGroupWithOnDemandProperties::m_property_holder
PropertyHolder m_property_holder
Definition
SourceGroupWithOnDemandProperties.h:87
std::function
std::move
T move(T... args)
SourceXtractor
Definition
Aperture.h:30
Generated by
1.10.0