mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
refactor: Split util::AnyPtr into its own file
This commit is contained in:
parent
44de325d95
commit
7eee356c0a
7 changed files with 31 additions and 21 deletions
|
@ -279,6 +279,7 @@ BITCOIN_CORE_H = \
|
|||
txorphanage.h \
|
||||
txrequest.h \
|
||||
undo.h \
|
||||
util/any.h \
|
||||
util/asmap.h \
|
||||
util/batchpriority.h \
|
||||
util/bip32.h \
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
#include <streams.h>
|
||||
#include <sync.h>
|
||||
#include <txmempool.h>
|
||||
#include <util/any.h>
|
||||
#include <util/check.h>
|
||||
#include <util/system.h>
|
||||
#include <validation.h>
|
||||
#include <version.h>
|
||||
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
#include <rpc/util.h>
|
||||
#include <scheduler.h>
|
||||
#include <univalue.h>
|
||||
#include <util/any.h>
|
||||
#include <util/check.h>
|
||||
#include <util/syscall_sandbox.h>
|
||||
#include <util/system.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#ifdef HAVE_MALLOC_INFO
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <rpc/protocol.h>
|
||||
#include <rpc/request.h>
|
||||
#include <txmempool.h>
|
||||
#include <util/system.h>
|
||||
#include <util/any.h>
|
||||
#include <validation.h>
|
||||
|
||||
#include <any>
|
||||
|
|
26
src/util/any.h
Normal file
26
src/util/any.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
// Copyright (c) 2023 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_UTIL_ANY_H
|
||||
#define BITCOIN_UTIL_ANY_H
|
||||
|
||||
#include <any>
|
||||
|
||||
namespace util {
|
||||
|
||||
/**
|
||||
* Helper function to access the contained object of a std::any instance.
|
||||
* Returns a pointer to the object if passed instance has a value and the type
|
||||
* matches, nullptr otherwise.
|
||||
*/
|
||||
template<typename T>
|
||||
T* AnyPtr(const std::any& any) noexcept
|
||||
{
|
||||
T* const* ptr = std::any_cast<T*>(&any);
|
||||
return ptr ? *ptr : nullptr;
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
|
||||
#endif // BITCOIN_UTIL_ANY_H
|
|
@ -13,7 +13,6 @@
|
|||
#include <compat/assumptions.h>
|
||||
#include <compat/compat.h>
|
||||
|
||||
#include <any>
|
||||
#include <set>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
@ -36,20 +35,4 @@ void runCommand(const std::string& strCommand);
|
|||
*/
|
||||
int GetNumCores();
|
||||
|
||||
namespace util {
|
||||
|
||||
/**
|
||||
* Helper function to access the contained object of a std::any instance.
|
||||
* Returns a pointer to the object if passed instance has a value and the type
|
||||
* matches, nullptr otherwise.
|
||||
*/
|
||||
template<typename T>
|
||||
T* AnyPtr(const std::any& any) noexcept
|
||||
{
|
||||
T* const* ptr = std::any_cast<T*>(&any);
|
||||
return ptr ? *ptr : nullptr;
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
|
||||
#endif // BITCOIN_UTIL_SYSTEM_H
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <common/url.h>
|
||||
#include <rpc/util.h>
|
||||
#include <util/system.h>
|
||||
#include <util/any.h>
|
||||
#include <util/translation.h>
|
||||
#include <wallet/context.h>
|
||||
#include <wallet/wallet.h>
|
||||
|
|
Loading…
Add table
Reference in a new issue