/src/wabt/include/wabt/result.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2017 WebAssembly Community Group participants |
3 | | * |
4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | * you may not use this file except in compliance with the License. |
6 | | * You may obtain a copy of the License at |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | |
17 | | #ifndef WABT_RESULT_H_ |
18 | | #define WABT_RESULT_H_ |
19 | | |
20 | | namespace wabt { |
21 | | |
22 | | struct Result { |
23 | | enum Enum { |
24 | | Ok, |
25 | | Error, |
26 | | }; |
27 | | |
28 | 0 | Result() : Result(Ok) {} |
29 | 89.1M | Result(Enum e) : enum_(e) {} |
30 | 90.7M | operator Enum() const { return enum_; } |
31 | | Result& operator|=(Result rhs); |
32 | | |
33 | | private: |
34 | | Enum enum_; |
35 | | }; |
36 | | |
37 | 807k | inline Result operator|(Result lhs, Result rhs) { |
38 | 807k | return (lhs == Result::Error || rhs == Result::Error) ? Result::Error |
39 | 807k | : Result::Ok; |
40 | 807k | } |
41 | | |
42 | 807k | inline Result& Result::operator|=(Result rhs) { |
43 | 807k | enum_ = *this | rhs; |
44 | 807k | return *this; |
45 | 807k | } |
46 | | |
47 | 32.6M | inline bool Succeeded(Result result) { |
48 | 32.6M | return result == Result::Ok; |
49 | 32.6M | } |
50 | 55.6M | inline bool Failed(Result result) { |
51 | 55.6M | return result == Result::Error; |
52 | 55.6M | } |
53 | | |
54 | | #define CHECK_RESULT(expr) \ |
55 | 54.8M | do { \ |
56 | 54.8M | if (Failed(expr)) { \ |
57 | 33.3k | return ::wabt::Result::Error; \ |
58 | 33.3k | } \ |
59 | 54.8M | } while (0) |
60 | | |
61 | | } // namespace wabt |
62 | | |
63 | | #endif // WABT_RESULT_H_ |