Simo 0.0.1
Loading...
Searching...
No Matches
InitializationStatus.h
1/*
2 * Copyright 2026 Matteo Fusi and Contributors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SIMO_INITIALIZATIONSTATUS_H
18#define SIMO_INITIALIZATIONSTATUS_H
19
20#include <format>
21#include <ostream>
22#include <string>
23#include <string_view>
24#include <vector>
25
26#include "Simo/compiler/Compiler.h"
27
28namespace Simo {
29
30class Module;
31
32class SIMO_PUBLIC InitializationStatus {
33 public:
34 InitializationStatus(Module* module,
35 const std::vector<std::string>& error_list);
36
37 explicit InitializationStatus(Module* module);
38
39 static InitializationStatus ok(Module* module);
40
41 void add_error(std::string_view new_error);
42
43 [[nodiscard]] std::string to_string() const;
44
45 template <typename... Args>
46 InitializationStatus& emplace_sub_error(Args... args) {
47 sub_errors.emplace_back(args...);
48 success_ &= sub_errors.back().success();
49 return sub_errors.back();
50 }
51
52 [[nodiscard]] bool success() const;
53
54 explicit operator bool() const;
55
56 protected:
57 Module* module = nullptr;
58 std::vector<std::string> error_list;
59 std::vector<InitializationStatus> sub_errors;
60 bool success_ = false;
61
62 void append_to(std::string& out, std::size_t indent) const;
63};
64
65inline std::ostream& operator<<(std::ostream& os,
66 const InitializationStatus& status) {
67 return os << status.to_string();
68}
69
70} // namespace Simo
71
72template <>
73struct std::formatter<Simo::InitializationStatus, char>
74 : std::formatter<std::string, char> {
75 auto format(const Simo::InitializationStatus& status,
76 std::format_context& ctx) const {
77 return std::formatter<std::string, char>::format(status.to_string(), ctx);
78 }
79};
80
81#endif // SIMO_INITIALIZATIONSTATUS_H
Definition InitializationStatus.h:32
Definition Module.h:90
General namespace for Simo.
Definition Collection.h:51