summaryrefslogtreecommitdiff
path: root/absl/flags/internal
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2020-05-26 10:57:33 -0700
committerGravatar Derek Mauro <dmauro@google.com>2020-05-26 14:45:38 -0400
commit33caf1097ecce4fe892567462fa8821d477854b4 (patch)
tree27eecef4f8c5638857b134ea117c3bd20a980b96 /absl/flags/internal
parentcf1a02e2dc5a1bc9d095f4c996306de448ca200f (diff)
Export of internal Abseil changes
-- 7d0468a6610ed85586d5c87fd65de8dac5118923 by Derek Mauro <dmauro@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 313226473 -- 1131ef6d116f5ce7d46537a82f300ea06dcaaa53 by Gennadiy Rozental <rogeeff@google.com>: Migrate internal interface to use mutable references. PiperOrigin-RevId: 312931131 -- 96225212a9f5fbd0b38c71fe65539164992c7c3b by Laramie Leavitt <lar@google.com>: Remove random/internal/distributions.h This file was something of an historical artifact. All of the related code has either been removed or migraged, and so the only remaining type belongs with uniform_helper.h, as it is used to infer the return type of the absl::Uniform method in a few cases. PiperOrigin-RevId: 312878173 -- 6dcbd5be58ad425e08740ff64088373ee7fe4a72 by Mark Barolak <mbar@google.com>: Release the StrFormat test case for Cords to open source. PiperOrigin-RevId: 312707974 -- 34484d18dfb63a0a7ad6e2aaeb570e33592968be by Abseil Team <absl-team@google.com>: Let Cord::Cord(string&&), Cord::operator=(string&&), Cord::Append(string&&), and Cord::Prepend(string&&) steal string data and embed it into the Cord as a single external chunk, instead of copying it into flat chunks (at most 4083-byte each). Stealing string data is faster, but it creates a long chunk, which leads to a higher more memory usage if its subcords are created and outlive the whole Cord. These functions revert to copying the data if any of the following conditions holds: - string size is at most kMaxBytesToCopy (511), to avoid the overhead of an external chunk for short strings; - less than half of string capacity is used, to avoid pinning to much unused memory. PiperOrigin-RevId: 312683785 GitOrigin-RevId: 7d0468a6610ed85586d5c87fd65de8dac5118923 Change-Id: If79b5a1dfe6d53a8ddddbc7da84338f11fc4cfa3
Diffstat (limited to 'absl/flags/internal')
-rw-r--r--absl/flags/internal/flag.cc38
-rw-r--r--absl/flags/internal/flag.h24
-rw-r--r--absl/flags/internal/private_handle_accessor.cc10
-rw-r--r--absl/flags/internal/private_handle_accessor.h6
-rw-r--r--absl/flags/internal/registry.cc95
-rw-r--r--absl/flags/internal/registry.h6
-rw-r--r--absl/flags/internal/type_erased.cc2
-rw-r--r--absl/flags/internal/usage.cc25
8 files changed, 101 insertions, 105 deletions
diff --git a/absl/flags/internal/flag.cc b/absl/flags/internal/flag.cc
index 35ae55fb..ee974244 100644
--- a/absl/flags/internal/flag.cc
+++ b/absl/flags/internal/flag.cc
@@ -62,14 +62,14 @@ bool ShouldValidateFlagValue(FlagFastTypeId flag_type_id) {
// need to acquire these locks themselves.
class MutexRelock {
public:
- explicit MutexRelock(absl::Mutex* mu) : mu_(mu) { mu_->Unlock(); }
- ~MutexRelock() { mu_->Lock(); }
+ explicit MutexRelock(absl::Mutex& mu) : mu_(mu) { mu_.Unlock(); }
+ ~MutexRelock() { mu_.Lock(); }
MutexRelock(const MutexRelock&) = delete;
MutexRelock& operator=(const MutexRelock&) = delete;
private:
- absl::Mutex* mu_;
+ absl::Mutex& mu_;
};
} // namespace
@@ -82,7 +82,7 @@ class FlagImpl;
class FlagState : public flags_internal::FlagStateInterface {
public:
template <typename V>
- FlagState(FlagImpl* flag_impl, const V& v, bool modified,
+ FlagState(FlagImpl& flag_impl, const V& v, bool modified,
bool on_command_line, int64_t counter)
: flag_impl_(flag_impl),
value_(v),
@@ -91,9 +91,9 @@ class FlagState : public flags_internal::FlagStateInterface {
counter_(counter) {}
~FlagState() override {
- if (flag_impl_->ValueStorageKind() != FlagValueStorageKind::kAlignedBuffer)
+ if (flag_impl_.ValueStorageKind() != FlagValueStorageKind::kAlignedBuffer)
return;
- flags_internal::Delete(flag_impl_->op_, value_.heap_allocated);
+ flags_internal::Delete(flag_impl_.op_, value_.heap_allocated);
}
private:
@@ -101,15 +101,15 @@ class FlagState : public flags_internal::FlagStateInterface {
// Restores the flag to the saved state.
void Restore() const override {
- if (!flag_impl_->RestoreState(*this)) return;
+ if (!flag_impl_.RestoreState(*this)) return;
- ABSL_INTERNAL_LOG(
- INFO, absl::StrCat("Restore saved value of ", flag_impl_->Name(),
- " to: ", flag_impl_->CurrentValue()));
+ ABSL_INTERNAL_LOG(INFO,
+ absl::StrCat("Restore saved value of ", flag_impl_.Name(),
+ " to: ", flag_impl_.CurrentValue()));
}
// Flag and saved flag data.
- FlagImpl* flag_impl_;
+ FlagImpl& flag_impl_;
union SavedValue {
explicit SavedValue(void* v) : heap_allocated(v) {}
explicit SavedValue(int64_t v) : one_word(v) {}
@@ -326,7 +326,7 @@ void FlagImpl::InvokeCallback() const {
// and it also can be different by the time the callback invocation is
// completed. Requires that *primary_lock be held in exclusive mode; it may be
// released and reacquired by the implementation.
- MutexRelock relock(DataGuard());
+ MutexRelock relock(*DataGuard());
absl::MutexLock lock(&callback_->guard);
cb();
}
@@ -339,17 +339,17 @@ std::unique_ptr<FlagStateInterface> FlagImpl::SaveState() {
switch (ValueStorageKind()) {
case FlagValueStorageKind::kAlignedBuffer: {
return absl::make_unique<FlagState>(
- this, flags_internal::Clone(op_, AlignedBufferValue()), modified,
+ *this, flags_internal::Clone(op_, AlignedBufferValue()), modified,
on_command_line, counter_);
}
case FlagValueStorageKind::kOneWordAtomic: {
return absl::make_unique<FlagState>(
- this, OneWordValue().load(std::memory_order_acquire), modified,
+ *this, OneWordValue().load(std::memory_order_acquire), modified,
on_command_line, counter_);
}
case FlagValueStorageKind::kTwoWordsAtomic: {
return absl::make_unique<FlagState>(
- this, TwoWordsValue().load(std::memory_order_acquire), modified,
+ *this, TwoWordsValue().load(std::memory_order_acquire), modified,
on_command_line, counter_);
}
}
@@ -410,14 +410,14 @@ std::atomic<AlignedTwoWords>& FlagImpl::TwoWordsValue() const {
// parsed value. In case if any error is encountered in either step, the error
// message is stored in 'err'
std::unique_ptr<void, DynValueDeleter> FlagImpl::TryParse(
- absl::string_view value, std::string* err) const {
+ absl::string_view value, std::string& err) const {
std::unique_ptr<void, DynValueDeleter> tentative_value = MakeInitValue();
std::string parse_err;
if (!flags_internal::Parse(op_, value, tentative_value.get(), &parse_err)) {
absl::string_view err_sep = parse_err.empty() ? "" : "; ";
- *err = absl::StrCat("Illegal value '", value, "' specified for flag '",
- Name(), "'", err_sep, parse_err);
+ err = absl::StrCat("Illegal value '", value, "' specified for flag '",
+ Name(), "'", err_sep, parse_err);
return nullptr;
}
@@ -473,7 +473,7 @@ void FlagImpl::Write(const void* src) {
// * Update the current flag value if it was never set before
// The mode is selected based on 'set_mode' parameter.
bool FlagImpl::ParseFrom(absl::string_view value, FlagSettingMode set_mode,
- ValueSource source, std::string* err) {
+ ValueSource source, std::string& err) {
absl::MutexLock l(DataGuard());
switch (set_mode) {
diff --git a/absl/flags/internal/flag.h b/absl/flags/internal/flag.h
index 97ddb5f9..e1885809 100644
--- a/absl/flags/internal/flag.h
+++ b/absl/flags/internal/flag.h
@@ -374,31 +374,31 @@ struct FlagValue;
template <typename T>
struct FlagValue<T, FlagValueStorageKind::kAlignedBuffer> {
- bool Get(T*) const { return false; }
+ bool Get(T&) const { return false; }
alignas(T) char value[sizeof(T)];
};
template <typename T>
struct FlagValue<T, FlagValueStorageKind::kOneWordAtomic> : FlagOneWordValue {
- bool Get(T* dst) const {
+ bool Get(T& dst) const {
int64_t one_word_val = value.load(std::memory_order_acquire);
if (ABSL_PREDICT_FALSE(one_word_val == UninitializedFlagValue())) {
return false;
}
- std::memcpy(dst, static_cast<const void*>(&one_word_val), sizeof(T));
+ std::memcpy(&dst, static_cast<const void*>(&one_word_val), sizeof(T));
return true;
}
};
template <typename T>
struct FlagValue<T, FlagValueStorageKind::kTwoWordsAtomic> : FlagTwoWordsValue {
- bool Get(T* dst) const {
+ bool Get(T& dst) const {
AlignedTwoWords two_words_val = value.load(std::memory_order_acquire);
if (ABSL_PREDICT_FALSE(!two_words_val.IsInitialized())) {
return false;
}
- std::memcpy(dst, static_cast<const void*>(&two_words_val), sizeof(T));
+ std::memcpy(&dst, static_cast<const void*>(&two_words_val), sizeof(T));
return true;
}
};
@@ -502,7 +502,7 @@ class FlagImpl final : public CommandLineFlag {
// Attempts to parse supplied `value` string. If parsing is successful,
// returns new value. Otherwise returns nullptr.
std::unique_ptr<void, DynValueDeleter> TryParse(absl::string_view value,
- std::string* err) const
+ std::string& err) const
ABSL_EXCLUSIVE_LOCKS_REQUIRED(*DataGuard());
// Stores the flag value based on the pointer to the source.
void StoreValue(const void* src) ABSL_EXCLUSIVE_LOCKS_REQUIRED(*DataGuard());
@@ -544,7 +544,7 @@ class FlagImpl final : public CommandLineFlag {
ABSL_LOCKS_EXCLUDED(*DataGuard());
bool ParseFrom(absl::string_view value, FlagSettingMode set_mode,
- ValueSource source, std::string* error) override
+ ValueSource source, std::string& error) override
ABSL_LOCKS_EXCLUDED(*DataGuard());
// Immutable flag's state.
@@ -651,7 +651,7 @@ class Flag {
impl_.AssertValidType(base_internal::FastTypeId<T>(), &GenRuntimeTypeId<T>);
#endif
- if (!value_.Get(&u.value)) impl_.Read(&u.value);
+ if (!value_.Get(u.value)) impl_.Read(&u.value);
return std::move(u.value);
}
void Set(const T& v) {
@@ -730,12 +730,12 @@ struct FlagRegistrarEmpty {};
template <typename T, bool do_register>
class FlagRegistrar {
public:
- explicit FlagRegistrar(Flag<T>* flag) : flag_(flag) {
- if (do_register) flags_internal::RegisterCommandLineFlag(&flag_->impl_);
+ explicit FlagRegistrar(Flag<T>& flag) : flag_(flag) {
+ if (do_register) flags_internal::RegisterCommandLineFlag(flag_.impl_);
}
FlagRegistrar OnUpdate(FlagCallbackFunc cb) && {
- flag_->impl_.SetCallback(cb);
+ flag_.impl_.SetCallback(cb);
return *this;
}
@@ -745,7 +745,7 @@ class FlagRegistrar {
operator FlagRegistrarEmpty() const { return {}; } // NOLINT
private:
- Flag<T>* flag_; // Flag being registered (not owned).
+ Flag<T>& flag_; // Flag being registered (not owned).
};
} // namespace flags_internal
diff --git a/absl/flags/internal/private_handle_accessor.cc b/absl/flags/internal/private_handle_accessor.cc
index 64fe3166..24b49136 100644
--- a/absl/flags/internal/private_handle_accessor.cc
+++ b/absl/flags/internal/private_handle_accessor.cc
@@ -24,8 +24,8 @@ FlagFastTypeId PrivateHandleAccessor::TypeId(const CommandLineFlag& flag) {
}
std::unique_ptr<FlagStateInterface> PrivateHandleAccessor::SaveState(
- CommandLineFlag* flag) {
- return flag->SaveState();
+ CommandLineFlag& flag) {
+ return flag.SaveState();
}
bool PrivateHandleAccessor::IsSpecifiedOnCommandLine(
@@ -43,12 +43,12 @@ void PrivateHandleAccessor::CheckDefaultValueParsingRoundtrip(
flag.CheckDefaultValueParsingRoundtrip();
}
-bool PrivateHandleAccessor::ParseFrom(CommandLineFlag* flag,
+bool PrivateHandleAccessor::ParseFrom(CommandLineFlag& flag,
absl::string_view value,
flags_internal::FlagSettingMode set_mode,
flags_internal::ValueSource source,
- std::string* error) {
- return flag->ParseFrom(value, set_mode, source, error);
+ std::string& error) {
+ return flag.ParseFrom(value, set_mode, source, error);
}
} // namespace flags_internal
diff --git a/absl/flags/internal/private_handle_accessor.h b/absl/flags/internal/private_handle_accessor.h
index 07838600..9a327a07 100644
--- a/absl/flags/internal/private_handle_accessor.h
+++ b/absl/flags/internal/private_handle_accessor.h
@@ -31,7 +31,7 @@ class PrivateHandleAccessor {
static FlagFastTypeId TypeId(const CommandLineFlag& flag);
// Access to CommandLineFlag::SaveState.
- static std::unique_ptr<FlagStateInterface> SaveState(CommandLineFlag* flag);
+ static std::unique_ptr<FlagStateInterface> SaveState(CommandLineFlag& flag);
// Access to CommandLineFlag::IsSpecifiedOnCommandLine.
static bool IsSpecifiedOnCommandLine(const CommandLineFlag& flag);
@@ -43,9 +43,9 @@ class PrivateHandleAccessor {
// Access to CommandLineFlag::CheckDefaultValueParsingRoundtrip.
static void CheckDefaultValueParsingRoundtrip(const CommandLineFlag& flag);
- static bool ParseFrom(CommandLineFlag* flag, absl::string_view value,
+ static bool ParseFrom(CommandLineFlag& flag, absl::string_view value,
flags_internal::FlagSettingMode set_mode,
- flags_internal::ValueSource source, std::string* error);
+ flags_internal::ValueSource source, std::string& error);
};
} // namespace flags_internal
diff --git a/absl/flags/internal/registry.cc b/absl/flags/internal/registry.cc
index 70d76557..4bcebfa9 100644
--- a/absl/flags/internal/registry.cc
+++ b/absl/flags/internal/registry.cc
@@ -60,8 +60,8 @@ class FlagRegistry {
FlagRegistry() = default;
~FlagRegistry() = default;
- // Store a flag in this registry. Takes ownership of *flag.
- void RegisterFlag(CommandLineFlag* flag);
+ // Store a flag in this registry. Takes ownership of *flag.
+ void RegisterFlag(CommandLineFlag& flag);
void Lock() ABSL_EXCLUSIVE_LOCK_FUNCTION(lock_) { lock_.Lock(); }
void Unlock() ABSL_UNLOCK_FUNCTION(lock_) { lock_.Unlock(); }
@@ -74,12 +74,12 @@ class FlagRegistry {
// found or not retired. Does not emit a warning.
CommandLineFlag* FindRetiredFlagLocked(absl::string_view name);
- static FlagRegistry* GlobalRegistry(); // returns a singleton registry
+ static FlagRegistry& GlobalRegistry(); // returns a singleton registry
private:
friend class FlagSaverImpl; // reads all the flags in order to copy them
friend void ForEachFlagUnlocked(
- std::function<void(CommandLineFlag*)> visitor);
+ std::function<void(CommandLineFlag&)> visitor);
// The map from name to flag, for FindFlagLocked().
using FlagMap = std::map<absl::string_view, CommandLineFlag*>;
@@ -94,65 +94,62 @@ class FlagRegistry {
FlagRegistry& operator=(const FlagRegistry&);
};
-FlagRegistry* FlagRegistry::GlobalRegistry() {
+FlagRegistry& FlagRegistry::GlobalRegistry() {
static FlagRegistry* global_registry = new FlagRegistry;
- return global_registry;
+ return *global_registry;
}
namespace {
class FlagRegistryLock {
public:
- explicit FlagRegistryLock(FlagRegistry* fr) : fr_(fr) { fr_->Lock(); }
- ~FlagRegistryLock() { fr_->Unlock(); }
+ explicit FlagRegistryLock(FlagRegistry& fr) : fr_(fr) { fr_.Lock(); }
+ ~FlagRegistryLock() { fr_.Unlock(); }
private:
- FlagRegistry* const fr_;
+ FlagRegistry& fr_;
};
-void DestroyRetiredFlag(CommandLineFlag* flag);
+void DestroyRetiredFlag(CommandLineFlag& flag);
} // namespace
-void FlagRegistry::RegisterFlag(CommandLineFlag* flag) {
- FlagRegistryLock registry_lock(this);
+void FlagRegistry::RegisterFlag(CommandLineFlag& flag) {
+ FlagRegistryLock registry_lock(*this);
std::pair<FlagIterator, bool> ins =
- flags_.insert(FlagMap::value_type(flag->Name(), flag));
+ flags_.insert(FlagMap::value_type(flag.Name(), &flag));
if (ins.second == false) { // means the name was already in the map
- CommandLineFlag* old_flag = ins.first->second;
- if (flag->IsRetired() != old_flag->IsRetired()) {
+ CommandLineFlag& old_flag = *ins.first->second;
+ if (flag.IsRetired() != old_flag.IsRetired()) {
// All registrations must agree on the 'retired' flag.
flags_internal::ReportUsageError(
absl::StrCat(
- "Retired flag '", flag->Name(),
- "' was defined normally in file '",
- (flag->IsRetired() ? old_flag->Filename() : flag->Filename()),
- "'."),
+ "Retired flag '", flag.Name(), "' was defined normally in file '",
+ (flag.IsRetired() ? old_flag.Filename() : flag.Filename()), "'."),
true);
- } else if (flags_internal::PrivateHandleAccessor::TypeId(*flag) !=
- flags_internal::PrivateHandleAccessor::TypeId(*old_flag)) {
+ } else if (flags_internal::PrivateHandleAccessor::TypeId(flag) !=
+ flags_internal::PrivateHandleAccessor::TypeId(old_flag)) {
flags_internal::ReportUsageError(
- absl::StrCat("Flag '", flag->Name(),
+ absl::StrCat("Flag '", flag.Name(),
"' was defined more than once but with "
"differing types. Defined in files '",
- old_flag->Filename(), "' and '", flag->Filename(), "'."),
+ old_flag.Filename(), "' and '", flag.Filename(), "'."),
true);
- } else if (old_flag->IsRetired()) {
+ } else if (old_flag.IsRetired()) {
// Retired flag can just be deleted.
DestroyRetiredFlag(flag);
return;
- } else if (old_flag->Filename() != flag->Filename()) {
+ } else if (old_flag.Filename() != flag.Filename()) {
flags_internal::ReportUsageError(
- absl::StrCat("Flag '", flag->Name(),
+ absl::StrCat("Flag '", flag.Name(),
"' was defined more than once (in files '",
- old_flag->Filename(), "' and '", flag->Filename(),
- "')."),
+ old_flag.Filename(), "' and '", flag.Filename(), "')."),
true);
} else {
flags_internal::ReportUsageError(
absl::StrCat(
- "Something wrong with flag '", flag->Name(), "' in file '",
- flag->Filename(), "'. One possibility: file '", flag->Filename(),
+ "Something wrong with flag '", flag.Name(), "' in file '",
+ flag.Filename(), "'. One possibility: file '", flag.Filename(),
"' is being linked both statically and dynamically into this "
"executable. e.g. some files listed as srcs to a test and also "
"listed as srcs of some shared lib deps of the same test."),
@@ -206,7 +203,7 @@ class FlagSaverImpl {
// It's an error to call this more than once.
void SaveFromRegistry() {
assert(backup_registry_.empty()); // call only once!
- flags_internal::ForEachFlag([&](CommandLineFlag* flag) {
+ flags_internal::ForEachFlag([&](CommandLineFlag& flag) {
if (auto flag_state =
flags_internal::PrivateHandleAccessor::SaveState(flag)) {
backup_registry_.emplace_back(std::move(flag_state));
@@ -244,39 +241,39 @@ FlagSaver::~FlagSaver() {
CommandLineFlag* FindCommandLineFlag(absl::string_view name) {
if (name.empty()) return nullptr;
- FlagRegistry* const registry = FlagRegistry::GlobalRegistry();
+ FlagRegistry& registry = FlagRegistry::GlobalRegistry();
FlagRegistryLock frl(registry);
- return registry->FindFlagLocked(name);
+ return registry.FindFlagLocked(name);
}
CommandLineFlag* FindRetiredFlag(absl::string_view name) {
- FlagRegistry* const registry = FlagRegistry::GlobalRegistry();
+ FlagRegistry& registry = FlagRegistry::GlobalRegistry();
FlagRegistryLock frl(registry);
- return registry->FindRetiredFlagLocked(name);
+ return registry.FindRetiredFlagLocked(name);
}
// --------------------------------------------------------------------
-void ForEachFlagUnlocked(std::function<void(CommandLineFlag*)> visitor) {
- FlagRegistry* const registry = FlagRegistry::GlobalRegistry();
- for (FlagRegistry::FlagConstIterator i = registry->flags_.begin();
- i != registry->flags_.end(); ++i) {
- visitor(i->second);
+void ForEachFlagUnlocked(std::function<void(CommandLineFlag&)> visitor) {
+ FlagRegistry& registry = FlagRegistry::GlobalRegistry();
+ for (FlagRegistry::FlagConstIterator i = registry.flags_.begin();
+ i != registry.flags_.end(); ++i) {
+ visitor(*i->second);
}
}
-void ForEachFlag(std::function<void(CommandLineFlag*)> visitor) {
- FlagRegistry* const registry = FlagRegistry::GlobalRegistry();
+void ForEachFlag(std::function<void(CommandLineFlag&)> visitor) {
+ FlagRegistry& registry = FlagRegistry::GlobalRegistry();
FlagRegistryLock frl(registry);
ForEachFlagUnlocked(visitor);
}
// --------------------------------------------------------------------
-bool RegisterCommandLineFlag(CommandLineFlag* flag) {
- FlagRegistry::GlobalRegistry()->RegisterFlag(flag);
+bool RegisterCommandLineFlag(CommandLineFlag& flag) {
+ FlagRegistry::GlobalRegistry().RegisterFlag(flag);
return true;
}
@@ -307,7 +304,7 @@ class RetiredFlagObj final : public CommandLineFlag {
}
bool ParseFrom(absl::string_view, flags_internal::FlagSettingMode,
- flags_internal::ValueSource, std::string*) override {
+ flags_internal::ValueSource, std::string&) override {
return false;
}
@@ -320,16 +317,16 @@ class RetiredFlagObj final : public CommandLineFlag {
const FlagFastTypeId type_id_;
};
-void DestroyRetiredFlag(CommandLineFlag* flag) {
- assert(flag->IsRetired());
- delete static_cast<RetiredFlagObj*>(flag);
+void DestroyRetiredFlag(CommandLineFlag& flag) {
+ assert(flag.IsRetired());
+ delete static_cast<RetiredFlagObj*>(&flag);
}
} // namespace
bool Retire(const char* name, FlagFastTypeId type_id) {
auto* flag = new flags_internal::RetiredFlagObj(name, type_id);
- FlagRegistry::GlobalRegistry()->RegisterFlag(flag);
+ FlagRegistry::GlobalRegistry().RegisterFlag(*flag);
return true;
}
diff --git a/absl/flags/internal/registry.h b/absl/flags/internal/registry.h
index f722fd44..a118865a 100644
--- a/absl/flags/internal/registry.h
+++ b/absl/flags/internal/registry.h
@@ -39,14 +39,14 @@ CommandLineFlag* FindRetiredFlag(absl::string_view name);
// Executes specified visitor for each non-retired flag in the registry.
// Requires the caller hold the registry lock.
-void ForEachFlagUnlocked(std::function<void(CommandLineFlag*)> visitor);
+void ForEachFlagUnlocked(std::function<void(CommandLineFlag&)> visitor);
// Executes specified visitor for each non-retired flag in the registry. While
// callback are executed, the registry is locked and can't be changed.
-void ForEachFlag(std::function<void(CommandLineFlag*)> visitor);
+void ForEachFlag(std::function<void(CommandLineFlag&)> visitor);
//-----------------------------------------------------------------------------
-bool RegisterCommandLineFlag(CommandLineFlag*);
+bool RegisterCommandLineFlag(CommandLineFlag&);
//-----------------------------------------------------------------------------
// Retired registrations:
diff --git a/absl/flags/internal/type_erased.cc b/absl/flags/internal/type_erased.cc
index 35b0d125..b2523b24 100644
--- a/absl/flags/internal/type_erased.cc
+++ b/absl/flags/internal/type_erased.cc
@@ -58,7 +58,7 @@ bool SetCommandLineOptionWithMode(absl::string_view name,
std::string error;
if (!flags_internal::PrivateHandleAccessor::ParseFrom(
- flag, value, set_mode, kProgrammaticChange, &error)) {
+ *flag, value, set_mode, kProgrammaticChange, error)) {
// Errors here are all of the form: the provided name was a recognized
// flag, but the value was invalid (bad type, or validation failed).
flags_internal::ReportUsageError(error, false);
diff --git a/absl/flags/internal/usage.cc b/absl/flags/internal/usage.cc
index 11664e10..2a2231a7 100644
--- a/absl/flags/internal/usage.cc
+++ b/absl/flags/internal/usage.cc
@@ -107,8 +107,8 @@ class FlagHelpPrettyPrinter {
public:
// Pretty printer holds on to the std::ostream& reference to direct an output
// to that stream.
- FlagHelpPrettyPrinter(int max_line_len, std::ostream* out)
- : out_(*out),
+ FlagHelpPrettyPrinter(int max_line_len, std::ostream& out)
+ : out_(out),
max_line_len_(max_line_len),
line_len_(0),
first_line_(true) {}
@@ -182,7 +182,7 @@ class FlagHelpPrettyPrinter {
bool first_line_;
};
-void FlagHelpHumanReadable(const CommandLineFlag& flag, std::ostream* out) {
+void FlagHelpHumanReadable(const CommandLineFlag& flag, std::ostream& out) {
FlagHelpPrettyPrinter printer(80, out); // Max line length is 80.
// Flag name.
@@ -244,29 +244,28 @@ void FlagsHelpImpl(std::ostream& out, flags_internal::FlagKindFilter filter_cb,
// This map is used to output matching flags grouped by package and file
// name.
std::map<std::string,
- std::map<std::string, std::vector<const CommandLineFlag*>>>
+ std::map<std::string, std::vector<const absl::CommandLineFlag*>>>
matching_flags;
- flags_internal::ForEachFlag([&](CommandLineFlag* flag) {
- std::string flag_filename = flag->Filename();
+ flags_internal::ForEachFlag([&](absl::CommandLineFlag& flag) {
+ std::string flag_filename = flag.Filename();
// Ignore retired flags.
- if (flag->IsRetired()) return;
+ if (flag.IsRetired()) return;
// If the flag has been stripped, pretend that it doesn't exist.
- if (flag->Help() == flags_internal::kStrippedFlagHelp) return;
+ if (flag.Help() == flags_internal::kStrippedFlagHelp) return;
// Make sure flag satisfies the filter
if (!filter_cb || !filter_cb(flag_filename)) return;
matching_flags[std::string(flags_internal::Package(flag_filename))]
[flag_filename]
- .push_back(flag);
+ .push_back(&flag);
});
- absl::string_view
- package_separator; // controls blank lines between packages.
- absl::string_view file_separator; // controls blank lines between files.
+ absl::string_view package_separator; // controls blank lines between packages
+ absl::string_view file_separator; // controls blank lines between files
for (const auto& package : matching_flags) {
if (format == HelpFormat::kHumanReadable) {
out << package_separator;
@@ -304,7 +303,7 @@ void FlagsHelpImpl(std::ostream& out, flags_internal::FlagKindFilter filter_cb,
void FlagHelp(std::ostream& out, const CommandLineFlag& flag,
HelpFormat format) {
if (format == HelpFormat::kHumanReadable)
- flags_internal::FlagHelpHumanReadable(flag, &out);
+ flags_internal::FlagHelpHumanReadable(flag, out);
}
// --------------------------------------------------------------------