SourceXtractorPlusPlus  0.8
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 
34 }
35 
38 }
39 
42 }
43 
46 }
47 
50 }
51 
54 }
55 
58  m_sources.emplace_back(source, *this);
59 }
60 
62  iter& iter_impl = dynamic_cast<iter&>(pos.getImpl());
63  auto next_entangled_it = m_sources.erase(iter_impl.m_entangled_it);
65  return iterator(std::unique_ptr<IteratorImpl>(new iter{next_entangled_it}));
66 }
67 
69  auto& other_group = dynamic_cast<const SourceGroupWithOnDemandProperties&>(other);
70  // We go through the EntangledSources of the other group and we create new ones
71  // locally, pointing to the same wrapped sources. This is necessary, so the
72  // new EntangledSources have a reference to the correct group.
73  for (auto& source : other_group.m_sources) {
74  this->m_sources.emplace_back( source.m_source, *this);
75  }
76  this->clearGroupProperties();
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  const_cast<EntangledSource&>(source).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
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
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
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.
STL class.
Identifier used to set and retrieve properties.
Definition: PropertyId.h:40
GroupIterator< SourceInterface > iterator
GroupIterator< const SourceInterface > 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