Android-cuttlefish cvd tool
error.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright 2019, The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef LIBTEEUI_INCLUDE_TEEUI_ERROR_H_
19#define LIBTEEUI_INCLUDE_TEEUI_ERROR_H_
20
21#include "log.h"
22#include <stdint.h>
23
24namespace teeui {
25
26class Error {
27 public:
28 enum error_e : uint32_t {
41 };
42
43 constexpr Error() noexcept : v_(OK) {}
44 constexpr Error(error_e v) noexcept : v_(v) {}
45 constexpr Error(Error&&) noexcept = default;
46 constexpr Error(const Error&) noexcept = default;
47
48 Error& operator=(error_e v) {
49 v_ = v;
50 return *this;
51 }
52 Error& operator=(const Error& other) {
53 v_ = other.v_;
54 return *this;
55 }
56
62 operator bool() const { return v_ != OK; }
63
64 Error operator||(const Error& rhs) const { return *this ? *this : rhs; }
65
66 inline bool operator==(error_e v) const { return v_ == v; };
67 inline bool operator!=(error_e v) const { return v_ != v; };
68
69 constexpr error_e code() const { return v_; }
70
71 private:
73};
74
75#ifdef TEEUI_DO_LOG_DEBUG
76// keep this in the header, so the test can switch it on without switching it on in the static
77// library
78[[maybe_unused]] static std::ostream& operator<<(std::ostream& out, Error e) {
79 switch (e.code()) {
80 case Error::OK:
81 return out << "teeui::Error::OK";
83 return out << "teeui::Error::NotInitialized";
85 return out << "teeui::Error::FaceNotLoaded";
87 return out << "teeui::Error::CharSizeNotSet";
89 return out << "teeui::Error::GlyphNotLoaded";
91 return out << "teeui::Error::GlyphNotRendered";
93 return out << "teeui::Error::GlyphNotExtracted";
95 return out << "teeui::Error::UnsupportedPixelFormat";
97 return out << "teeui::Error::OutOfBoundsDrawing";
99 return out << "teeui::Error::BBoxComputation";
101 return out << "teeui::Error::OutOfMemory";
102 default:
103 return out << "Invalid teeui::Error Code";
104 }
105}
106#endif
107
108} // namespace teeui
109
110#endif // LIBTEEUI_INCLUDE_TEEUI_ERROR_H_
Definition: error.h:26
constexpr Error() noexcept
Definition: error.h:43
bool operator==(error_e v) const
Definition: error.h:66
error_e v_
Definition: error.h:72
Error & operator=(const Error &other)
Definition: error.h:52
constexpr error_e code() const
Definition: error.h:69
Error operator||(const Error &rhs) const
Definition: error.h:64
error_e
Definition: error.h:28
@ GlyphNotRendered
Definition: error.h:34
@ FaceNotLoaded
Definition: error.h:31
@ CharSizeNotSet
Definition: error.h:32
@ NotInitialized
Definition: error.h:30
@ GlyphNotLoaded
Definition: error.h:33
@ BBoxComputation
Definition: error.h:38
@ OK
Definition: error.h:29
@ OutOfBoundsDrawing
Definition: error.h:37
@ OutOfMemory
Definition: error.h:39
@ Localization
Definition: error.h:40
@ UnsupportedPixelFormat
Definition: error.h:36
@ GlyphNotExtracted
Definition: error.h:35
constexpr Error(Error &&) noexcept=default
bool operator!=(error_e v) const
Definition: error.h:67
constexpr Error(error_e v) noexcept
Definition: error.h:44
std::ostream & operator<<(std::ostream &os, const ServiceInfo &service_info)
Definition: mdns_service_info.h:43
Definition: layout.h:28