SourceXtractorPlusPlus  0.19
SourceXtractor++, the next generation SExtractor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SourceGrouping.cpp
Go to the documentation of this file.
1 
24 
25 
26 namespace SourceXtractor {
27 
30  unsigned int hard_limit)
31  : m_grouping_criteria(grouping_criteria), m_group_factory(group_factory), m_hard_limit(hard_limit) {
32 }
33 
35  // Pointer which points to the group of the source
36  SourceGroupInterface* matched_group = nullptr;
37 
38  auto source_ptr = source.get();
40 
41  for (auto group_it = m_source_groups.begin(); group_it != m_source_groups.end(); ++group_it) {
42 
43  if (m_hard_limit > 0) {
44  unsigned int current_group_size = (matched_group != nullptr) ? matched_group->size() : 1;
45  if (current_group_size >= m_hard_limit) {
46  break; // no need to try to find matching groups anymore, we have reached the limit
47  }
48 
49  if (current_group_size + (*group_it)->size() > m_hard_limit) {
50  continue; // we can't merge groups without hitting the limit, so skip it
51  }
52  }
53 
54  // Search if the source meets the grouping criteria with any of the sources in the group
55  bool in_group = false;
56  for (auto& s : **group_it) {
57  if (m_grouping_criteria->shouldGroup(*source_ptr, s)) {
58  in_group = true;
59  break; // No need to check the rest of the group sources
60  }
61  }
62 
63  if (in_group) {
64  if (matched_group == nullptr) {
65  matched_group = group_it->get();
66  matched_group->addSource(std::move(source));
67  } else {
68  matched_group->merge(std::move(**group_it));
69  groups_to_remove.emplace_back(group_it);
70  }
71  }
72  }
73 
74  // If there was no group the source should be grouped in, we create a new one
75  if (matched_group == nullptr) {
76  auto new_group = m_group_factory->createSourceGroup();
77  new_group->addSource(std::move(source));
78  m_source_groups.emplace_back(std::move(new_group));
79  }
80 
81  for (auto& group_it : groups_to_remove) {
82  m_source_groups.erase(group_it);
83  }
84 }
85 
88 
89  // We iterate through all the SourceGroups we have
90  for (auto group_it = m_source_groups.begin(); group_it != m_source_groups.end(); ++group_it) {
91  // We look at its Sources and if we find at least one that needs to be processed we put it in groups_to_process
92  for (auto& source : **group_it) {
93  if (process_event.m_selection_criteria->mustBeProcessed(source)) {
94  groups_to_process.push_back(group_it);
95  break;
96  }
97  }
98  }
99 
100  // For each SourceGroup that we put in groups_to_process,
101  for (auto& group : groups_to_process) {
102  // we remove it from our list of stored SourceGroups and notify our observers
103  sendSource(std::move(*group));
104  m_source_groups.erase(group);
105  }
106 }
107 
109  return m_grouping_criteria->requiredProperties();
110 }
111 
112 } // SEFramework namespace
113 
114 
115 
SourceGrouping(std::shared_ptr< GroupingCriteria > grouping_criteria, std::shared_ptr< SourceGroupFactory > group_factory, unsigned int hard_limit)
std::shared_ptr< SourceGroupFactory > m_group_factory
const std::shared_ptr< SelectionCriteria > m_selection_criteria
Definition: PipelineStage.h:35
Event received by SourceGrouping to request the processing of some of the Sources stored...
Definition: PipelineStage.h:33
void receiveSource(std::unique_ptr< SourceInterface > source) override
Handles a new Source.
void receiveProcessSignal(const ProcessSourcesEvent &event) override
Handles a ProcessSourcesEvent to trigger the processing of some of the Sources stored in SourceGroupi...
virtual void merge(SourceGroupInterface &&other)=0
T push_back(T...args)
constexpr double s
std::shared_ptr< GroupingCriteria > m_grouping_criteria
std::set< PropertyId > requiredProperties() const
Returns the set of required properties to compute the grouping.
T move(T...args)
T get(T...args)
Defines the interface used to group sources.
STL class.
STL class.
STL class.
std::list< std::unique_ptr< SourceGroupInterface > > m_source_groups
virtual void addSource(std::unique_ptr< SourceInterface > source)=0
void sendSource(std::unique_ptr< SourceGroupInterface > source) const
Definition: PipelineStage.h:85
virtual unsigned int size() const =0