SourceXtractorPlusPlus  0.11
Please provide a description of the project.
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 
SourceXtractor::SourceGroupWithOnDemandProperties::merge
void merge(const SourceGroupInterface &other) override
Definition: SourceGroupWithOnDemandProperties.cpp:67
std::shared_ptr< TaskProvider >
std::move
T move(T... args)
SourceXtractor::Property
Base class for all Properties. (has no actual content)
Definition: Property.h:33
std::list::size
T size(T... args)
SourceXtractor::SourceGroupWithOnDemandProperties
A SourceGroupInterface implementation which used a TaskProvider to compute missing properties.
Definition: SourceGroupWithOnDemandProperties.h:42
GroupTask.h
SourceXtractor::PropertyHolder::setProperty
void setProperty(std::unique_ptr< Property > property, const PropertyId &property_id)
Sets a property, overwriting it if necessary.
Definition: PropertyHolder.cpp:40
SourceXtractor::PropertyHolder::isPropertySet
bool isPropertySet(const PropertyId &property_id) const
Returns true if the property is set.
Definition: PropertyHolder.cpp:44
SourceXtractor::PropertyNotFoundException
An exception indicating that a Property was not available and could not be computed on demand.
Definition: PropertyNotFoundException.h:36
SourceXtractor::GroupTask
A Task that acts on a SourceGroup to compute one or more properties.
Definition: GroupTask.h:36
SourceXtractor::SourceGroupWithOnDemandProperties::addSource
void addSource(std::shared_ptr< SourceInterface > source) override
Definition: SourceGroupWithOnDemandProperties.cpp:56
SourceXtractor::SourceGroupWithOnDemandProperties::removeSource
iterator removeSource(iterator pos) override
Definition: SourceGroupWithOnDemandProperties.cpp:61
SourceXtractor::PropertyId
Identifier used to set and retrieve properties.
Definition: PropertyId.h:40
SourceXtractor::PropertyHolder::getProperty
const Property & getProperty(const PropertyId &property_id) const
Returns a reference to a Property if it is set, if not throws a PropertyNotFoundException.
Definition: PropertyHolder.cpp:29
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
Definition: Aperture.h:30
SourceXtractor::SourceGroupWithOnDemandProperties::end
iterator end() override
Definition: SourceGroupWithOnDemandProperties.cpp:36
SourceXtractor::SourceGroupWithOnDemandProperties::m_task_provider
std::shared_ptr< TaskProvider > m_task_provider
Definition: SourceGroupWithOnDemandProperties.h:87
SourceXtractor::SourceGroupWithOnDemandProperties::getProperty
virtual const Property & getProperty(const PropertyId &property_id) const=0
SourceXtractor::SourceGroupWithOnDemandProperties::m_property_holder
PropertyHolder m_property_holder
Definition: SourceGroupWithOnDemandProperties.h:86
SourceXtractor::SourceGroupWithOnDemandProperties::EntangledSource
Definition: SourceGroupWithOnDemandProperties.h:95
std::list::erase
T erase(T... args)
SourceXtractor::SourceGroupWithOnDemandProperties::size
unsigned int size() const override
Definition: SourceGroupWithOnDemandProperties.cpp:107
SourceXtractor::SourceGroupInterface::const_iterator
std::list< SourceWrapper >::const_iterator const_iterator
Definition: SourceGroupInterface.h:82
SourceGroupWithOnDemandProperties.h
std::list::emplace_back
T emplace_back(T... args)
SourceXtractor::SourceGroupInterface
Defines the interface used to group sources.
Definition: SourceGroupInterface.h:37
std::list::begin
T begin(T... args)
SourceXtractor::SourceGroupWithOnDemandProperties::setProperty
virtual void setProperty(std::unique_ptr< Property > property, const PropertyId &property_id)=0
SourceXtractor::PropertyHolder::clear
void clear()
Definition: PropertyHolder.cpp:48
SourceXtractor::SourceGroupWithOnDemandProperties::cend
const_iterator cend() override
Definition: SourceGroupWithOnDemandProperties.cpp:44
SourceXtractor::SourceGroupWithOnDemandProperties::clearGroupProperties
void clearGroupProperties()
Definition: SourceGroupWithOnDemandProperties.cpp:100
SourceXtractor::SourceGroupInterface::iterator
std::list< SourceWrapper >::iterator iterator
Definition: SourceGroupInterface.h:81
SourceXtractor::SourceGroupWithOnDemandProperties::m_sources
std::list< SourceWrapper > m_sources
Definition: SourceGroupWithOnDemandProperties.h:84
std::list::end
T end(T... args)
SourceXtractor::SourceGroupWithOnDemandProperties::cbegin
const_iterator cbegin() override
Definition: SourceGroupWithOnDemandProperties.cpp:40
SourceXtractor::SourceGroupWithOnDemandProperties::begin
iterator begin() override
Definition: SourceGroupWithOnDemandProperties.cpp:32
std::unique_ptr
STL class.
SourceXtractor::SourceGroupWithOnDemandProperties::SourceGroupWithOnDemandProperties
SourceGroupWithOnDemandProperties(std::shared_ptr< TaskProvider > task_provider)
Definition: SourceGroupWithOnDemandProperties.cpp:28