FastLED 3.9.15
Loading...
Searching...
No Matches
type_conversion_result.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/string.h"
4#include "fl/stl/vector.h"
5#include "fl/stl/stdint.h"
6#include "fl/stl/noexcept.h"
7
8namespace fl {
9
10// =============================================================================
11// TypeConversionResult - Warning/Error tracking for type conversions
12// =============================================================================
13
15public:
17
21
24 result.mWarnings.push_back(msg);
25 return result;
26 }
27
30 result.mHasError = true;
31 result.mErrorMessage = msg;
32 return result;
33 }
34
35 bool ok() const { return !mHasError; }
36 bool hasWarning() const { return !mWarnings.empty(); }
37 bool hasError() const { return mHasError; }
38
39 const fl::vector<fl::string>& warnings() const { return mWarnings; }
40 const fl::string& errorMessage() const { return mErrorMessage; }
41
42 void addWarning(const fl::string& msg) {
43 mWarnings.push_back(msg);
44 }
45
46 void setError(const fl::string& msg) {
47 mHasError = true;
48 mErrorMessage = msg;
49 }
50
51 // Merge another result into this one
52 void merge(const TypeConversionResult& other) {
53 for (fl::size i = 0; i < other.mWarnings.size(); i++) {
54 mWarnings.push_back(other.mWarnings[i]);
55 }
56 if (other.mHasError) {
57 mHasError = true;
59 }
60 }
61
62private:
66};
67
68} // namespace fl
void addWarning(const fl::string &msg)
const fl::string & errorMessage() const
static TypeConversionResult error(const fl::string &msg)
const fl::vector< fl::string > & warnings() const
static TypeConversionResult warning(const fl::string &msg)
void setError(const fl::string &msg)
void merge(const TypeConversionResult &other)
fl::vector< fl::string > mWarnings
static TypeConversionResult success()
fl::size size() const FL_NOEXCEPT
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT