/src/sentencepiece/third_party/absl/flags/flag.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2016 Google Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License.! |
14 | | |
15 | | #ifndef ABSL_FLAGS_FLAG_H_ |
16 | | #define ABSL_FLAGS_FLAG_H_ |
17 | | |
18 | | #include <functional> |
19 | | #include <memory> |
20 | | #include <string> |
21 | | #include <vector> |
22 | | |
23 | | namespace absl { |
24 | | namespace internal { |
25 | | struct FlagFunc; |
26 | | |
27 | | void RegisterFlag(const std::string &name, std::shared_ptr<FlagFunc> func); |
28 | | |
29 | | } // namespace internal |
30 | | |
31 | | template <typename T> |
32 | | class Flag { |
33 | | public: |
34 | | Flag(const char *name, const char *type, const char *help, |
35 | | const T &defautl_value); |
36 | | virtual ~Flag(); |
37 | | const T &value() const; |
38 | | void set_value(const T &value); |
39 | | void set_value_as_str(const std::string &value_as_str); |
40 | | |
41 | | private: |
42 | | T value_; |
43 | | std::shared_ptr<internal::FlagFunc> func_; |
44 | | }; |
45 | | |
46 | | template <typename T> |
47 | 0 | const T &GetFlag(const Flag<T> &flag) { |
48 | 0 | return flag.value(); |
49 | 0 | } Unexecuted instantiation: int const& absl::GetFlag<int>(absl::Flag<int> const&) Unexecuted instantiation: bool const& absl::GetFlag<bool>(absl::Flag<bool> const&) |
50 | | |
51 | | template <typename T, typename V> |
52 | | void SetFlag(Flag<T> *flag, const V &v) { |
53 | | const T value(v); |
54 | | flag->set_value(value); |
55 | | } |
56 | | |
57 | | #define HAS_ABSL_CLEANUP_FLAGS |
58 | | |
59 | | void CleanupFlags(); |
60 | | |
61 | | } // namespace absl |
62 | | |
63 | | #define ABSL_FLAG(Type, name, defautl_value, help) \ |
64 | | absl::Flag<Type> FLAGS_##name(#name, #Type, help, defautl_value); |
65 | | |
66 | | #define ABSL_DECLARE_FLAG(Type, name) extern absl::Flag<Type> FLAGS_##name; |
67 | | |
68 | | #endif // ABSL_FLAGS_FLAG_H_ |