SourceXtractorPlusPlus 0.19.2
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SourceGroupWithOnDemandProperties.cpp
Go to the documentation of this file.
1
25
26namespace SourceXtractor {
27
29 : m_task_provider(task_provider) {
30}
31
33 return m_sources.begin();
34}
35
37 return m_sources.end();
38}
39
41 return m_sources.cbegin();
42}
43
45 return m_sources.cend();
46}
47
49 return m_sources.cbegin();
50}
51
53 return m_sources.cend();
54}
55
58 m_sources.emplace_back(Euclid::make_unique<EntangledSource>(std::move(source), *this));
59}
60
62 auto next_iter = m_sources.erase(pos);
64 return next_iter;
65}
66
68 auto& other_group = dynamic_cast<SourceGroupWithOnDemandProperties&>(other);
69 // We go through the EntangledSources of the other group and we create new ones
70 // locally, pointing to the same wrapped sources. This is necessary, so the
71 // new EntangledSources have a reference to the correct group.
72 for (auto& source : other_group.m_sources) {
73 auto& entangled_source = dynamic_cast<EntangledSource&>(source.getRef());
74 m_sources.emplace_back(Euclid::make_unique<EntangledSource>(std::move(entangled_source.m_source), *this));
75 }
76 other_group.m_sources.clear();
78}
79
81 // If we already have the property, return it
82 if (m_property_holder.isPropertySet(property_id)) {
83 return m_property_holder.getProperty(property_id);
84 }
85
86 // If not, get the task for that property, use it to compute the property then return it
87 auto task = m_task_provider->getTask<GroupTask>(property_id);
88 if (task) {
90 return m_property_holder.getProperty(property_id);
91 }
92
93 // No task available to make that property, we throw an exception
94 throw PropertyNotFoundException(property_id);
95}
96
98 m_property_holder.setProperty(std::move(property), property_id);
99}
100
103 for (auto& source : m_sources) {
104 dynamic_cast<EntangledSource&>(source.getRef()).m_property_holder.clear();
105 }
106}
107
109 return m_sources.size();
110}
111
112} // SourceXtractor namespace
113
114
115
T begin(T... args)
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.
bool isPropertySet(const PropertyId &property_id) const
Returns true if the property is set.
const Property & getProperty(const PropertyId &property_id) const
Returns a reference to a Property if it is set, if not throws a PropertyNotFoundException.
void setProperty(std::unique_ptr< Property > property, const PropertyId &property_id)
Sets a property, overwriting it if necessary.
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
Defines the interface used to group sources.
std::list< SourceWrapper >::const_iterator const_iterator
std::list< SourceWrapper >::iterator iterator
A SourceGroupInterface implementation which used a TaskProvider to compute missing properties.
SourceGroupWithOnDemandProperties(std::shared_ptr< TaskProvider > task_provider)
const Property & getProperty(const PropertyId &property_id) const override
void setProperty(std::unique_ptr< Property > property, const PropertyId &property_id) override
void addSource(std::unique_ptr< SourceInterface > source) override
T emplace_back(T... args)
T end(T... args)
T erase(T... args)
T move(T... args)
T size(T... args)