cesium-native 0.44.2
Loading...
Searching...
No Matches
ErrorList.h
1#pragma once
2
3#include <CesiumUtility/Library.h>
4#include <CesiumUtility/Log.h> // NOLINT
5#include <CesiumUtility/joinToString.h>
6
7#include <spdlog/spdlog.h>
8
9#include <string>
10#include <vector>
11
12namespace CesiumUtility {
13
18struct CESIUMUTILITY_API ErrorList {
25 static ErrorList error(std::string errorMessage);
26
33 static ErrorList warning(std::string warningMessage);
34
41 void merge(const ErrorList& errorList);
42
49 void merge(ErrorList&& errorList);
50
56 template <typename ErrorStr> void emplaceError(ErrorStr&& error) {
57 errors.emplace_back(std::forward<ErrorStr>(error));
58 }
59
65 template <typename WarningStr> void emplaceWarning(WarningStr&& warning) {
66 warnings.emplace_back(std::forward<WarningStr>(warning));
67 }
68
72 bool hasErrors() const noexcept;
73
80 template <typename PromptStr>
81 void logError(
82 const std::shared_ptr<spdlog::logger>& pLogger,
83 PromptStr&& prompt) const noexcept {
84 if (!errors.empty()) {
85 SPDLOG_LOGGER_ERROR(
86 pLogger,
87 "{}:\n- {}",
88 std::forward<PromptStr>(prompt),
89 CesiumUtility::joinToString(errors, "\n- "));
90 }
91 }
92
99 template <typename PromptStr>
101 const std::shared_ptr<spdlog::logger>& pLogger,
102 PromptStr&& prompt) const noexcept {
103 if (!warnings.empty()) {
104 SPDLOG_LOGGER_WARN(
105 pLogger,
106 "{}:\n- {}",
107 std::forward<PromptStr>(prompt),
108 CesiumUtility::joinToString(warnings, "\n- "));
109 }
110 }
111
115 explicit operator bool() const noexcept;
116
120 std::vector<std::string> errors;
121
125 std::vector<std::string> warnings;
126};
127
128} // namespace CesiumUtility
Utility classes for Cesium.
std::string joinToString(TIterator begin, TIterator end, const std::string &separator)
Joins multiple elements together into a string, separated by a given separator.
STL namespace.
The container to store the error and warning list when loading a tile or glTF content.
Definition ErrorList.h:18
bool hasErrors() const noexcept
Check if there are any error messages.
static ErrorList error(std::string errorMessage)
Creates an ErrorList containing a single error.
void emplaceWarning(WarningStr &&warning)
Add a warning message.
Definition ErrorList.h:65
static ErrorList warning(std::string warningMessage)
Creates an ErrorList containing a single warning.
void logWarning(const std::shared_ptr< spdlog::logger > &pLogger, PromptStr &&prompt) const noexcept
Log all the warning messages.
Definition ErrorList.h:100
void merge(ErrorList &&errorList)
Merge the errors and warnings from other ErrorList together.
void emplaceError(ErrorStr &&error)
Add an error message.
Definition ErrorList.h:56
void merge(const ErrorList &errorList)
Merge the errors and warnings from other ErrorList together.