SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
EntangledSource.cpp
Go to the documentation of this file.
1
17/*
18 * @file EntangledSource.cpp
19 * @author nikoapos
20 */
21
24
25namespace SourceXtractor {
26
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.
35 if (entangled_ptr != nullptr) {
36 m_source = entangled_ptr->m_source;
37 }
38}
39
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
80 m_property_holder.setProperty(std::move(property), property_id);
81}
82
86
87} // SourceXtractor namespace
A Task that acts on a SourceGroup to compute one or more properties.
Definition GroupTask.h:36
virtual void computeProperties(SourceGroupInterface &group) const =0
Computes one or more properties for the SourceGroup and/or the Sources it contains.
Identifier used to set and retrieve properties.
Definition PropertyId.h:40
An exception indicating that a Property was not available and could not be computed on demand.
Base class for all Properties. (has no actual content)
Definition Property.h:33
const Property & getProperty(const PropertyId &property_id) const override
void setProperty(std::unique_ptr< Property > property, const PropertyId &property_id) override
EntangledSource(std::shared_ptr< SourceInterface > source, SourceGroupWithOnDemandProperties &group)
SourceGroupWithOnDemandProperties(std::shared_ptr< TaskProvider > task_provider)
T move(T... args)
T dynamic_pointer_cast(T... args)