about summary refs log tree commit diff
path: root/absl/flags/internal
diff options
context:
space:
mode:
Diffstat (limited to 'absl/flags/internal')
-rw-r--r--absl/flags/internal/commandlineflag.cc27
-rw-r--r--absl/flags/internal/commandlineflag.h31
-rw-r--r--absl/flags/internal/commandlineflag_test.cc31
-rw-r--r--absl/flags/internal/flag.h1
-rw-r--r--absl/flags/internal/private_handle_accessor.cc52
-rw-r--r--absl/flags/internal/private_handle_accessor.h52
-rw-r--r--absl/flags/internal/registry.cc7
-rw-r--r--absl/flags/internal/type_erased.cc7
-rw-r--r--absl/flags/internal/usage.cc1
9 files changed, 131 insertions, 78 deletions
diff --git a/absl/flags/internal/commandlineflag.cc b/absl/flags/internal/commandlineflag.cc
index c919fa1be8a7..84112437d9cf 100644
--- a/absl/flags/internal/commandlineflag.cc
+++ b/absl/flags/internal/commandlineflag.cc
@@ -28,33 +28,6 @@ bool CommandLineFlag::ParseFrom(absl::string_view value, std::string* error) {
                    flags_internal::kProgrammaticChange, error);
 }
 
-FlagFastTypeId PrivateHandleInterface::TypeId(const CommandLineFlag& flag) {
-  return flag.TypeId();
-}
-
-std::unique_ptr<FlagStateInterface> PrivateHandleInterface::SaveState(
-    CommandLineFlag* flag) {
-  return flag->SaveState();
-}
-
-bool PrivateHandleInterface::ValidateInputValue(const CommandLineFlag& flag,
-                                                absl::string_view value) {
-  return flag.ValidateInputValue(value);
-}
-
-void PrivateHandleInterface::CheckDefaultValueParsingRoundtrip(
-    const CommandLineFlag& flag) {
-  flag.CheckDefaultValueParsingRoundtrip();
-}
-
-bool PrivateHandleInterface::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);
-}
-
 }  // namespace flags_internal
 ABSL_NAMESPACE_END
 }  // namespace absl
diff --git a/absl/flags/internal/commandlineflag.h b/absl/flags/internal/commandlineflag.h
index af5e05d59984..2d3b794dbd0f 100644
--- a/absl/flags/internal/commandlineflag.h
+++ b/absl/flags/internal/commandlineflag.h
@@ -16,18 +16,12 @@
 #ifndef ABSL_FLAGS_INTERNAL_COMMANDLINEFLAG_H_
 #define ABSL_FLAGS_INTERNAL_COMMANDLINEFLAG_H_
 
-#include <stddef.h>
-#include <stdint.h>
-
 #include <memory>
 #include <string>
-#include <typeinfo>
 
 #include "absl/base/config.h"
 #include "absl/base/internal/fast_type_id.h"
 #include "absl/base/macros.h"
-#include "absl/flags/config.h"
-#include "absl/flags/marshalling.h"
 #include "absl/strings/string_view.h"
 #include "absl/types/optional.h"
 
