summaryrefslogtreecommitdiff
path: root/absl/flags/internal/flag.h
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2020-05-08 10:36:00 -0700
committerGravatar vslashg <gfalcon@google.com>2020-05-08 15:22:38 -0400
commitc45d1c09d517e145d722e00deea9be6c8be8dd57 (patch)
tree6db7d9f18aeb714064b25fd11ade71f3d2fbe3ae /absl/flags/internal/flag.h
parenta35ef8a62ce7cded2f131ccbd2b5c4a81d622507 (diff)
Export of internal Abseil changes
-- 47f13ea42ae272c995b1cd5073a45e046fa325eb by Matthew Brown <matthewbr@google.com>: absl::StrFormat: Centralize FormatConversionCharSet vs FormatConversionSpec checking - Move it into a central location, rather than requiring individual overloads to validate. PiperOrigin-RevId: 310583805 -- a567c8fc8032031d551d6b457755851f442e65ad by Gennadiy Rozental <rogeeff@google.com>: Internal change PiperOrigin-RevId: 310427635 -- 49848f7fab9b0f528d33f60cbccf688e2ea68afa by Gennadiy Rozental <rogeeff@google.com>: Make Get/Set private methods of absl::Flag<T>. PiperOrigin-RevId: 310413908 GitOrigin-RevId: 47f13ea42ae272c995b1cd5073a45e046fa325eb Change-Id: I6530c754731c1a9463877561fa61786460ed60af
Diffstat (limited to 'absl/flags/internal/flag.h')
-rw-r--r--absl/flags/internal/flag.h64
1 files changed, 50 insertions, 14 deletions
diff --git a/absl/flags/internal/flag.h b/absl/flags/internal/flag.h
index f53f484f..b060199e 100644
--- a/absl/flags/internal/flag.h
+++ b/absl/flags/internal/flag.h
@@ -40,6 +40,30 @@
namespace absl {
ABSL_NAMESPACE_BEGIN
+
+// Forward declaration of absl::Flag<T> public API.
+namespace flags_internal {
+template <typename T>
+class Flag;
+} // namespace flags_internal
+
+#if defined(_MSC_VER) && !defined(__clang__)
+template <typename T>
+class Flag;
+#else
+template <typename T>
+using Flag = flags_internal::Flag<T>;
+#endif
+
+template <typename T>
+ABSL_MUST_USE_RESULT T GetFlag(const absl::Flag<T>& flag);
+
+template <typename T>
+void SetFlag(absl::Flag<T>* flag, const T& v);
+
+template <typename T, typename V>
+void SetFlag(absl::Flag<T>* flag, const V& v);
+
namespace flags_internal {
///////////////////////////////////////////////////////////////////////////////
@@ -596,6 +620,32 @@ class Flag {
flags_internal::StorageKind<T>(), default_arg),
value_() {}
+ // CommandLineFlag interface
+ absl::string_view Name() const { return impl_.Name(); }
+ std::string Filename() const { return impl_.Filename(); }
+ std::string Help() const { return impl_.Help(); }
+ bool IsSpecifiedOnCommandLine() const {
+ return impl_.IsSpecifiedOnCommandLine();
+ }
+ std::string DefaultValue() const { return impl_.DefaultValue(); }
+ std::string CurrentValue() const { return impl_.CurrentValue(); }
+
+ private:
+ template <typename U, bool do_register>
+ friend class FlagRegistrar;
+
+#if !defined(_MSC_VER) || defined(__clang__)
+ template <typename U>
+ friend U absl::GetFlag(const flags_internal::Flag<U>& flag);
+ template <typename U>
+ friend void absl::SetFlag(flags_internal::Flag<U>* flag, const U& v);
+ template <typename U, typename V>
+ friend void absl::SetFlag(flags_internal::Flag<U>* flag, const V& v);
+#else
+ template <typename U>
+ friend class absl::Flag;
+#endif
+
T Get() const {
// See implementation notes in CommandLineFlag::Get().
union U {
@@ -617,20 +667,6 @@ class Flag {
impl_.Write(&v);
}
- // CommandLineFlag interface
- absl::string_view Name() const { return impl_.Name(); }
- std::string Filename() const { return impl_.Filename(); }
- std::string Help() const { return impl_.Help(); }
- bool IsSpecifiedOnCommandLine() const {
- return impl_.IsSpecifiedOnCommandLine();
- }
- std::string DefaultValue() const { return impl_.DefaultValue(); }
- std::string CurrentValue() const { return impl_.CurrentValue(); }
-
- private:
- template <typename U, bool do_register>
- friend class FlagRegistrar;
-
// Flag's data
// The implementation depends on value_ field to be placed exactly after the
// impl_ field, so that impl_ can figure out the offset to the value and