Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2019 The Abseil Authors. |
| 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 | // https://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 | #ifndef ABSL_FLAGS_INTERNAL_COMMANDLINEFLAG_H_ |
| 17 | #define ABSL_FLAGS_INTERNAL_COMMANDLINEFLAG_H_ |
| 18 | |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 19 | #include "absl/base/config.h" |
| 20 | #include "absl/base/internal/fast_type_id.h" |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 21 | |
| 22 | namespace absl { |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 23 | ABSL_NAMESPACE_BEGIN |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 24 | namespace flags_internal { |
| 25 | |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 26 | // An alias for flag fast type id. This value identifies the flag value type |
| 27 | // similarly to typeid(T), without relying on RTTI being available. In most |
| 28 | // cases this id is enough to uniquely identify the flag's value type. In a few |
| 29 | // cases we'll have to resort to using actual RTTI implementation if it is |
| 30 | // available. |
| 31 | using FlagFastTypeId = absl::base_internal::FastTypeIdType; |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 32 | |
| 33 | // Options that control SetCommandLineOptionWithMode. |
| 34 | enum FlagSettingMode { |
| 35 | // update the flag's value unconditionally (can call this multiple times). |
| 36 | SET_FLAGS_VALUE, |
| 37 | // update the flag's value, but *only if* it has not yet been updated |
| 38 | // with SET_FLAGS_VALUE, SET_FLAG_IF_DEFAULT, or "FLAGS_xxx = nondef". |
| 39 | SET_FLAG_IF_DEFAULT, |
| 40 | // set the flag's default value to this. If the flag has not been updated |
| 41 | // yet (via SET_FLAGS_VALUE, SET_FLAG_IF_DEFAULT, or "FLAGS_xxx = nondef") |
| 42 | // change the flag's current value to the new default value as well. |
| 43 | SET_FLAGS_DEFAULT |
| 44 | }; |
| 45 | |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 46 | // Options that control ParseFrom: Source of a value. |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 47 | enum ValueSource { |
| 48 | // Flag is being set by value specified on a command line. |
| 49 | kCommandLine, |
| 50 | // Flag is being set by value specified in the code. |
| 51 | kProgrammaticChange, |
| 52 | }; |
| 53 | |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 54 | // Handle to FlagState objects. Specific flag state objects will restore state |
| 55 | // of a flag produced this flag state from method CommandLineFlag::SaveState(). |
| 56 | class FlagStateInterface { |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 57 | public: |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 58 | virtual ~FlagStateInterface(); |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 59 | |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 60 | // Restores the flag originated this object to the saved state. |
| 61 | virtual void Restore() const = 0; |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 64 | } // namespace flags_internal |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 65 | ABSL_NAMESPACE_END |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 66 | } // namespace absl |
| 67 | |
| 68 | #endif // ABSL_FLAGS_INTERNAL_COMMANDLINEFLAG_H_ |