aboutsummaryrefslogtreecommitdiffhomepage
path: root/absl/flags/internal/commandlineflag.h
diff options
context:
space:
mode:
Diffstat (limited to 'absl/flags/internal/commandlineflag.h')
-rw-r--r--absl/flags/internal/commandlineflag.h64
1 files changed, 29 insertions, 35 deletions
diff --git a/absl/flags/internal/commandlineflag.h b/absl/flags/internal/commandlineflag.h
index d82443a..2351257 100644
--- a/absl/flags/internal/commandlineflag.h
+++ b/absl/flags/internal/commandlineflag.h
@@ -71,13 +71,6 @@ using InitialValGenFunc = void* (*)();
struct CommandLineFlagInfo;
-// Signature for the mutation callback used by watched Flags
-// The callback is noexcept.
-// TODO(rogeeff): add noexcept after C++17 support is added.
-using FlagCallback = void (*)();
-
-using FlagValidator = bool (*)();
-
extern const char kStrippedFlagHelp[];
// The per-type function
@@ -201,53 +194,55 @@ struct CommandLineFlag {
const char* name_arg, HelpText help_text, const char* filename_arg,
const flags_internal::FlagOpFn op_arg,
const flags_internal::FlagMarshallingOpFn marshalling_op_arg,
- const flags_internal::InitialValGenFunc initial_value_gen,
- const bool retired_arg, void* def_arg, void* cur_arg)
+ const flags_internal::InitialValGenFunc initial_value_gen, void* def_arg,
+ void* cur_arg)
: name(name_arg),
help(help_text),
filename(filename_arg),
op(op_arg),
marshalling_op(marshalling_op_arg),
make_init_value(initial_value_gen),
- retired(retired_arg),
inited(false),
modified(false),
on_command_line(false),
- validator(nullptr),
- callback(nullptr),
def(def_arg),
cur(cur_arg),
counter(0),
atomic(kAtomicInit),
locks(nullptr) {}
- // Revert the init routine.
- void Destroy() const;
+ // Virtual destructor
+ virtual void Destroy() const = 0;
// Not copyable/assignable.
CommandLineFlag(const CommandLineFlag&) = delete;
CommandLineFlag& operator=(const CommandLineFlag&) = delete;
+ // Access methods.
+
+ // Returns true iff this object corresponds to retired flag
+ virtual bool IsRetired() const { return false; }
+ // Returns true iff this is a handle to an Abseil Flag.
+ virtual bool IsAbseilFlag() const { return true; }
+
absl::string_view Name() const { return name; }
std::string Help() const { return help.GetHelpText(); }
- bool IsRetired() const { return this->retired; }
bool IsModified() const;
void SetModified(bool is_modified);
bool IsSpecifiedOnCommandLine() const;
- // Returns true iff this is a handle to an Abseil Flag.
- bool IsAbseilFlag() const {
- // Set to null for V1 flags
- return this->make_init_value != nullptr;
- }
absl::string_view Typename() const;
std::string Filename() const;
std::string DefaultValue() const;
std::string CurrentValue() const;
- bool HasValidatorFn() const;
- bool SetValidatorFn(FlagValidator fn);
- bool InvokeValidator(const void* value) const;
+ // Interfaces to operate on validators.
+ virtual bool HasValidatorFn() const { return false; }
+ virtual bool InvokeValidator(const void* /*value*/) const { return true; }
+ // Invoke the flag validators for old flags.
+ // TODO(rogeeff): implement proper validators for Abseil Flags
+ bool ValidateDefaultValue() const;
+ bool ValidateInputValue(absl::string_view value) const;
// Return true iff flag has type T.
template <typename T>
@@ -268,8 +263,8 @@ struct CommandLineFlag {
return res;
}
- void SetCallback(const flags_internal::FlagCallback mutation_callback);
- void InvokeCallback();
+ // Interfaces to overate on callbacks.
+ virtual void InvokeCallback() {}
// Sets the value of the flag based on specified std::string `value`. If the flag
// was successfully set to new value, it returns true. Otherwise, sets `error`
@@ -286,29 +281,23 @@ struct CommandLineFlag {
void StoreAtomic(size_t size);
void CheckDefaultValueParsingRoundtrip() const;
- // Invoke the flag validators for old flags.
- // TODO(rogeeff): implement proper validators for Abseil Flags
- bool ValidateDefaultValue() const;
- bool ValidateInputValue(absl::string_view value) const;
// Constant configuration for a particular flag.
- private:
+ protected:
+ ~CommandLineFlag() = default;
+
const char* const name;
const HelpText help;
const char* const filename;
- protected:
const FlagOpFn op; // Type-specific handler
const FlagMarshallingOpFn marshalling_op; // Marshalling ops handler
const InitialValGenFunc make_init_value; // Makes initial value for the flag
- const bool retired; // Is the flag retired?
std::atomic<bool> inited; // fields have been lazily initialized
// Mutable state (guarded by locks->primary_mu).
bool modified; // Has flag value been modified?
bool on_command_line; // Specified on command line.
- FlagValidator validator; // Validator function, or nullptr
- FlagCallback callback; // Mutation callback, or nullptr
void* def; // Lazily initialized pointer to default value
void* cur; // Lazily initialized pointer to current value
int64_t counter; // Mutation counter
@@ -326,7 +315,7 @@ struct CommandLineFlag {
// Ensure that the lazily initialized fields of *flag have been initialized,
// and return the lock which should be locked when flag's state is mutated.
- absl::Mutex* InitFlagIfNecessary() const;
+ absl::Mutex* InitFlagIfNecessary() const LOCK_RETURNED(locks->primary_mu);
// copy construct new value of flag's type in a memory referenced by dst
// based on current flag's value
@@ -342,6 +331,11 @@ struct CommandLineFlag {
friend bool TryParseLocked(CommandLineFlag* flag, void* dst,
absl::string_view value, std::string* err);
friend absl::Mutex* InitFlag(CommandLineFlag* flag);
+
+ // This is a short term, until we completely rework persistent state
+ // storage API.
+ virtual void* GetValidator() const { return nullptr; }
+ virtual void SetValidator(void*) {}
};
// Update any copy of the flag value that is stored in an atomic word.