abseil-cpp/absl/flags/internal/registry.h
Go to the documentation of this file.
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_REGISTRY_H_
17 #define ABSL_FLAGS_INTERNAL_REGISTRY_H_
18 
19 #include <functional>
20 
21 #include "absl/base/config.h"
22 #include "absl/flags/commandlineflag.h"
23 #include "absl/flags/internal/commandlineflag.h"
24 #include "absl/strings/string_view.h"
25 
26 // --------------------------------------------------------------------
27 // Global flags registry API.
28 
29 namespace absl {
31 namespace flags_internal {
32 
33 // Executes specified visitor for each non-retired flag in the registry. While
34 // callback are executed, the registry is locked and can't be changed.
35 void ForEachFlag(std::function<void(CommandLineFlag&)> visitor);
36 
37 //-----------------------------------------------------------------------------
38 
39 bool RegisterCommandLineFlag(CommandLineFlag&, const char* filename);
40 
41 void FinalizeRegistry();
42 
43 //-----------------------------------------------------------------------------
44 // Retired registrations:
45 //
46 // Retired flag registrations are treated specially. A 'retired' flag is
47 // provided only for compatibility with automated invocations that still
48 // name it. A 'retired' flag:
49 // - is not bound to a C++ FLAGS_ reference.
50 // - has a type and a value, but that value is intentionally inaccessible.
51 // - does not appear in --help messages.
52 // - is fully supported by _all_ flag parsing routines.
53 // - consumes args normally, and complains about type mismatches in its
54 // argument.
55 // - emits a complaint but does not die (e.g. LOG(ERROR)) if it is
56 // accessed by name through the flags API for parsing or otherwise.
57 //
58 // The registrations for a flag happen in an unspecified order as the
59 // initializers for the namespace-scope objects of a program are run.
60 // Any number of weak registrations for a flag can weakly define the flag.
61 // One non-weak registration will upgrade the flag from weak to non-weak.
62 // Further weak registrations of a non-weak flag are ignored.
63 //
64 // This mechanism is designed to support moving dead flags into a
65 // 'graveyard' library. An example migration:
66 //
67 // 0: Remove references to this FLAGS_flagname in the C++ codebase.
68 // 1: Register as 'retired' in old_lib.
69 // 2: Make old_lib depend on graveyard.
70 // 3: Add a redundant 'retired' registration to graveyard.
71 // 4: Remove the old_lib 'retired' registration.
72 // 5: Eventually delete the graveyard registration entirely.
73 //
74 
75 // Retire flag with name "name" and type indicated by ops.
76 void Retire(const char* name, FlagFastTypeId type_id, char* buf);
77 
78 constexpr size_t kRetiredFlagObjSize = 3 * sizeof(void*);
79 constexpr size_t kRetiredFlagObjAlignment = alignof(void*);
80 
81 // Registered a retired flag with name 'flag_name' and type 'T'.
82 template <typename T>
83 class RetiredFlag {
84  public:
85  void Retire(const char* flag_name) {
86  flags_internal::Retire(flag_name, base_internal::FastTypeId<T>(), buf_);
87  }
88 
89  private:
91 };
92 
93 } // namespace flags_internal
95 } // namespace absl
96 
97 #endif // ABSL_FLAGS_INTERNAL_REGISTRY_H_
absl::flags_internal::kRetiredFlagObjSize
constexpr size_t kRetiredFlagObjSize
Definition: abseil-cpp/absl/flags/internal/registry.h:78
filename
const char * filename
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:135
absl::flags_internal::RegisterCommandLineFlag
bool RegisterCommandLineFlag(CommandLineFlag &, const char *filename)
Definition: abseil-cpp/absl/flags/reflection.cc:191
absl::flags_internal::FlagFastTypeId
absl::base_internal::FastTypeIdType FlagFastTypeId
Definition: abseil-cpp/absl/flags/internal/commandlineflag.h:31
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
setup.name
name
Definition: setup.py:542
absl::flags_internal::RetiredFlag
Definition: abseil-cpp/absl/flags/internal/registry.h:83
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
absl::flags_internal::FinalizeRegistry
void FinalizeRegistry()
Definition: abseil-cpp/absl/flags/reflection.cc:196
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
absl::flags_internal::ForEachFlag
void ForEachFlag(std::function< void(CommandLineFlag &)> visitor)
Definition: abseil-cpp/absl/flags/reflection.cc:178
absl::flags_internal::RetiredFlag::Retire
void Retire(const char *flag_name)
Definition: abseil-cpp/absl/flags/internal/registry.h:85
absl::flags_internal::RetiredFlag::buf_
char buf_[kRetiredFlagObjSize]
Definition: abseil-cpp/absl/flags/internal/registry.h:90
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
absl::flags_internal::kRetiredFlagObjAlignment
constexpr size_t kRetiredFlagObjAlignment
Definition: abseil-cpp/absl/flags/internal/registry.h:79
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition: grpc_tool.cc:250
absl::flags_internal::Retire
void Retire(const char *name, FlagFastTypeId type_id, char *buf)
Definition: abseil-cpp/absl/flags/reflection.cc:281


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