abseil-cpp/absl/flags/reflection.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 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 // -----------------------------------------------------------------------------
17 // File: reflection.h
18 // -----------------------------------------------------------------------------
19 //
20 // This file defines the routines to access and operate on an Abseil Flag's
21 // reflection handle.
22 
23 #ifndef ABSL_FLAGS_REFLECTION_H_
24 #define ABSL_FLAGS_REFLECTION_H_
25 
26 #include <string>
27 
28 #include "absl/base/config.h"
29 #include "absl/container/flat_hash_map.h"
30 #include "absl/flags/commandlineflag.h"
31 #include "absl/flags/internal/commandlineflag.h"
32 
33 namespace absl {
35 namespace flags_internal {
36 class FlagSaverImpl;
37 } // namespace flags_internal
38 
39 // FindCommandLineFlag()
40 //
41 // Returns the reflection handle of an Abseil flag of the specified name, or
42 // `nullptr` if not found. This function will emit a warning if the name of a
43 // 'retired' flag is specified.
45 
46 // Returns current state of the Flags registry in a form of mapping from flag
47 // name to a flag reflection handle.
49 
50 //------------------------------------------------------------------------------
51 // FlagSaver
52 //------------------------------------------------------------------------------
53 //
54 // A FlagSaver object stores the state of flags in the scope where the FlagSaver
55 // is defined, allowing modification of those flags within that scope and
56 // automatic restoration of the flags to their previous state upon leaving the
57 // scope.
58 //
59 // A FlagSaver can be used within tests to temporarily change the test
60 // environment and restore the test case to its previous state.
61 //
62 // Example:
63 //
64 // void MyFunc() {
65 // absl::FlagSaver fs;
66 // ...
67 // absl::SetFlag(&FLAGS_myFlag, otherValue);
68 // ...
69 // } // scope of FlagSaver left, flags return to previous state
70 //
71 // This class is thread-safe.
72 
73 class FlagSaver {
74  public:
75  FlagSaver();
76  ~FlagSaver();
77 
78  FlagSaver(const FlagSaver&) = delete;
79  void operator=(const FlagSaver&) = delete;
80 
81  private:
83 };
84 
85 //-----------------------------------------------------------------------------
86 
88 } // namespace absl
89 
90 #endif // ABSL_FLAGS_REFLECTION_H_
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
absl::FindCommandLineFlag
CommandLineFlag * FindCommandLineFlag(absl::string_view name)
Definition: abseil-cpp/absl/flags/reflection.cc:336
setup.name
name
Definition: setup.py:542
absl::CommandLineFlag
Definition: abseil-cpp/absl/flags/commandlineflag.h:62
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
absl::FlagSaver::impl_
flags_internal::FlagSaverImpl * impl_
Definition: abseil-cpp/absl/flags/reflection.h:82
absl::FlagSaver::FlagSaver
FlagSaver()
Definition: abseil-cpp/absl/flags/reflection.cc:323
absl::FlagSaver::operator=
void operator=(const FlagSaver &)=delete
absl::FlagSaver
Definition: abseil-cpp/absl/flags/reflection.h:73
absl::flags_internal::FlagSaverImpl
Definition: abseil-cpp/absl/flags/reflection.cc:291
absl::flat_hash_map
Definition: abseil-cpp/absl/container/flat_hash_map.h:113
absl::FlagSaver::~FlagSaver
~FlagSaver()
Definition: abseil-cpp/absl/flags/reflection.cc:327
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
absl::GetAllFlags
absl::flat_hash_map< absl::string_view, absl::CommandLineFlag * > GetAllFlags()
Definition: abseil-cpp/absl/flags/reflection.cc:345


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:00