vulp  2.3.0
ObserverPipeline.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: Apache-2.0
2 // Copyright 2022 Stéphane Caron
3 
4 #pragma once
5 
6 #include <memory>
7 #include <vector>
8 
11 
13 namespace vulp::observation {
14 
23  using ObserverPtrVector = std::vector<std::shared_ptr<observation::Observer>>;
24  using SourcePtrVector = std::vector<std::shared_ptr<observation::Source>>;
25  using Dictionary = palimpsest::Dictionary;
26 
27  public:
28  using iterator = ObserverPtrVector::iterator;
29 
34  void reset(const Dictionary& config);
35 
36  /* Add a source at the beginning of the pipeline.
37  *
38  * \param source Source to append.
39  *
40  * \note Contrary to observers, the order in which sources are executed is
41  * not guaranteed. If a source needs to run after another, consider splitting
42  * it into one source and one observer.
43  */
44  void connect_source(std::shared_ptr<Source> source) {
45  sources_.push_back(std::shared_ptr<Source>(source));
46  }
47 
48  /* Append an observer at the end of the pipeline.
49  *
50  * \param observer Observer to append.
51  */
52  void append_observer(std::shared_ptr<Observer> observer) {
53  observers_.push_back(std::shared_ptr<Observer>(observer));
54  }
55 
57  SourcePtrVector& sources() { return sources_; }
58 
60  size_t nb_sources() { return sources_.size(); }
61 
63  ObserverPtrVector& observers() { return observers_; }
64 
66  size_t nb_observers() { return observers_.size(); }
67 
72  void run(Dictionary& observation);
73 
74  private:
76  SourcePtrVector sources_;
77 
79  ObserverPtrVector observers_;
80 };
81 
82 } // namespace vulp::observation
SourcePtrVector & sources()
Sources of the pipeline.
void reset(const Dictionary &config)
Reset observers.
ObserverPtrVector & observers()
Observers of the pipeline. Order matters.
void run(Dictionary &observation)
Run observer pipeline on an observation dictionary.
size_t nb_observers()
Number of observers in the pipeline.
size_t nb_sources()
Number of sources in the pipeline.
void connect_source(std::shared_ptr< Source > source)
void append_observer(std::shared_ptr< Observer > observer)
ObserverPtrVector::iterator iterator
State observation.