cesium-native 0.43.0
Loading...
Searching...
No Matches
ErrorList.h
1#pragma once
2
3#include "Library.h"
4#include "joinToString.h"
5
6#include <spdlog/spdlog.h>
7
8#include <string>
9#include <vector>
10
11namespace CesiumUtility {
12
17struct CESIUMUTILITY_API ErrorList {
24 static ErrorList error(std::string errorMessage);
25
32 static ErrorList warning(std::string warningMessage);
33
40 void merge(const ErrorList& errorList);
41
48 void merge(ErrorList&& errorList);
49
55 template <typename ErrorStr> void emplaceError(ErrorStr&& error) {
56 errors.emplace_back(std::forward<ErrorStr>(error));
57 }
58
64 template <typename WarningStr> void emplaceWarning(WarningStr&& warning) {
65 warnings.emplace_back(std::forward<WarningStr>(warning));
66 }
67
71 bool hasErrors() const noexcept;
72
79 template <typename PromptStr>
80 void logError(
81 const std::shared_ptr<spdlog::logger>& pLogger,
82 PromptStr&& prompt) const noexcept {
83 if (!errors.empty()) {
84 SPDLOG_LOGGER_ERROR(
85 pLogger,
86 "{}:\n- {}",
87 std::forward<PromptStr>(prompt),
88 CesiumUtility::joinToString(errors, "\n- "));
89 }
90 }
91
98 template <typename PromptStr>
100 const std::shared_ptr<spdlog::logger>& pLogger,
101 PromptStr&& prompt) const noexcept {
102 if (!warnings.empty()) {
103 SPDLOG_LOGGER_WARN(
104 pLogger,
105 "{}:\n- {}",
106 std::forward<PromptStr>(prompt),
107 CesiumUtility::joinToString(warnings, "\n- "));
108 }
109 }
110
114 explicit operator bool() const noexcept;
115
119 std::vector<std::string> errors;
120
124 std::vector<std::string> warnings;
125};
126
127} // 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:17
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:64
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:99
void merge(ErrorList &&errorList)
Merge the errors and warnings from other ErrorList together.
void emplaceError(ErrorStr &&error)
Add an error message.
Definition ErrorList.h:55
void merge(const ErrorList &errorList)
Merge the errors and warnings from other ErrorList together.