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