SourceXtractorPlusPlus  0.11
Please provide a description of the project.
SourceGrouping.cpp
Go to the documentation of this file.
1 
24 
25 
26 namespace SourceXtractor {
27 
30  : m_grouping_criteria(grouping_criteria), m_group_factory(group_factory) {
31 }
32 
34  // Pointer which points to the group of the source
35  std::shared_ptr<SourceGroupInterface> matched_group = nullptr;
36 
38 
39  for (auto group_it = m_source_groups.begin(); group_it != m_source_groups.end(); ++group_it) {
40  // Search if the source meets the grouping criteria with any of the sources in the group
41  bool in_group = false;
42  for (auto& s : **group_it) {
43  if (m_grouping_criteria->shouldGroup(*source, s)) {
44  in_group = true;
45  break; // No need to check the rest of the group sources
46  }
47  }
48 
49  if (in_group) {
50  if (matched_group == nullptr) {
51  matched_group = *group_it;
52  matched_group->addSource(source);
53  } else {
54  matched_group->merge(**group_it);
55  groups_to_remove.emplace_back(group_it);
56  }
57  }
58  }
59 
60  // If there was no group the source should be grouped in, we create a new one
61  if (matched_group == nullptr) {
62  matched_group = m_group_factory->createSourceGroup();
63  matched_group->addSource(source);
64  m_source_groups.emplace_back(matched_group);
65  }
66 
67  for (auto& group_it : groups_to_remove) {
68  m_source_groups.erase(group_it);
69  }
70 }
71 
74 
75  // We iterate through all the SourceGroups we have
76  for (auto group_it = m_source_groups.begin(); group_it != m_source_groups.end(); ++group_it) {
77  // We look at its Sources and if we find at least one that needs to be processed we put it in groups_to_process
78  for (auto& source : **group_it) {
79  if (process_event.m_selection_criteria.mustBeProcessed(source)) {
80  groups_to_process.push_back(group_it);
81  break;
82  }
83  }
84  }
85 
86  // For each SourceGroup that we put in groups_to_process,
87  for (auto& group : groups_to_process) {
88  // we remove it from our list of stored SourceGroups and notify our observers
89  notifyObservers(*group);
90  m_source_groups.erase(group);
91  }
92 }
93 
94 } // SEFramework namespace
95 
96 
97 
std::shared_ptr< SourceGroupFactory > m_group_factory
virtual void handleMessage(const std::shared_ptr< SourceInterface > &source) override
Handles a new Source.
constexpr double s
Event received by SourceGrouping to request the processing of some of the Sources stored...
const SelectionCriteria & m_selection_criteria
T end(T... args)
T push_back(T... args)
std::list< std::shared_ptr< SourceGroupInterface > > m_source_groups
SourceGrouping(std::shared_ptr< GroupingCriteria > grouping_criteria, std::shared_ptr< SourceGroupFactory > group_factory)
std::shared_ptr< GroupingCriteria > m_grouping_criteria
void notifyObservers(const std::shared_ptr< SourceGroupInterface > &message) const
Definition: Observable.h:71
T erase(T... args)
STL class.
virtual bool mustBeProcessed(const SourceInterface &source) const =0
Determines if the given Source must be processed or not.
T begin(T... args)
T emplace_back(T... args)