forked from muhleder/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.h
81 lines (62 loc) · 1.72 KB
/
status.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_FML_STATUS_H_
#define FLUTTER_FML_STATUS_H_
#include <string_view>
namespace fml {
enum class StatusCode {
kOk,
kCancelled,
kUnknown,
kInvalidArgument,
kDeadlineExceeded,
kNotFound,
kAlreadyExists,
kPermissionDenied,
kResourceExhausted,
kFailedPrecondition,
kAborted,
kOutOfRange,
kUnimplemented,
kInternal,
kUnavailable,
kDataLoss,
kUnauthenticated
};
/// Class that represents the resolution of the execution of a procedure. This
/// is used similarly to how exceptions might be used, typically as the return
/// value to a synchronous procedure or an argument to an asynchronous callback.
class Status final {
public:
/// Creates an 'ok' status.
Status();
Status(fml::StatusCode code, std::string_view message);
fml::StatusCode code() const;
/// A noop that helps with static analysis tools if you decide to ignore an
/// error.
void IgnoreError() const;
/// @return 'true' when the code is kOk.
bool ok() const;
std::string_view message() const;
private:
fml::StatusCode code_;
std::string_view message_;
};
inline Status::Status() : code_(fml::StatusCode::kOk), message_() {}
inline Status::Status(fml::StatusCode code, std::string_view message)
: code_(code), message_(message) {}
inline fml::StatusCode Status::code() const {
return code_;
}
inline void Status::IgnoreError() const {
// noop
}
inline bool Status::ok() const {
return code_ == fml::StatusCode::kOk;
}
inline std::string_view Status::message() const {
return message_;
}
} // namespace fml
#endif // FLUTTER_FML_SIZE_H_