blob: 54d2c35b7cb40c23f5461852cd2e99f6be02d378 [file] [log] [blame]
Alex Lighteb7c1442015-08-31 13:17:42 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
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 ART_RUNTIME_EXPERIMENTAL_FLAGS_H_
18#define ART_RUNTIME_EXPERIMENTAL_FLAGS_H_
19
20#include <ostream>
21
22namespace art {
23
24// Possible experimental features that might be enabled.
25struct ExperimentalFlags {
26 // The actual flag values.
27 enum {
28 kNone = 0x0000,
Alex Light7233c7e2016-07-28 10:07:45 -070029 kAgents = 0x0001, // 0b00000001
Alex Light185d1342016-08-11 10:48:03 -070030 kRuntimePlugins = 0x0002, // 0b00000010
Alex Lighteb7c1442015-08-31 13:17:42 -070031 };
32
33 constexpr ExperimentalFlags() : value_(0x0000) {}
Chih-Hung Hsieha5931182016-09-01 15:08:13 -070034 constexpr ExperimentalFlags(decltype(kNone) t) // NOLINT, implicit
35 : value_(static_cast<uint32_t>(t)) {}
Alex Lighteb7c1442015-08-31 13:17:42 -070036
37 constexpr operator decltype(kNone)() const {
38 return static_cast<decltype(kNone)>(value_);
39 }
40
41 constexpr explicit operator bool() const {
42 return value_ != kNone;
43 }
44
45 constexpr ExperimentalFlags operator|(const decltype(kNone)& b) const {
46 return static_cast<decltype(kNone)>(value_ | static_cast<uint32_t>(b));
47 }
48 constexpr ExperimentalFlags operator|(const ExperimentalFlags& b) const {
49 return static_cast<decltype(kNone)>(value_ | b.value_);
50 }
51
52 constexpr ExperimentalFlags operator&(const ExperimentalFlags& b) const {
53 return static_cast<decltype(kNone)>(value_ & b.value_);
54 }
55 constexpr ExperimentalFlags operator&(const decltype(kNone)& b) const {
56 return static_cast<decltype(kNone)>(value_ & static_cast<uint32_t>(b));
57 }
58
59 constexpr bool operator==(const ExperimentalFlags& b) const {
60 return value_ == b.value_;
61 }
62
63 private:
64 uint32_t value_;
65};
66
Alex Light7233c7e2016-07-28 10:07:45 -070067inline std::ostream& operator<<(std::ostream& stream, const ExperimentalFlags& e) {
68 bool started = false;
69 if (e & ExperimentalFlags::kAgents) {
70 stream << (started ? "|" : "") << "kAgents";
71 started = true;
72 }
Alex Light185d1342016-08-11 10:48:03 -070073 if (e & ExperimentalFlags::kRuntimePlugins) {
74 stream << (started ? "|" : "") << "kRuntimePlugins";
75 started = true;
76 }
Alex Light7233c7e2016-07-28 10:07:45 -070077 if (!started) {
78 stream << "kNone";
79 }
Alex Lighteb7c1442015-08-31 13:17:42 -070080 return stream;
81}
82
83inline std::ostream& operator<<(std::ostream& stream, const decltype(ExperimentalFlags::kNone)& e) {
84 return stream << ExperimentalFlags(e);
85}
86
87} // namespace art
88
89#endif // ART_RUNTIME_EXPERIMENTAL_FLAGS_H_