|
|
|||
File indexing completed on 2025-12-15 09:41:43
0001 // 0002 // Copyright 2020 The Abseil Authors. 0003 // 0004 // Licensed under the Apache License, Version 2.0 (the "License"); 0005 // you may not use this file except in compliance with the License. 0006 // You may obtain a copy of the License at 0007 // 0008 // https://www.apache.org/licenses/LICENSE-2.0 0009 // 0010 // Unless required by applicable law or agreed to in writing, software 0011 // distributed under the License is distributed on an "AS IS" BASIS, 0012 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0013 // See the License for the specific language governing permissions and 0014 // limitations under the License. 0015 // 0016 // ----------------------------------------------------------------------------- 0017 // File: reflection.h 0018 // ----------------------------------------------------------------------------- 0019 // 0020 // This file defines the routines to access and operate on an Abseil Flag's 0021 // reflection handle. 0022 0023 #ifndef ABSL_FLAGS_REFLECTION_H_ 0024 #define ABSL_FLAGS_REFLECTION_H_ 0025 0026 #include <string> 0027 0028 #include "absl/base/config.h" 0029 #include "absl/container/flat_hash_map.h" 0030 #include "absl/flags/commandlineflag.h" 0031 #include "absl/flags/internal/commandlineflag.h" 0032 0033 namespace absl { 0034 ABSL_NAMESPACE_BEGIN 0035 namespace flags_internal { 0036 class FlagSaverImpl; 0037 } // namespace flags_internal 0038 0039 // FindCommandLineFlag() 0040 // 0041 // Returns the reflection handle of an Abseil flag of the specified name, or 0042 // `nullptr` if not found. This function will emit a warning if the name of a 0043 // 'retired' flag is specified. 0044 absl::CommandLineFlag* FindCommandLineFlag(absl::string_view name); 0045 0046 // Returns current state of the Flags registry in a form of mapping from flag 0047 // name to a flag reflection handle. 0048 absl::flat_hash_map<absl::string_view, absl::CommandLineFlag*> GetAllFlags(); 0049 0050 //------------------------------------------------------------------------------ 0051 // FlagSaver 0052 //------------------------------------------------------------------------------ 0053 // 0054 // A FlagSaver object stores the state of flags in the scope where the FlagSaver 0055 // is defined, allowing modification of those flags within that scope and 0056 // automatic restoration of the flags to their previous state upon leaving the 0057 // scope. 0058 // 0059 // A FlagSaver can be used within tests to temporarily change the test 0060 // environment and restore the test case to its previous state. 0061 // 0062 // Example: 0063 // 0064 // void MyFunc() { 0065 // absl::FlagSaver fs; 0066 // ... 0067 // absl::SetFlag(&FLAGS_myFlag, otherValue); 0068 // ... 0069 // } // scope of FlagSaver left, flags return to previous state 0070 // 0071 // This class is thread-safe. 0072 0073 class FlagSaver { 0074 public: 0075 FlagSaver(); 0076 ~FlagSaver(); 0077 0078 FlagSaver(const FlagSaver&) = delete; 0079 void operator=(const FlagSaver&) = delete; 0080 0081 private: 0082 flags_internal::FlagSaverImpl* impl_; 0083 }; 0084 0085 //----------------------------------------------------------------------------- 0086 0087 ABSL_NAMESPACE_END 0088 } // namespace absl 0089 0090 #endif // ABSL_FLAGS_REFLECTION_H_
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|