You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

commandlineflag.h 2.8 kB

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