Skip to content

Commit 7eee356

Browse files
committed
refactor: Split util::AnyPtr into its own file
1 parent 44de325 commit 7eee356

File tree

7 files changed

+31
-21
lines changed

7 files changed

+31
-21
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ BITCOIN_CORE_H = \
279279
txorphanage.h \
280280
txrequest.h \
281281
undo.h \
282+
util/any.h \
282283
util/asmap.h \
283284
util/batchpriority.h \
284285
util/bip32.h \

src/rest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#include <streams.h>
2525
#include <sync.h>
2626
#include <txmempool.h>
27+
#include <util/any.h>
2728
#include <util/check.h>
28-
#include <util/system.h>
2929
#include <validation.h>
3030
#include <version.h>
3131

src/rpc/node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
#include <rpc/util.h>
2020
#include <scheduler.h>
2121
#include <univalue.h>
22+
#include <util/any.h>
2223
#include <util/check.h>
2324
#include <util/syscall_sandbox.h>
24-
#include <util/system.h>
2525

2626
#include <stdint.h>
2727
#ifdef HAVE_MALLOC_INFO

src/rpc/server_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <rpc/protocol.h>
1212
#include <rpc/request.h>
1313
#include <txmempool.h>
14-
#include <util/system.h>
14+
#include <util/any.h>
1515
#include <validation.h>
1616

1717
#include <any>

src/util/any.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2023 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_UTIL_ANY_H
6+
#define BITCOIN_UTIL_ANY_H
7+
8+
#include <any>
9+
10+
namespace util {
11+
12+
/**
13+
* Helper function to access the contained object of a std::any instance.
14+
* Returns a pointer to the object if passed instance has a value and the type
15+
* matches, nullptr otherwise.
16+
*/
17+
template<typename T>
18+
T* AnyPtr(const std::any& any) noexcept
19+
{
20+
T* const* ptr = std::any_cast<T*>(&any);
21+
return ptr ? *ptr : nullptr;
22+
}
23+
24+
} // namespace util
25+
26+
#endif // BITCOIN_UTIL_ANY_H

src/util/system.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <compat/assumptions.h>
1414
#include <compat/compat.h>
1515

16-
#include <any>
1716
#include <set>
1817
#include <stdint.h>
1918
#include <string>
@@ -36,20 +35,4 @@ void runCommand(const std::string& strCommand);
3635
*/
3736
int GetNumCores();
3837

39-
namespace util {
40-
41-
/**
42-
* Helper function to access the contained object of a std::any instance.
43-
* Returns a pointer to the object if passed instance has a value and the type
44-
* matches, nullptr otherwise.
45-
*/
46-
template<typename T>
47-
T* AnyPtr(const std::any& any) noexcept
48-
{
49-
T* const* ptr = std::any_cast<T*>(&any);
50-
return ptr ? *ptr : nullptr;
51-
}
52-
53-
} // namespace util
54-
5538
#endif // BITCOIN_UTIL_SYSTEM_H

src/wallet/rpc/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <common/url.h>
88
#include <rpc/util.h>
9-
#include <util/system.h>
9+
#include <util/any.h>
1010
#include <util/translation.h>
1111
#include <wallet/context.h>
1212
#include <wallet/wallet.h>

0 commit comments

Comments
 (0)