aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/abseil-cpp/absl/flags/internal/flag.h
diff options
context:
space:
mode:
authoranastasy888 <anastasy888@yandex-team.ru>2022-02-10 16:45:54 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:54 +0300
commit49f765d71da452ea93138a25559dfa68dd76c7f3 (patch)
tree1016041feb637349e401dcc0fa85217dd2c2c639 /contrib/restricted/abseil-cpp/absl/flags/internal/flag.h
parent7353a3fdea9c67c256980c00a2b3b67f09b23a27 (diff)
downloadydb-49f765d71da452ea93138a25559dfa68dd76c7f3.tar.gz
Restoring authorship annotation for <anastasy888@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/restricted/abseil-cpp/absl/flags/internal/flag.h')
-rw-r--r--contrib/restricted/abseil-cpp/absl/flags/internal/flag.h278
1 files changed, 139 insertions, 139 deletions
diff --git a/contrib/restricted/abseil-cpp/absl/flags/internal/flag.h b/contrib/restricted/abseil-cpp/absl/flags/internal/flag.h
index 124a2f1c03..4324cfdf70 100644
--- a/contrib/restricted/abseil-cpp/absl/flags/internal/flag.h
+++ b/contrib/restricted/abseil-cpp/absl/flags/internal/flag.h
@@ -1,79 +1,79 @@
-//
-// Copyright 2019 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_FLAG_H_
-#define ABSL_FLAGS_INTERNAL_FLAG_H_
-
+//
+// Copyright 2019 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_FLAG_H_
+#define ABSL_FLAGS_INTERNAL_FLAG_H_
+
#include <stddef.h>
#include <stdint.h>
-#include <atomic>
-#include <cstring>
+#include <atomic>
+#include <cstring>
#include <memory>
#include <new>
#include <string>
#include <type_traits>
#include <typeinfo>
-
+
#include "absl/base/attributes.h"
#include "absl/base/call_once.h"
#include "absl/base/casts.h"
#include "absl/base/config.h"
#include "absl/base/optimization.h"
-#include "absl/base/thread_annotations.h"
+#include "absl/base/thread_annotations.h"
#include "absl/flags/commandlineflag.h"
#include "absl/flags/config.h"
-#include "absl/flags/internal/commandlineflag.h"
-#include "absl/flags/internal/registry.h"
+#include "absl/flags/internal/commandlineflag.h"
+#include "absl/flags/internal/registry.h"
#include "absl/flags/internal/sequence_lock.h"
#include "absl/flags/marshalling.h"
#include "absl/meta/type_traits.h"
#include "absl/strings/string_view.h"
-#include "absl/synchronization/mutex.h"
+#include "absl/synchronization/mutex.h"
#include "absl/utility/utility.h"
-
-namespace absl {
+
+namespace absl {
ABSL_NAMESPACE_BEGIN
///////////////////////////////////////////////////////////////////////////////
// Forward declaration of absl::Flag<T> public API.
-namespace flags_internal {
+namespace flags_internal {
template <typename T>
class Flag;
} // namespace flags_internal
-
+
#if defined(_MSC_VER) && !defined(__clang__)
-template <typename T>
-class Flag;
+template <typename T>
+class Flag;
#else
template <typename T>
using Flag = flags_internal::Flag<T>;
#endif
-
-template <typename T>
+
+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);
-
+
template <typename U>
const CommandLineFlag& GetFlagReflectionHandle(const absl::Flag<U>& f);
-
+
///////////////////////////////////////////////////////////////////////////////
// Flag value type operations, eg., parsing, copying, etc. are provided
// by function specific to that type with a signature matching FlagOpFn.
@@ -91,9 +91,9 @@ enum class FlagOp {
kParse,
kUnparse,
kValueOffset,
-};
+};
using FlagOpFn = void* (*)(FlagOp, const void*, void*, void*);
-
+
// Forward declaration for Flag value specific operations.
template <typename T>
void* FlagOps(FlagOp op, const void* v1, void* v2, void* v3);
@@ -173,15 +173,15 @@ inline const std::type_info* GenRuntimeTypeId() {
///////////////////////////////////////////////////////////////////////////////
// Flag help auxiliary structs.
-// This is help argument for absl::Flag encapsulating the string literal pointer
-// or pointer to function generating it as well as enum descriminating two
-// cases.
-using HelpGenFunc = std::string (*)();
-
+// This is help argument for absl::Flag encapsulating the string literal pointer
+// or pointer to function generating it as well as enum descriminating two
+// cases.
+using HelpGenFunc = std::string (*)();
+
template <size_t N>
struct FixedCharArray {
char value[N];
-
+
template <size_t... I>
static constexpr FixedCharArray<N> FromLiteralString(
absl::string_view str, absl::index_sequence<I...>) {
@@ -204,50 +204,50 @@ union FlagHelpMsg {
constexpr explicit FlagHelpMsg(const char* help_msg) : literal(help_msg) {}
constexpr explicit FlagHelpMsg(HelpGenFunc help_gen) : gen_func(help_gen) {}
- const char* literal;
- HelpGenFunc gen_func;
-};
-
+ const char* literal;
+ HelpGenFunc gen_func;
+};
+
enum class FlagHelpKind : uint8_t { kLiteral = 0, kGenFunc = 1 };
-
+
struct FlagHelpArg {
FlagHelpMsg source;
FlagHelpKind kind;
-};
-
+};
+
extern const char kStrippedFlagHelp[];
-
-// These two HelpArg overloads allows us to select at compile time one of two
-// way to pass Help argument to absl::Flag. We'll be passing
+
+// These two HelpArg overloads allows us to select at compile time one of two
+// way to pass Help argument to absl::Flag. We'll be passing
// AbslFlagHelpGenFor##name as Gen and integer 0 as a single argument to prefer
// first overload if possible. If help message is evaluatable on constexpr
// context We'll be able to make FixedCharArray out of it and we'll choose first
// overload. In this case the help message expression is immediately evaluated
// and is used to construct the absl::Flag. No additionl code is generated by
// ABSL_FLAG Otherwise SFINAE kicks in and first overload is dropped from the
-// consideration, in which case the second overload will be used. The second
-// overload does not attempt to evaluate the help message expression
-// immediately and instead delays the evaluation by returing the function
-// pointer (&T::NonConst) genering the help message when necessary. This is
-// evaluatable in constexpr context, but the cost is an extra function being
-// generated in the ABSL_FLAG code.
+// consideration, in which case the second overload will be used. The second
+// overload does not attempt to evaluate the help message expression
+// immediately and instead delays the evaluation by returing the function
+// pointer (&T::NonConst) genering the help message when necessary. This is
+// evaluatable in constexpr context, but the cost is an extra function being
+// generated in the ABSL_FLAG code.
template <typename Gen, size_t N>
constexpr FlagHelpArg HelpArg(const FixedCharArray<N>& value) {
return {FlagHelpMsg(value.value), FlagHelpKind::kLiteral};
-}
-
+}
+
template <typename Gen>
constexpr FlagHelpArg HelpArg(std::false_type) {
return {FlagHelpMsg(&Gen::NonConst), FlagHelpKind::kGenFunc};
-}
-
+}
+
///////////////////////////////////////////////////////////////////////////////
// Flag default value auxiliary structs.
// Signature for the function generating the initial flag value (usually
-// based on default value supplied in flag's definition)
+// based on default value supplied in flag's definition)
using FlagDfltGenFunc = void (*)(void*);
-
+
union FlagDefaultSrc {
constexpr explicit FlagDefaultSrc(FlagDfltGenFunc gen_func_arg)
: gen_func(gen_func_arg) {}
@@ -404,16 +404,16 @@ struct FlagValue<T, FlagValueStorageKind::kAlignedBuffer> {
///////////////////////////////////////////////////////////////////////////////
// Flag callback auxiliary structs.
-// Signature for the mutation callback used by watched Flags
-// The callback is noexcept.
-// TODO(rogeeff): add noexcept after C++17 support is added.
+// Signature for the mutation callback used by watched Flags
+// The callback is noexcept.
+// TODO(rogeeff): add noexcept after C++17 support is added.
using FlagCallbackFunc = void (*)();
-
+
struct FlagCallback {
FlagCallbackFunc func;
absl::Mutex guard; // Guard for concurrent callback invocations.
};
-
+
///////////////////////////////////////////////////////////////////////////////
// Flag implementation, which does not depend on flag value type.
// The class encapsulates the Flag's data and access to it.
@@ -428,14 +428,14 @@ struct DynValueDeleter {
class FlagState;
class FlagImpl final : public CommandLineFlag {
- public:
+ public:
constexpr FlagImpl(const char* name, const char* filename, FlagOpFn op,
FlagHelpArg help, FlagValueStorageKind value_kind,
FlagDefaultArg default_arg)
: name_(name),
filename_(filename),
op_(op),
- help_(help.source),
+ help_(help.source),
help_source_kind_(static_cast<uint8_t>(help.kind)),
value_storage_kind_(static_cast<uint8_t>(value_kind)),
def_kind_(static_cast<uint8_t>(default_arg.kind)),
@@ -444,8 +444,8 @@ class FlagImpl final : public CommandLineFlag {
callback_(nullptr),
default_value_(default_arg.source),
data_guard_{} {}
-
- // Constant access methods
+
+ // Constant access methods
int64_t ReadOneWord() const ABSL_LOCKS_EXCLUDED(*DataGuard());
bool ReadOneBool() const ABSL_LOCKS_EXCLUDED(*DataGuard());
void Read(void* dst) const override ABSL_LOCKS_EXCLUDED(*DataGuard());
@@ -467,15 +467,15 @@ class FlagImpl final : public CommandLineFlag {
void Read(T* value) const ABSL_LOCKS_EXCLUDED(*DataGuard()) {
*value = absl::bit_cast<FlagValueAndInitBit<T>>(ReadOneWord()).value;
}
-
- // Mutating access methods
+
+ // Mutating access methods
void Write(const void* src) ABSL_LOCKS_EXCLUDED(*DataGuard());
-
- // Interfaces to operate on callbacks.
+
+ // Interfaces to operate on callbacks.
void SetCallback(const FlagCallbackFunc mutation_callback)
ABSL_LOCKS_EXCLUDED(*DataGuard());
void InvokeCallback() const ABSL_EXCLUSIVE_LOCKS_REQUIRED(*DataGuard());
-
+
// Used in read/write operations to validate source/target has correct type.
// For example if flag is declared as absl::Flag<int> FLAGS_foo, a call to
// absl::GetFlag(FLAGS_foo) validates that the type of FLAGS_foo is indeed
@@ -486,10 +486,10 @@ class FlagImpl final : public CommandLineFlag {
const std::type_info* (*gen_rtti)()) const;
private:
- template <typename T>
+ template <typename T>
friend class Flag;
friend class FlagState;
-
+
// Ensures that `data_guard_` is initialized and returns it.
absl::Mutex* DataGuard() const
ABSL_LOCK_RETURNED(reinterpret_cast<absl::Mutex*>(data_guard_));
@@ -535,7 +535,7 @@ class FlagImpl final : public CommandLineFlag {
FlagHelpKind HelpSourceKind() const {
return static_cast<FlagHelpKind>(help_source_kind_);
- }
+ }
FlagValueStorageKind ValueStorageKind() const {
return static_cast<FlagValueStorageKind>(value_storage_kind_);
}
@@ -543,7 +543,7 @@ class FlagImpl final : public CommandLineFlag {
ABSL_EXCLUSIVE_LOCKS_REQUIRED(*DataGuard()) {
return static_cast<FlagDefaultKind>(def_kind_);
}
-
+
// CommandLineFlag interface implementation
absl::string_view Name() const override;
std::string Filename() const override;
@@ -557,7 +557,7 @@ class FlagImpl final : public CommandLineFlag {
ABSL_LOCKS_EXCLUDED(*DataGuard());
void CheckDefaultValueParsingRoundtrip() const override
ABSL_LOCKS_EXCLUDED(*DataGuard());
-
+
int64_t ModificationCount() const ABSL_EXCLUSIVE_LOCKS_REQUIRED(*DataGuard());
// Interfaces to save and restore flags to/from persistent state.
@@ -565,7 +565,7 @@ class FlagImpl final : public CommandLineFlag {
// saving and restoring a state.
std::unique_ptr<FlagStateInterface> SaveState() override
ABSL_LOCKS_EXCLUDED(*DataGuard());
-
+
// Restores the flag state to the supplied state object. If there is
// nothing to restore returns false. Otherwise returns true.
bool RestoreState(const FlagState& flag_state)
@@ -585,11 +585,11 @@ class FlagImpl final : public CommandLineFlag {
const FlagOpFn op_;
// Help message literal or function to generate it.
const FlagHelpMsg help_;
- // Indicates if help message was supplied as literal or generator func.
+ // Indicates if help message was supplied as literal or generator func.
const uint8_t help_source_kind_ : 1;
// Kind of storage this flag is using for the flag's value.
const uint8_t value_storage_kind_ : 2;
-
+
uint8_t : 0; // The bytes containing the const bitfields must not be
// shared with bytes containing the mutable bitfields.
@@ -616,7 +616,7 @@ class FlagImpl final : public CommandLineFlag {
// value via SetCommandLineOptionWithMode. def_kind_ is used to distinguish
// these two cases.
FlagDefaultSrc default_value_;
-
+
// This is reserved space for an absl::Mutex to guard flag data. It will be
// initialized in FlagImpl::Init via placement new.
// We can't use "absl::Mutex data_guard_", since this class is not literal.
@@ -625,21 +625,21 @@ class FlagImpl final : public CommandLineFlag {
// and can fail. Using reserved space + placement new allows us to avoid both
// problems.
alignas(absl::Mutex) mutable char data_guard_[sizeof(absl::Mutex)];
-};
-
+};
+
///////////////////////////////////////////////////////////////////////////////
// The Flag object parameterized by the flag's value type. This class implements
// flag reflection handle interface.
-template <typename T>
+template <typename T>
class Flag {
- public:
+ public:
constexpr Flag(const char* name, const char* filename, FlagHelpArg help,
const FlagDefaultArg default_arg)
: impl_(name, filename, &FlagOps<T>, help,
flags_internal::StorageKind<T>(), default_arg),
value_() {}
-
+
// CommandLineFlag interface
absl::string_view Name() const { return impl_.Name(); }
std::string Filename() const { return impl_.Filename(); }
@@ -656,15 +656,15 @@ class Flag {
friend class FlagRegistrar;
friend class FlagImplPeer;
- T Get() const {
- // See implementation notes in CommandLineFlag::Get().
- union U {
- T value;
- U() {}
- ~U() { value.~T(); }
- };
- U u;
-
+ T Get() const {
+ // See implementation notes in CommandLineFlag::Get().
+ union U {
+ T value;
+ U() {}
+ ~U() { value.~T(); }
+ };
+ U u;
+
#if !defined(NDEBUG)
impl_.AssertValidType(base_internal::FastTypeId<T>(), &GenRuntimeTypeId<T>);
#endif
@@ -672,16 +672,16 @@ class Flag {
if (ABSL_PREDICT_FALSE(!value_.Get(impl_.seq_lock_, u.value))) {
impl_.Read(&u.value);
}
- return std::move(u.value);
- }
+ return std::move(u.value);
+ }
void Set(const T& v) {
impl_.AssertValidType(base_internal::FastTypeId<T>(), &GenRuntimeTypeId<T>);
impl_.Write(&v);
- }
-
+ }
+
// Access to the reflection.
const CommandLineFlag& Reflect() const { return impl_; }
-
+
// 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
@@ -689,29 +689,29 @@ class Flag {
FlagImpl impl_;
FlagValue<T> value_;
};
-
+
///////////////////////////////////////////////////////////////////////////////
// Trampoline for friend access
-
+
class FlagImplPeer {
public:
template <typename T, typename FlagType>
static T InvokeGet(const FlagType& flag) {
return flag.Get();
- }
+ }
template <typename FlagType, typename T>
static void InvokeSet(FlagType& flag, const T& v) {
flag.Set(v);
- }
+ }
template <typename FlagType>
static const CommandLineFlag& InvokeReflect(const FlagType& f) {
return f.Reflect();
- }
-};
-
+ }
+};
+
///////////////////////////////////////////////////////////////////////////////
// Implementation of Flag value specific operations routine.
-template <typename T>
+template <typename T>
void* FlagOps(FlagOp op, const void* v1, void* v2, void* v3) {
switch (op) {
case FlagOp::kAlloc: {
@@ -760,39 +760,39 @@ void* FlagOps(FlagOp op, const void* v1, void* v2, void* v3) {
(sizeof(FlagImpl) + round_to - 1) / round_to * round_to;
return reinterpret_cast<void*>(offset);
}
- }
+ }
return nullptr;
-}
-
+}
+
///////////////////////////////////////////////////////////////////////////////
-// This class facilitates Flag object registration and tail expression-based
-// flag definition, for example:
-// ABSL_FLAG(int, foo, 42, "Foo help").OnUpdate(NotifyFooWatcher);
+// This class facilitates Flag object registration and tail expression-based
+// flag definition, for example:
+// ABSL_FLAG(int, foo, 42, "Foo help").OnUpdate(NotifyFooWatcher);
struct FlagRegistrarEmpty {};
-template <typename T, bool do_register>
-class FlagRegistrar {
- public:
+template <typename T, bool do_register>
+class FlagRegistrar {
+ public:
explicit FlagRegistrar(Flag<T>& flag, const char* filename) : flag_(flag) {
if (do_register)
flags_internal::RegisterCommandLineFlag(flag_.impl_, filename);
- }
-
+ }
+
FlagRegistrar OnUpdate(FlagCallbackFunc cb) && {
flag_.impl_.SetCallback(cb);
- return *this;
- }
-
+ return *this;
+ }
+
// Make the registrar "die" gracefully as an empty struct on a line where
// registration happens. Registrar objects are intended to live only as
// temporary.
operator FlagRegistrarEmpty() const { return {}; } // NOLINT
-
- private:
+
+ private:
Flag<T>& flag_; // Flag being registered (not owned).
-};
-
-} // namespace flags_internal
+};
+
+} // namespace flags_internal
ABSL_NAMESPACE_END
-} // namespace absl
-
-#endif // ABSL_FLAGS_INTERNAL_FLAG_H_
+} // namespace absl
+
+#endif // ABSL_FLAGS_INTERNAL_FLAG_H_