Everett
Loading...
Searching...
No Matches
index_pipeline.h
Go to the documentation of this file.
1
13#pragma once
14
16
18
19#include <cstddef>
20#include <cstdint>
21#include <memory>
22#include <span>
23#include <stdexcept>
24#include <utility>
25#include <vector>
26
27namespace everett {
28 // Builds owning indexes through the same bounded sample queues as file output.
29 // Native stages are ordered nearest the target first, new head last. Finalizing
30 // builds compact navigation and binds each completed pair to its exact target.
31 template <class P>
32 struct index_pipeline : index_detail::pipeline_driver<P, profile_blob<P>, index_builder<P>> {
33 using policy_type = P;
35 using pair_type = std::shared_ptr<blob_type const>;
36
37 index_pipeline(pair_type target, std::vector<pair_type> native_stages)
38 : base(std::move(target), make_stages(native_stages)), results_(this->stages_.size()) {}
39
41 if (this->failed_) error_detail::raise<std::logic_error>("index pipeline has failed");
42 if (!this->done()) error_detail::raise<std::logic_error>("index pipeline still has input");
43 if (!this->finished_) {
44 try {
45 auto target = this->target_;
46 for (std::size_t i = 0; i != this->stages_.size(); ++i) {
47 results_[i] = std::make_shared<blob_type const>(this->stages_[i]->finish(target));
48 target = results_[i];
49 }
50 this->finished_ = true;
51 } catch (...) {
52 this->failed_ = true;
53 throw;
54 }
55 }
56 return results_.empty() ? this->target_ : results_.back();
57 }
58
59 private:
61 std::vector<pair_type> results_;
62
63 static std::vector<std::unique_ptr<index_builder<P>>> make_stages(std::span<pair_type const> sources) {
64 std::vector<std::unique_ptr<index_builder<P>>> result;
65 result.reserve(sources.size());
66 for (auto const & source : sources) {
67 if (!source) error_detail::raise<std::invalid_argument>("null pipeline native source");
68 result.push_back(std::make_unique<index_builder<P>>(*source));
69 }
70 return result;
71 }
72 };
73}
Outlines exceptional check failures while preserving their types and messages.
Shares bounded front-coded sample handoff between index pipelines.
Definition active_engine.h:18
Definition index_builder.h:47
Definition index_pipeline_detail.h:39
std::vector< std::unique_ptr< index_builder< P > > > stages_
Definition index_pipeline_detail.h:93
std::size_t size() const noexcept
Definition index_pipeline_detail.h:62
bool done() const noexcept
Definition index_pipeline_detail.h:57
Definition index_pipeline.h:32
index_pipeline(pair_type target, std::vector< pair_type > native_stages)
Definition index_pipeline.h:37
P policy_type
Definition index_pipeline.h:33
std::shared_ptr< blob_type const > pair_type
Definition index_pipeline.h:35
static std::vector< std::unique_ptr< index_builder< P > > > make_stages(std::span< pair_type const > sources)
Definition index_pipeline.h:63
std::vector< pair_type > results_
Definition index_pipeline.h:61
pair_type finish()
Definition index_pipeline.h:40
Definition profile_blob.h:187