SourceXtractorPlusPlus  0.12
Please provide a description of the project.
EntangledSource.cpp
Go to the documentation of this file.
1 
17 /*
18  * @file EntangledSource.cpp
19  * @author nikoapos
20  */
21 
24 
25 namespace SourceXtractor {
26 
28  : m_source(source), m_group(group) {
29  // Normally, it should not be possible that the given source is of type
30  // EntangledSource, because the entangled sources of a group can only be
31  // accessed via the iterator as references. Nevertheless, to be sure that
32  // future changes will not change the behavior, we do a check to the given
33  // source and if it is an EntangledSource we use its encapsulated source instead.
34  auto entangled_ptr = std::dynamic_pointer_cast<EntangledSource>(m_source);
35  if (entangled_ptr != nullptr) {
36  m_source = entangled_ptr->m_source;
37  }
38 }
39 
41 
42  // If we already have the property stored in this object, returns it
43  if (m_property_holder.isPropertySet(property_id)) {
44  return m_property_holder.getProperty(property_id);
45  }
46 
47  // If the property is already stored in the group, we return it
48  if (m_group.m_property_holder.isPropertySet(property_id)) {
49  return m_group.getProperty(property_id);
50  }
51 
52  try {
53  // Try to get the the property from the encapsulated Source
54  // if it cannot provide it, this will throw a PropertyNotFoundException
55  return m_source->getProperty(property_id);
56  } catch (PropertyNotFoundException& e) {
57  // Getting this exception means the property must be computed at the group level
58 
59  // Get the group task
60  auto group_task = m_group.m_task_provider->getTask<GroupTask>(property_id);
61  if (!group_task) {
62  // No task is available to make that property
63  throw PropertyNotFoundException(property_id);
64  }
65 
66  // Use the task to make the property
67  group_task->computeProperties(m_group);
68 
69  // The property should now be available either in this object or in the group object
70  if (m_property_holder.isPropertySet(property_id)) {
71  return m_property_holder.getProperty(property_id);
72  } else {
73  return m_group.m_property_holder.getProperty(property_id);
74  }
75  }
76 
77 } // end of getProperty()
78 
80  m_property_holder.setProperty(std::move(property), property_id);
81 }
82 
84  return this->m_source < other.m_source;
85 }
86 
87 } // SourceXtractor namespace
void setProperty(std::unique_ptr< Property > property, const PropertyId &property_id) override
A SourceGroupInterface implementation which used a TaskProvider to compute missing properties...
constexpr double e
const Property & getProperty(const PropertyId &property_id) const
Returns a reference to a Property if it is set, if not throws a PropertyNotFoundException.
const Property & getProperty(const PropertyId &property_id) const override
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
bool isPropertySet(const PropertyId &property_id) const
Returns true if the property is set.
T dynamic_pointer_cast(T... args)
T move(T... args)
STL class.
Identifier used to set and retrieve properties.
Definition: PropertyId.h:40
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...
EntangledSource(std::shared_ptr< SourceInterface > source, SourceGroupWithOnDemandProperties &group)