Flow 1.0.1
Flow project: Full implementation reference.
cfg_manager_fwd.hpp
Go to the documentation of this file.
1/* Flow
2 * Copyright 2023 Akamai Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the
5 * "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in
12 * writing, software distributed under the License is
13 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 * CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing
16 * permissions and limitations under the License. */
17
18/// @file
19#pragma once
20
21namespace flow::cfg
22{
23// Types.
24
25// Find doc headers near the bodies of these compound types.
26
27template<typename... S_d_value_set>
28class Config_manager;
29
30template<typename Value_set>
31struct Final_validator_func;
32
33struct Null_value_set;
34
35template<typename Value_set>
36class Static_config_manager;
37
38/**
39 * Result enumeration for a Final_validator_func::Type function which is used by a Config_manager user
40 * when parsing a config source (ex: file). In short such a function can consider the file as one to skip
41 * entirely, as okay to accept, or as erroneous.
42 */
44{
45 /**
46 * The holistically-checked cumulative `Value_set` has no problems and shall be accepted into the candidate
47 * `Value_set`; if this is the final config-source (ex: file), that candidate shall be canonicalized.
48 * `apply_*()` shall return `true` (success).
49 */
51
52 /**
53 * The holistically-checked cumulative `Value_set` has contents such that the validator function decided
54 * that the *current* `apply_*()` shall have no effect, meaning the `Value_set` candidate shall remain
55 * unchanged from just-before that *current* `apply_*()`; if this is the final config-source (ex: file),
56 * that unchanged candidate shall be canonicalized. `apply_*()` shall return `true` (success).
57 *
58 * `S_SKIP` shall also have this effect on all subsequently scanned `Value_set`s in the same
59 * `apply_static()`, `apply_dynamic()`, or `apply_static_and_dynamic()` call; that is to say
60 * one SKIPped `Value_set` causes all subsequent ones to behave as-if they too were SKIPped.
61 */
62 S_SKIP,
63
64 /**
65 * The holistically-checked cumulative `Value_set` has invalid contents; the candidate shall be rejected,
66 * and `apply_*()` shall return `false` (failure).
67 */
68 S_FAIL
69}; // enum class Final_validator_outcome
70
71// Free functions.
72
73/**
74 * Serializes (briefly) a Config_manager to a standard output stream.
75 *
76 * @relatesalso Config_manager
77 *
78 * @tparam S_d_value_set
79 * See Config_manager doc header.
80 * @param os
81 * Stream to which to serialize.
82 * @param val
83 * Value to serialize.
84 * @return `os`.
85 */
86template<typename... S_d_value_set>
87std::ostream& operator<<(std::ostream& os, const Config_manager<S_d_value_set...>& val);
88
89} // namespace flow::cfg
90
91// Macros.
92
93/**
94 * Convenience macro particularly useful in the `final_validator_func()` callback taken by various
95 * Config_manager APIs; checks the given condition; if `false` logs a FLOW_LOG_WARNING() containing the failed
96 * condition and executes `outcome = flow::cfg::Final_validator_func::S_FAIL;`; otherwise no-op. Note the context
97 * must be such that FLOW_LOG_WARNING() compiles and acts properly.
98 *
99 * If `auto outcome = flow::cfg::Final_validator_func::S_ACCEPT;` precedes multiple invocations of this macro, then
100 * by the end of those invocations `outcome == S_ACCEPT` if and only if all checks passed. All errors will be printed
101 * if `outcome != S_ACCEPT`.
102 *
103 * Informally: If you have a condition that would cause your `final_validator_func()` to return
104 * flow::cfg::Final_validator_outcome::S_SKIP, then it is probably best to check for this potential condition,
105 * and `return flow::cfg::Final_validator_outcome::S_SKIP` if it holds, before any further checks
106 * (FLOW_CFG_OPT_CHECK_ASSERT() calls).
107 *
108 * @param ARG_must_be_true
109 * An expression convertible to `bool` that should evaluate to `true` to avoid WARNING and `outcome = S_FAIL;`.
110 */
111#define FLOW_CFG_OPT_CHECK_ASSERT(ARG_must_be_true) \
112 FLOW_UTIL_SEMICOLON_SAFE \
113 ( \
114 if (!(ARG_must_be_true)) \
115 { \
116 FLOW_LOG_WARNING("Validation failed; the following condition must hold: [" #ARG_must_be_true "]."); \
117 outcome = ::flow::cfg::Final_validator_outcome::S_FAIL; \
118 } \
119 )
Flow module that facilitates configuring modules, such as applications and APIs, via statically and/o...
Definition: cfg_fwd.hpp:112
Final_validator_outcome
Result enumeration for a Final_validator_func::Type function which is used by a Config_manager user w...
@ S_ACCEPT
The holistically-checked cumulative Value_set has no problems and shall be accepted into the candidat...
@ S_SKIP
The holistically-checked cumulative Value_set has contents such that the validator function decided t...
@ S_FAIL
The holistically-checked cumulative Value_set has invalid contents; the candidate shall be rejected,...
std::ostream & operator<<(std::ostream &os, const Option_set< Value_set > &val)
Serializes (briefly) an Option_set to a standard output stream.