SourceXtractorPlusPlus
1.0.3
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::GroupTask::computeProperties
virtual void computeProperties(SourceGroupInterface &group) const =0
Computes one or more properties for the SourceGroup and/or the Sources it contains.
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::m_group
SourceGroupWithOnDemandProperties & m_group
Definition
SourceGroupWithOnDemandProperties.h:114
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_property_holder
PropertyHolder m_property_holder
Definition
SourceGroupWithOnDemandProperties.h:112
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::SourceGroupWithOnDemandProperties
SourceGroupWithOnDemandProperties(std::shared_ptr< TaskProvider > task_provider)
Definition
SourceGroupWithOnDemandProperties.cpp:32
std::move
T move(T... args)
SourceXtractor
Definition
Aperture.h:30
std::dynamic_pointer_cast
T dynamic_pointer_cast(T... args)
std::shared_ptr
std::unique_ptr
Generated by
1.15.0