diff options
author | Abseil Team <absl-team@google.com> | 2020-06-03 14:03:13 -0700 |
---|---|---|
committer | Gennadiy Rozental <rogeeff@google.com> | 2020-06-03 18:19:47 -0400 |
commit | 1d31b5c365e975d3c8a8f90492c3d9de35ef024f (patch) | |
tree | fbc8093e8aad757b8790fb2688c0e4694e082fa4 /absl/random/internal/mocking_bit_gen_base.h | |
parent | da3a87690c56f965705b6a233d25ba5a3294067c (diff) |
Export of internal Abseil changes
--
9e8b4a286d70df9487bff080816bd07ae38af5f8 by Evan Brown <ezb@google.com>:
Add btree_node::transfer_n/transfer_n_backward and replace usage of uninitialized_move_n and value_destroy_n.
PiperOrigin-RevId: 314600027
--
6c452aa1ee7e46ab941ba7d1fa636da8ea3d7370 by Laramie Leavitt <lar@google.com>:
Remove the MockingBitGenBase base class in favor of type-erasure in BitGenRef.
In Abseil random, mocking was split across two different classes,
MockingBitGenBase and MockingBitGen. This split existed because Google Mock is a
test-only library that we don't link into production, so MockingBitGenBase
provided a low-overhead scaffold used to lookup mocks when in test code, but
which is unused in production code.
That has been replaced by type-erasure which looks for a method named
CallImpl with the correct signature.
Weaken the coupling between MockingBitGen, DistributionCaller, and MockOverloadSet.
Rename CallImpl to InvokeMock()
Previously, the implementation of DistributionCaller was also split across different files using explicit instantiation of the DistributionCaller struct and some details in the Mocking classes. Now Distribution caller uses the presence of the InvokeMock() method to choose whether to use the mockable call path or the default call path.
PiperOrigin-RevId: 314584095
--
07853c47dc98698d67d65a3b9b662a65ab9def0a by Abseil Team <absl-team@google.com>:
Add PC / backtrace / symbolization support for Apple platforms.
Full backtrace support requires iOS 9+
PiperOrigin-RevId: 314415072
--
43889f17a132b31f6558c6482721cbbc776128fd by Gennadiy Rozental <rogeeff@google.com>:
Consolidate all reflection interface in the new module 'reflection' and expose interface to locate reflection handle by name.
PiperOrigin-RevId: 314390358
GitOrigin-RevId: 9e8b4a286d70df9487bff080816bd07ae38af5f8
Change-Id: I8e0910437740cf9ea9da5000adddfcef127e1158
Diffstat (limited to 'absl/random/internal/mocking_bit_gen_base.h')
-rw-r--r-- | absl/random/internal/mocking_bit_gen_base.h | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/absl/random/internal/mocking_bit_gen_base.h b/absl/random/internal/mocking_bit_gen_base.h deleted file mode 100644 index 23ecaf6c..00000000 --- a/absl/random/internal/mocking_bit_gen_base.h +++ /dev/null @@ -1,85 +0,0 @@ -// -// Copyright 2018 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_RANDOM_INTERNAL_MOCKING_BIT_GEN_BASE_H_ -#define ABSL_RANDOM_INTERNAL_MOCKING_BIT_GEN_BASE_H_ - -#include <string> -#include <typeinfo> - -#include "absl/random/random.h" -#include "absl/strings/str_cat.h" - -namespace absl { -ABSL_NAMESPACE_BEGIN -namespace random_internal { - -class MockingBitGenBase { - template <typename> - friend struct DistributionCaller; - using generator_type = absl::BitGen; - - public: - // URBG interface - using result_type = generator_type::result_type; - static constexpr result_type(min)() { return (generator_type::min)(); } - static constexpr result_type(max)() { return (generator_type::max)(); } - result_type operator()() { return gen_(); } - - virtual ~MockingBitGenBase() = default; - - protected: - // CallImpl is the type-erased virtual dispatch. - // The type of dist is always distribution<T>, - // The type of result is always distribution<T>::result_type. - virtual bool CallImpl(const std::type_info& distr_type, void* dist_args, - void* result) = 0; - - template <typename DistrT, typename ArgTupleT> - static const std::type_info& GetTypeId() { - return typeid(std::pair<absl::decay_t<DistrT>, absl::decay_t<ArgTupleT>>); - } - - // Call the generating distribution function. - // Invoked by DistributionCaller<>::Call<DistT>. - // DistT is the distribution type. - template <typename DistrT, typename... Args> - typename DistrT::result_type Call(Args&&... args) { - using distr_result_type = typename DistrT::result_type; - using ArgTupleT = std::tuple<absl::decay_t<Args>...>; - - ArgTupleT arg_tuple(std::forward<Args>(args)...); - auto dist = absl::make_from_tuple<DistrT>(arg_tuple); - - distr_result_type result{}; - bool found_match = - CallImpl(GetTypeId<DistrT, ArgTupleT>(), &arg_tuple, &result); - - if (!found_match) { - result = dist(gen_); - } - - return result; - } - - private: - generator_type gen_; -}; // namespace random_internal - -} // namespace random_internal -ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_RANDOM_INTERNAL_MOCKING_BIT_GEN_BASE_H_ |