about summary refs log tree commit diff
path: root/absl/flags/internal/commandlineflag.h
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2019-08-23T18·38-0700
committerXiaoyi Zhang <zhangxy@google.com>2019-08-23T18·48-0400
commit2d2d7fbc283315b676159716376e739d3d23ed94 (patch)
tree6530edfdc7591c4f89d0aa48442cc6d452c47735 /absl/flags/internal/commandlineflag.h
parent0302d1e5fa4fcdd1763b7d1bb3212943b1ae911d (diff)
Export of internal Abseil changes
--
d6748c733a70cd74ad9b76a0c9cd6b3fe2cecacf by Xiaoyi Zhang <zhangxy@google.com>:

Remove empty block, to address alerts reported in
https://github.com/abseil/abseil-cpp/issues/368.

PiperOrigin-RevId: 265099887

--
232e2036b5668d6d1296b881f9347756d84541ee by Derek Mauro <dmauro@google.com>:

Make the Linux Bazel CI scripts test with the exception mode explicitly set.

PiperOrigin-RevId: 265092105

--
942a40696c2c9b833be03e92d22a6ede7bccb6d4 by Xiaoyi Zhang <zhangxy@google.com>:

Import https://github.com/abseil/abseil-cpp/pull/372.
Suppress the unused variable warning on GCC, i.e. "-Wunused-variable".

PiperOrigin-RevId: 265063925

--
7ef90796b52cbdc260afc77cf47206f9356471d0 by Xiaoyi Zhang <zhangxy@google.com>:

Add quotes to `ABSL_COMMON_INCLUDE_DIRS` since it's a list and may contain a
`;`. This addresses https://github.com/abseil/abseil-cpp/issues/373.

PiperOrigin-RevId: 265059077

--
43f3ae742e00b83672ad6c5bc5b17fdb8f9fe6fe by Gennadiy Rozental <rogeeff@google.com>:

Internal re-organization

PiperOrigin-RevId: 264913945

--
6a2adf9c08ee1d98cc6b2855a676345c6495294a by Andy Soffer <asoffer@google.com>:

Publicly expose type names for uniform interval tags as in, for example, absl::IntervalClosedClosedTag, and add equality comparison operators.

PiperOrigin-RevId: 264861162

--
3c90c6e05fd61d56b419cd2d39dab8f17b8711b8 by Abseil Team <absl-team@google.com>:

Add validity check on returned frame pointer.

PiperOrigin-RevId: 264858823

--
2db87e0cfa0c6bea7ba81684b834cb8a73b7d748 by Gennadiy Rozental <rogeeff@google.com>:

Add MUST_USE_RESULT attribute to absl::GetFlag to prevent accidental misuse.

PiperOrigin-RevId: 264782762
GitOrigin-RevId: d6748c733a70cd74ad9b76a0c9cd6b3fe2cecacf
Change-Id: I169e9c5358e4f63000c1255e806d26b8afecf5ff
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 d82443a7760e..235125762b27 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.