SourceXtractorPlusPlus  0.19
SourceXtractor++, the next generation SExtractor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SourceGroupWithOnDemandProperties.cpp
Go to the documentation of this file.
1 
25 
26 namespace 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) {
89  task->computeProperties(const_cast<SourceGroupWithOnDemandProperties&>(*this));
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 
std::list< SourceWrapper >::iterator iterator
A SourceGroupInterface implementation which used a TaskProvider to compute missing properties...
virtual void computeProperties(SourceGroupInterface &group) const =0
Computes one or more properties for the SourceGroup and/or the Sources it contains.
T end(T...args)
SourceGroupWithOnDemandProperties(std::shared_ptr< TaskProvider > task_provider)
Base class for all Properties. (has no actual content)
Definition: Property.h:33
A Task that acts on a SourceGroup to compute one or more properties.
Definition: GroupTask.h:36
T erase(T...args)
void setProperty(std::unique_ptr< Property > property, const PropertyId &property_id) override
const Property & getProperty(const PropertyId &property_id) const
Returns a reference to a Property if it is set, if not throws a PropertyNotFoundException.
T move(T...args)
bool isPropertySet(const PropertyId &property_id) const
Returns true if the property is set.
Defines the interface used to group sources.
T size(T...args)
void addSource(std::unique_ptr< SourceInterface > source) override
STL class.
Identifier used to set and retrieve properties.
Definition: PropertyId.h:40
T begin(T...args)
std::list< SourceWrapper >::const_iterator const_iterator
void setProperty(std::unique_ptr< Property > property, const PropertyId &property_id)
Sets a property, overwriting it if necessary.
An exception indicating that a Property was not available and could not be computed on demand...
const Property & getProperty(const PropertyId &property_id) const override
T emplace_back(T...args)