@@ -147,7 +141,7 @@ class CommandLineFlag {
   ~CommandLineFlag() = default;
 
  private:
-  friend class PrivateHandleInterface;
+  friend class PrivateHandleAccessor;
 
   // Sets the value of the flag based on specified string `value`. If the flag
   // was successfully set to new value, it returns true. Otherwise, sets `error`
@@ -181,29 +175,6 @@ class CommandLineFlag {
   virtual void CheckDefaultValueParsingRoundtrip() const = 0;
 };
 
-// This class serves as a trampoline to access private methods of
-// CommandLineFlag. This class is intended for use exclusively internally inside
-// of the Abseil Flags implementation
-class PrivateHandleInterface {
- public:
-  // Access to CommandLineFlag::TypeId.
-  static FlagFastTypeId TypeId(const CommandLineFlag& flag);
-
-  // Access to CommandLineFlag::SaveState.
-  static std::unique_ptr<FlagStateInterface> SaveState(CommandLineFlag* flag);
-
-  // Access to CommandLineFlag::ValidateInputValue.
-  static bool ValidateInputValue(const CommandLineFlag& flag,
-                                 absl::string_view value);
-
-  // Access to CommandLineFlag::CheckDefaultValueParsingRoundtrip.
-  static void CheckDefaultValueParsingRoundtrip(const CommandLineFlag& flag);
-
-  static bool ParseFrom(CommandLineFlag* flag, absl::string_view value,
-                        flags_internal::FlagSettingMode set_mode,
-                        flags_internal::ValueSource source, std::string* error);
-};
-
 // This macro is the "source of truth" for the list of supported flag built-in
 // types.
 #define ABSL_FLAGS_INTERNAL_BUILTIN_TYPES(A) \
diff --git a/absl/flags/internal/commandlineflag_test.cc b/absl/flags/internal/commandlineflag_test.cc
index 4aeb3bf4dd3c..54d50fff353d 100644
--- a/absl/flags/internal/commandlineflag_test.cc
+++ b/absl/flags/internal/commandlineflag_test.cc
@@ -20,6 +20,7 @@
 
 #include "gtest/gtest.h"
 #include "absl/flags/flag.h"
+#include "absl/flags/internal/private_handle_accessor.h"
 #include "absl/flags/internal/registry.h"
 #include "absl/flags/usage_config.h"
 #include "absl/memory/memory.h"
@@ -122,52 +123,52 @@ TEST_F(CommandLineFlagTest, TestParseFromCurrentValue) {
   auto* flag_01 = flags::FindCommandLineFlag("int_flag");
   EXPECT_FALSE(flag_01->IsSpecifiedOnCommandLine());
 
-  EXPECT_TRUE(flags::PrivateHandleInterface::ParseFrom(
+  EXPECT_TRUE(flags::PrivateHandleAccessor::ParseFrom(
       flag_01, "11", flags::SET_FLAGS_VALUE, flags::kProgrammaticChange, &err));
   EXPECT_EQ(absl::GetFlag(FLAGS_int_flag), 11);
   EXPECT_FALSE(flag_01->IsSpecifiedOnCommandLine());
 
-  EXPECT_TRUE(flags::PrivateHandleInterface::ParseFrom(
+  EXPECT_TRUE(flags::PrivateHandleAccessor::ParseFrom(
       flag_01, "-123", flags::SET_FLAGS_VALUE, flags::kProgrammaticChange,
       &err));
   EXPECT_EQ(absl::GetFlag(FLAGS_int_flag), -123);
   EXPECT_FALSE(flag_01->IsSpecifiedOnCommandLine());
 
-  EXPECT_TRUE(!flags::PrivateHandleInterface::ParseFrom(
+  EXPECT_TRUE(!flags::PrivateHandleAccessor::ParseFrom(
       flag_01, "xyz", flags::SET_FLAGS_VALUE, flags::kProgrammaticChange,
       &err));
   EXPECT_EQ(absl::GetFlag(FLAGS_int_flag), -123);
   EXPECT_EQ(err, "Illegal value 'xyz' specified for flag 'int_flag'");
   EXPECT_FALSE(flag_01->IsSpecifiedOnCommandLine());
 
-  EXPECT_TRUE(!flags::PrivateHandleInterface::ParseFrom(
+  EXPECT_TRUE(!flags::PrivateHandleAccessor::ParseFrom(
       flag_01, "A1", flags::SET_FLAGS_VALUE, flags::kProgrammaticChange, &err));
   EXPECT_EQ(absl::GetFlag(FLAGS_int_flag), -123);
   EXPECT_EQ(err, "Illegal value 'A1' specified for flag 'int_flag'");
   EXPECT_FALSE(flag_01->IsSpecifiedOnCommandLine());
 
-  EXPECT_TRUE(flags::PrivateHandleInterface::ParseFrom(
+  EXPECT_TRUE(flags::PrivateHandleAccessor::ParseFrom(
       flag_01, "0x10", flags::SET_FLAGS_VALUE, flags::kProgrammaticChange,
       &err));
   EXPECT_EQ(absl::GetFlag(FLAGS_int_flag), 16);
   EXPECT_FALSE(flag_01->IsSpecifiedOnCommandLine());
 
-  EXPECT_TRUE(flags::PrivateHandleInterface::ParseFrom(
+  EXPECT_TRUE(flags::PrivateHandleAccessor::ParseFrom(
       flag_01, "011", flags::SET_FLAGS_VALUE, flags::kCommandLine, &err));
   EXPECT_EQ(absl::GetFlag(FLAGS_int_flag), 11);
   EXPECT_TRUE(flag_01->IsSpecifiedOnCommandLine());
 
-  EXPECT_TRUE(!flags::PrivateHandleInterface::ParseFrom(
+  EXPECT_TRUE(!flags::PrivateHandleAccessor::ParseFrom(
       flag_01, "", flags::SET_FLAGS_VALUE, flags::kProgrammaticChange, &err));
   EXPECT_EQ(err, "Illegal value '' specified for flag 'int_flag'");
 
   auto* flag_02 = flags::FindCommandLineFlag("string_flag");
-  EXPECT_TRUE(flags::PrivateHandleInterface::ParseFrom(
+  EXPECT_TRUE(flags::PrivateHandleAccessor::ParseFrom(
       flag_02, "xyz", flags::SET_FLAGS_VALUE, flags::kProgrammaticChange,
       &err));
   EXPECT_EQ(absl::GetFlag(FLAGS_string_flag), "xyz");
 
-  EXPECT_TRUE(flags::PrivateHandleInterface::ParseFrom(
+  EXPECT_TRUE(flags::PrivateHandleAccessor::ParseFrom(
       flag_02, "", flags::SET_FLAGS_VALUE, flags::kProgrammaticChange, &err));
   EXPECT_EQ(absl::GetFlag(FLAGS_string_flag), "");
 }
@@ -179,14 +180,14 @@ TEST_F(CommandLineFlagTest, TestParseFromDefaultValue) {
 
   auto* flag_01 = flags::FindCommandLineFlag("int_flag");
 
-  EXPECT_TRUE(flags::PrivateHandleInterface::ParseFrom(
+  EXPECT_TRUE(flags::PrivateHandleAccessor::ParseFrom(
       flag_01, "111", flags::SET_FLAGS_DEFAULT, flags::kProgrammaticChange,
       &err));
   EXPECT_EQ(flag_01->DefaultValue(), "111");
 
   auto* flag_02 = flags::FindCommandLineFlag("string_flag");
 
-  EXPECT_TRUE(flags::PrivateHandleInterface::ParseFrom(
+  EXPECT_TRUE(flags::PrivateHandleAccessor::ParseFrom(
       flag_02, "abc", flags::SET_FLAGS_DEFAULT, flags::kProgrammaticChange,
       &err));
   EXPECT_EQ(flag_02->DefaultValue(), "abc");
@@ -199,24 +200,24 @@ TEST_F(CommandLineFlagTest, TestParseFromIfDefault) {
 
   auto* flag_01 = flags::FindCommandLineFlag("int_flag");
 
-  EXPECT_TRUE(flags::PrivateHandleInterface::ParseFrom(
+  EXPECT_TRUE(flags::PrivateHandleAccessor::ParseFrom(
       flag_01, "22", flags::SET_FLAG_IF_DEFAULT, flags::kProgrammaticChange,
       &err))
       << err;
   EXPECT_EQ(absl::GetFlag(FLAGS_int_flag), 22);
 
-  EXPECT_TRUE(flags::PrivateHandleInterface::ParseFrom(
+  EXPECT_TRUE(flags::PrivateHandleAccessor::ParseFrom(
       flag_01, "33", flags::SET_FLAG_IF_DEFAULT, flags::kProgrammaticChange,
       &err));
   EXPECT_EQ(absl::GetFlag(FLAGS_int_flag), 22);
   // EXPECT_EQ(err, "ERROR: int_flag is already set to 22");
 
   // Reset back to default value
-  EXPECT_TRUE(flags::PrivateHandleInterface::ParseFrom(
+  EXPECT_TRUE(flags::PrivateHandleAccessor::ParseFrom(
       flag_01, "201", flags::SET_FLAGS_VALUE, flags::kProgrammaticChange,
       &err));
 
-  EXPECT_TRUE(flags::PrivateHandleInterface::ParseFrom(
+  EXPECT_TRUE(flags::PrivateHandleAccessor::ParseFrom(
       flag_01, "33", flags::SET_FLAG_IF_DEFAULT, flags::kProgrammaticChange,
       &err));
   EXPECT_EQ(absl::GetFlag(FLAGS_int_flag), 201);
diff --git a/absl/flags/internal/flag.h b/absl/flags/internal/flag.h
index b2208824508d..f53f484f8f44 100644
--- a/absl/flags/internal/flag.h
+++ b/absl/flags/internal/flag.h
@@ -31,6 +31,7 @@
 #include "absl/flags/config.h"
 #include "absl/flags/internal/commandlineflag.h"
 #include "absl/flags/internal/registry.h"
+#include "absl/flags/marshalling.h"
 #include "absl/memory/memory.h"
 #include "absl/meta/type_traits.h"
 #include "absl/strings/str_cat.h"
diff --git a/absl/flags/internal/private_handle_accessor.cc b/absl/flags/internal/private_handle_accessor.cc
new file mode 100644
index 000000000000..ec5776bb068e
--- /dev/null
+++ b/absl/flags/internal/private_handle_accessor.cc
@@ -0,0 +1,52 @@
+//
+// Copyright 2020 The Abseil Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "absl/flags/internal/private_handle_accessor.h"
+
+namespace absl {
+ABSL_NAMESPACE_BEGIN
+namespace flags_internal {
+
+FlagFastTypeId PrivateHandleAccessor::TypeId(const CommandLineFlag& flag) {
+  return flag.TypeId();
+}
+
+std::unique_ptr<FlagStateInterface> PrivateHandleAccessor::SaveState(
+    CommandLineFlag* flag) {
+  return flag->SaveState();
+}
+
+bool PrivateHandleAccessor::ValidateInputValue(const CommandLineFlag& flag,
+                                               absl::string_view value) {
+  return flag.ValidateInputValue(value);
+}
+
+void PrivateHandleAccessor::CheckDefaultValueParsingRoundtrip(
+    const CommandLineFlag& flag) {
+  flag.CheckDefaultValueParsingRoundtrip();
+}
+
+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);
+}
+
+}  // namespace flags_internal
+ABSL_NAMESPACE_END
+}  // namespace absl
+
diff --git a/absl/flags/internal/private_handle_accessor.h b/absl/flags/internal/private_handle_accessor.h
new file mode 100644
index 000000000000..fbb4409cdbc7
--- /dev/null
+++ b/absl/flags/internal/private_handle_accessor.h
@@ -0,0 +1,52 @@
+//
+// Copyright 2020 The Abseil Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef ABSL_FLAGS_INTERNAL_PRIVATE_HANDLE_ACCESSOR_H_
+#define ABSL_FLAGS_INTERNAL_PRIVATE_HANDLE_ACCESSOR_H_
+
+#include "absl/flags/internal/commandlineflag.h"
+
+namespace absl {
+ABSL_NAMESPACE_BEGIN
+namespace flags_internal {
+
+// This class serves as a trampoline to access private methods of
+// CommandLineFlag. This class is intended for use exclusively internally inside
+// of the Abseil Flags implementation.
+class PrivateHandleAccessor {
+ public:
+  // Access to CommandLineFlag::TypeId.
+  static FlagFastTypeId TypeId(const CommandLineFlag& flag);
+
+  // Access to CommandLineFlag::SaveState.
+  static std::unique_ptr<FlagStateInterface> SaveState(CommandLineFlag* flag);
+
+  // Access to CommandLineFlag::ValidateInputValue.
+  static bool ValidateInputValue(const CommandLineFlag& flag,
+                                 absl::string_view value);
+
+  // Access to CommandLineFlag::CheckDefaultValueParsingRoundtrip.
+  static void CheckDefaultValueParsingRoundtrip(const CommandLineFlag& flag);
+
+  static bool ParseFrom(CommandLineFlag* flag, absl::string_view value,
+                        flags_internal::FlagSettingMode set_mode,
+                        flags_internal::ValueSource source, std::string* error);
+};
+
+}  // namespace flags_internal
+ABSL_NAMESPACE_END
+}  // namespace absl
+
+#endif  // ABSL_FLAGS_INTERNAL_PRIVATE_HANDLE_ACCESSOR_H_
diff --git a/absl/flags/internal/registry.cc b/absl/flags/internal/registry.cc
index 62b5b40d88b8..3b941f04c21d 100644
--- a/absl/flags/internal/registry.cc
+++ b/absl/flags/internal/registry.cc
@@ -29,6 +29,7 @@
 #include "absl/base/internal/raw_logging.h"
 #include "absl/base/thread_annotations.h"
 #include "absl/flags/internal/commandlineflag.h"
+#include "absl/flags/internal/private_handle_accessor.h"
 #include "absl/flags/usage_config.h"
 #include "absl/strings/str_cat.h"
 #include "absl/strings/string_view.h"
@@ -127,8 +128,8 @@ void FlagRegistry::RegisterFlag(CommandLineFlag* flag) {
               (flag->IsRetired() ? old_flag->Filename() : flag->Filename()),
               "'."),
           true);
-    } else if (flags_internal::PrivateHandleInterface::TypeId(*flag) !=
-               flags_internal::PrivateHandleInterface::TypeId(*old_flag)) {
+    } else if (flags_internal::PrivateHandleAccessor::TypeId(*flag) !=
+               flags_internal::PrivateHandleAccessor::TypeId(*old_flag)) {
       flags_internal::ReportUsageError(
           absl::StrCat("Flag '", flag->Name(),
                        "' was defined more than once but with "
@@ -206,7 +207,7 @@ class FlagSaverImpl {
     assert(backup_registry_.empty());  // call only once!
     flags_internal::ForEachFlag([&](flags_internal::CommandLineFlag* flag) {
       if (auto flag_state =
-              flags_internal::PrivateHandleInterface::SaveState(flag)) {
+              flags_internal::PrivateHandleAccessor::SaveState(flag)) {
         backup_registry_.emplace_back(std::move(flag_state));
       }
     });
diff --git a/absl/flags/internal/type_erased.cc b/absl/flags/internal/type_erased.cc
index adeb7a1541ab..3cfc9b2dfbe9 100644
--- a/absl/flags/internal/type_erased.cc
+++ b/absl/flags/internal/type_erased.cc
@@ -22,6 +22,7 @@
 #include "absl/base/config.h"
 #include "absl/base/internal/raw_logging.h"
 #include "absl/flags/internal/commandlineflag.h"
+#include "absl/flags/internal/private_handle_accessor.h"
 #include "absl/flags/internal/registry.h"
 #include "absl/flags/usage_config.h"
 #include "absl/strings/string_view.h"
@@ -56,7 +57,7 @@ bool SetCommandLineOptionWithMode(absl::string_view name,
   if (!flag || flag->IsRetired()) return false;
 
   std::string error;
-  if (!flags_internal::PrivateHandleInterface::ParseFrom(
+  if (!flags_internal::PrivateHandleAccessor::ParseFrom(
           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).
@@ -74,8 +75,8 @@ bool IsValidFlagValue(absl::string_view name, absl::string_view value) {
 
   return flag != nullptr &&
          (flag->IsRetired() ||
-          flags_internal::PrivateHandleInterface::ValidateInputValue(*flag,
-                                                                     value));
+          flags_internal::PrivateHandleAccessor::ValidateInputValue(*flag,
+                                                                    value));
 }
 
 // --------------------------------------------------------------------
diff --git a/absl/flags/internal/usage.cc b/absl/flags/internal/usage.cc
index 9d856c87a6c0..10accc46f32a 100644
--- a/absl/flags/internal/usage.cc
+++ b/absl/flags/internal/usage.cc
@@ -27,6 +27,7 @@
 #include "absl/flags/internal/commandlineflag.h"
 #include "absl/flags/internal/flag.h"
 #include "absl/flags/internal/path_util.h"
+#include "absl/flags/internal/private_handle_accessor.h"
 #include "absl/flags/internal/program_name.h"
 #include "absl/flags/internal/registry.h"
 #include "absl/flags/usage_config.h"