361cb8a9db
-- 4a21ad4ffa957d28b770de8717289fab7410f567 by Gennadiy Rozental <rogeeff@google.com>: Internal cleanup PiperOrigin-RevId: 252366381 -- b6b0f25439549c54f1537a16625be1fecd3c7d8c by Xiaoyi Zhang <zhangxy@google.com>: Fix C4245 compiler warning of visual studio. This allows using abseil headers in code requiring strict warning settings. This is an import of https://github.com/abseil/abseil-cpp/pull/321. PiperOrigin-RevId: 252101240 -- 0543b7861b658a5a665298e1d868e29968ff7b27 by CJ Johnson <johnsoncj@google.com>: Adds new benchmarks for the constructors of InlinedVector PiperOrigin-RevId: 251905349 -- c65a08507917e9f8f6450b8beb235fe1426d7954 by CJ Johnson <johnsoncj@google.com>: Updates the InlinedVector BatchedBenchmark abstractions to 1) provide the index of the instance back to the prepare and test functions so that callers may perform extra work on local state with a unique per-instance ID and 2) reduce the number of manually written calls to BENCHMARK_TEMPLATE. PiperOrigin-RevId: 251895546 -- 99a1ae2d786b80096172f6e018711e15c0c750b9 by Samuel Benzaquen <sbenza@google.com>: Fix ambiguous construction problem in absl::variant<> to make in line with std::variant. ImaginaryFun is hiding duplicate objects instead of causing ambiguity. Add a second unique argument to make sure all overloads exist in the final overload set. PiperOrigin-RevId: 251860694 -- b54d0a12673be6ebb6e77e24a556ce9b758b3a7e by Abseil Team <absl-team@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 251739183 -- f51b115e0dc3fc9a9c9c20b33a1f27027a700d48 by Abseil Team <absl-team@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 251686812 -- 30e868049282dc6a6fc77d923ca7d2a5d35a1658 by Xiaoyi Zhang <zhangxy@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 251652119 GitOrigin-RevId: 4a21ad4ffa957d28b770de8717289fab7410f567 Change-Id: I7171cb613793fa90e0eb0143b65ec8264a2a84db
103 lines
3.5 KiB
C++
103 lines
3.5 KiB
C++
//
|
|
// 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 "absl/flags/internal/commandlineflag.h"
|
|
#include "absl/flags/internal/registry.h"
|
|
|
|
namespace absl {
|
|
namespace flags_internal {
|
|
|
|
// This is "unspecified" implementation of absl::Flag<T> type.
|
|
template <typename T>
|
|
class Flag {
|
|
public:
|
|
constexpr Flag(const char* name, const flags_internal::HelpGenFunc help_gen,
|
|
const char* filename,
|
|
const flags_internal::FlagMarshallingOpFn marshalling_op,
|
|
const flags_internal::InitialValGenFunc initial_value_gen)
|
|
: internal(name, flags_internal::HelpText::FromFunctionPointer(help_gen),
|
|
filename, &flags_internal::FlagOps<T>, marshalling_op,
|
|
initial_value_gen,
|
|
/*retired_arg=*/false, /*def_arg=*/nullptr,
|
|
/*cur_arg=*/nullptr) {}
|
|
|
|
// Not copyable/assignable.
|
|
Flag(const Flag<T>&) = delete;
|
|
Flag<T>& operator=(const Flag<T>&) = delete;
|
|
|
|
absl::string_view Name() const { return internal.Name(); }
|
|
std::string Help() const { return internal.Help(); }
|
|
std::string Filename() const { return internal.Filename(); }
|
|
|
|
absl::flags_internal::CommandLineFlag internal;
|
|
|
|
void SetCallback(const flags_internal::FlagCallback mutation_callback) {
|
|
internal.SetCallback(mutation_callback);
|
|
}
|
|
|
|
private:
|
|
// TODO(rogeeff): add these validations once UnparseFlag invocation is fixed
|
|
// for built-in types and when we cleanup existing code from operating on
|
|
// forward declared types.
|
|
// auto IsCopyConstructible(const T& v) -> decltype(T(v));
|
|
// auto HasAbslParseFlag(absl::string_view in, T* dst, std::string* err)
|
|
// -> decltype(AbslParseFlag(in, dst, err));
|
|
// auto HasAbslUnparseFlag(const T& v) -> decltype(AbslUnparseFlag(v));
|
|
};
|
|
|
|
// This class facilitates Flag object registration and tail expression-based
|
|
// flag definition, for example:
|
|
// ABSL_FLAG(int, foo, 42, "Foo help").OnUpdate(NotifyFooWatcher);
|
|
template <typename T, bool do_register>
|
|
class FlagRegistrar {
|
|
public:
|
|
explicit FlagRegistrar(Flag<T>* flag) : flag_(flag) {
|
|
if (do_register) flags_internal::RegisterCommandLineFlag(&flag_->internal);
|
|
}
|
|
|
|
FlagRegistrar& OnUpdate(flags_internal::FlagCallback cb) && {
|
|
flag_->SetCallback(cb);
|
|
return *this;
|
|
}
|
|
|
|
// Make the registrar "die" gracefully as a bool on a line where registration
|
|
// happens. Registrar objects are intended to live only as temporary.
|
|
operator bool() const { return true; } // NOLINT
|
|
|
|
private:
|
|
Flag<T>* flag_; // Flag being registered (not owned).
|
|
};
|
|
|
|
// This struct and corresponding overload to MakeDefaultValue are used to
|
|
// facilitate usage of {} as default value in ABSL_FLAG macro.
|
|
struct EmptyBraces {};
|
|
|
|
template <typename T>
|
|
T* MakeFromDefaultValue(T t) {
|
|
return new T(std::move(t));
|
|
}
|
|
|
|
template <typename T>
|
|
T* MakeFromDefaultValue(EmptyBraces) {
|
|
return new T;
|
|
}
|
|
|
|
} // namespace flags_internal
|
|
} // namespace absl
|
|
|
|
#endif // ABSL_FLAGS_INTERNAL_FLAG_H_
|