Go to the documentation of this file.
16 #include "absl/flags/reflection.h"
23 #include "absl/base/config.h"
24 #include "absl/base/thread_annotations.h"
25 #include "absl/container/flat_hash_map.h"
26 #include "absl/flags/commandlineflag.h"
27 #include "absl/flags/internal/private_handle_accessor.h"
28 #include "absl/flags/internal/registry.h"
29 #include "absl/flags/usage_config.h"
30 #include "absl/strings/str_cat.h"
31 #include "absl/strings/string_view.h"
32 #include "absl/synchronization/mutex.h"
36 namespace flags_internal {
87 class FlagRegistryLock {
90 ~FlagRegistryLock() {
fr_.Unlock(); }
102 auto it = std::partition_point(
108 FlagRegistryLock frl(*
this);
110 return it !=
flags_.end() ?
it->second :
nullptr;
118 "Inconsistency between flag object and registration for flag '",
120 "', likely due to duplicate flags or an ODR violation. Relevant "
127 FlagRegistryLock registry_lock(*
this);
129 std::pair<FlagIterator, bool> ins =
131 if (ins.second ==
false) {
137 "Retired flag '",
flag.Name(),
"' was defined normally in file '",
144 "' was defined more than once but with "
145 "differing types. Defined in files '",
153 "' was defined more than once (in files '",
154 old_flag.
Filename(),
"' and '",
flag.Filename(),
"')."),
159 "Something is wrong with flag '",
flag.Name(),
"' in file '",
160 flag.Filename(),
"'. One possibility: file '",
flag.Filename(),
161 "' is being linked both statically and dynamically into this "
162 "executable. e.g. some files listed as srcs to a test and also "
163 "listed as srcs of some shared lib deps of the same test."),
173 return *global_registry;
185 FlagRegistryLock frl(registry);
186 for (
const auto&
i : registry.
flags_) visitor(*
i.second);
198 FlagRegistryLock frl(registry);
199 if (registry.finalized_flags_.load(std::memory_order_relaxed)) {
203 registry.flat_flags_.reserve(registry.flags_.size());
204 for (
const auto& f : registry.flags_) {
205 registry.flat_flags_.push_back(f.second);
209 return lhs->Name() < rhs->Name();
211 registry.flags_.clear();
212 registry.finalized_flags_.store(
true, std::memory_order_release);
235 bool IsRetired()
const override {
return true; }
236 bool IsSpecifiedOnCommandLine()
const override {
255 std::unique_ptr<flags_internal::FlagStateInterface> SaveState()
override {
265 void CheckDefaultValueParsingRoundtrip()
const override { OnAccess(); }
267 void Read(
void*)
const override { OnAccess(); }
269 void OnAccess()
const {
285 flags_internal::RetiredFlagObj(
name, type_id);
302 if (
auto flag_state =
312 flag_state->Restore();
317 std::vector<std::unique_ptr<flags_internal::FlagStateInterface>>
337 if (
name.empty())
return nullptr;
348 if (!
flag.IsRetired()) res.insert({flag.Name(), &flag});
constexpr size_t kRetiredFlagObjSize
void RegisterFlag(CommandLineFlag &flag, const char *filename)
bool RegisterCommandLineFlag(CommandLineFlag &, const char *filename)
FlagRegistry & operator=(const FlagRegistry &)
static std::string Filename(const protobuf::FileDescriptor *file)
static std::unique_ptr< FlagStateInterface > SaveState(CommandLineFlag &flag)
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
void operator=(const FlagSaverImpl &)=delete
absl::base_internal::FastTypeIdType FlagFastTypeId
virtual bool IsRetired() const
FlagMap::iterator FlagIterator
CommandLineFlag * FindFlag(absl::string_view name)
static FlagRegistry & GlobalRegistry()
const typedef void * TypeId
void Unlock() ABSL_UNLOCK_FUNCTION()
std::vector< CommandLineFlag * > flat_flags_
CommandLineFlag * FindCommandLineFlag(absl::string_view name)
#define ABSL_NAMESPACE_END
const typedef MCPhysReg * iterator
std::atomic< bool > finalized_flags_
std::vector< std::unique_ptr< flags_internal::FlagStateInterface > > backup_registry_
#define ABSL_NAMESPACE_BEGIN
friend void FinalizeRegistry()
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
int Read(int fd, void *buf, unsigned int count)
std::shared_ptr< ExternalConnectionAcceptorImpl > impl_
void ReportUsageError(absl::string_view msg, bool is_fatal)
void Lock() ABSL_EXCLUSIVE_LOCK_FUNCTION()
friend void ForEachFlag(std::function< void(CommandLineFlag &)> visitor)
flags_internal::FlagSaverImpl * impl_
void ForEachFlag(std::function< void(CommandLineFlag &)> visitor)
std::string DefaultValue(const FieldDescriptor *field)
static FlagFastTypeId TypeId(const CommandLineFlag &flag)
void Lock() ABSL_EXCLUSIVE_LOCK_FUNCTION(lock_)
virtual std::string Filename() const =0
#define ABSL_EXCLUSIVE_LOCK_FUNCTION(...)
FlagsUsageConfig GetUsageConfig()
FlagMap::const_iterator FlagConstIterator
constexpr size_t kRetiredFlagObjAlignment
const FlagFastTypeId type_id_
void Retire(const char *name, FlagFastTypeId type_id, char *buf)
#define ABSL_UNLOCK_FUNCTION(...)
absl::flat_hash_map< absl::string_view, absl::CommandLineFlag * > GetAllFlags()
void Unlock() ABSL_UNLOCK_FUNCTION(lock_)
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:00