SourceXtractorPlusPlus  0.11
Please provide a description of the project.
 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(std::make_shared<EntangledSource>(source, *this));
59 }
60 
62  auto next_iter = m_sources.erase(pos);
64  return next_iter;
65 }
66 
68  auto& other_group = dynamic_cast<const 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(std::make_shared<EntangledSource>(entangled_source.m_source, *this));
75  }
77 }
78 
80  // If we already have the property, return it
81  if (m_property_holder.isPropertySet(property_id)) {
82  return m_property_holder.getProperty(property_id);
83  }
84 
85  // If not, get the task for that property, use it to compute the property then return it
86  auto task = m_task_provider->getTask<GroupTask>(property_id);
87  if (task) {
88  task->computeProperties(const_cast<SourceGroupWithOnDemandProperties&>(*this));
89  return m_property_holder.getProperty(property_id);
90  }
91 
92  // No task available to make that property, we throw an exception
93  throw PropertyNotFoundException(property_id);
94 }
95 
97  m_property_holder.setProperty(std::move(property), property_id);
98 }
99 
102  for (auto& source : m_sources) {
103  dynamic_cast<EntangledSource&>(source.getRef()).m_property_holder.clear();
104  }
105 }
106 
108  return m_sources.size();
109 }
110 
111 } // SourceXtractor namespace
112 
113 
114 
void merge(const SourceGroupInterface &other) override
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.
void addSource(std::shared_ptr< SourceInterface > source) override
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)
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)