8#include <capnp/schema.h>
13#include <kj/exception.h>
14#include <kj/string-tree.h>
31template <
typename... Types>
34 static constexpr size_t size =
sizeof...(Types);
45template <
template <
typename...>
class Class,
typename... Types,
typename... Args>
46Class<Types..., std::remove_reference_t<Args>...>
Make(Args&&...
args)
48 return Class<Types..., std::remove_reference_t<Args>...>{std::forward<Args>(
args)...};
56template <std::
size_t index,
typename List,
typename _First = TypeList<>,
bool done = index == 0>
60template <
typename _Second,
typename _First>
61struct Split<0, _Second, _First, true>
68template <std::size_t index,
typename Type,
typename... _Second,
typename... _First>
72 using First =
typename _Next::First;
73 using Second =
typename _Next::Second;
77template <
typename Callable>
78using ResultOf =
decltype(std::declval<Callable>()());
82using RemoveCvRef = std::remove_cv_t<std::remove_reference_t<T>>;
89template <
typename SfinaeExpr,
typename Result_>
96template <
typename SfinaeExpr,
typename Result =
void>
107template <
int priority>
128 const char* display_name = ::capnp::Schema::from<T>().getProto().getDisplayName().cStr();
129 const char* short_name = strchr(display_name,
':');
130 return short_name ? short_name + 1 : display_name;
134template <
typename Lock>
142template <
typename Lock,
typename Callback>
143void Unlock(Lock& lock, Callback&& callback)
155 template <
typename...
Params>
160 }
catch (
const kj::Exception& e) {
169template <
typename Callable>
179 mutable std::shared_ptr<DestructorCatcher<Callable>>
m_callable;
183template <
typename Callable>
186 return std::move(callable);
194std::string
LogEscape(
const kj::StringTree&
string);
197using FdToArgsFn = std::function<std::vector<std::string>(
int fd)>;
214inline char*
CharCast(
unsigned char* c) {
return (
char*)c; }
215inline const char*
CharCast(
const char* c) {
return c; }
216inline const char*
CharCast(
const unsigned char* c) {
return (
const char*)c; }
const CChainParams & Params()
Return the currently selected parameters.
#define T(expected, seed, data)
Functions to serialize / deserialize common bitcoin types.
void Unlock(Lock &lock, Callback &&callback)
int WaitProcess(int pid)
Wait for a process to exit and return its exit code.
const char * TypeName()
Return capnp type name with filename prefix removed.
std::string ThreadName(const char *exe_name)
Format current thread name as "{exe_name}-{$pid}/{thread_name}-{$tid}".
typename _Require< SfinaeExpr, Result >::Result Require
SFINAE helper, basically the same as to C++17's void_t, but allowing types other than void to be retu...
int SpawnProcess(int &pid, FdToArgsFn &&fd_to_args)
Spawn a new process that communicates with the current process over a socket pair.
AsyncCallable< std::remove_reference_t< Callable > > MakeAsyncCallable(Callable &&callable)
Construct AsyncCallable object.
Class< Types..., std::remove_reference_t< Args >... > Make(Args &&... args)
Construct a template class value by deducing template arguments from the types of constructor argumen...
std::decay_t< T > Decay
Type helper abbreviating std::decay.
std::remove_cv_t< std::remove_reference_t< T > > RemoveCvRef
Substitutue for std::remove_cvref_t.
std::string LogEscape(const kj::StringTree &string)
Escape binary string for use in log so it doesn't trigger unicode decode errors in python unit tests.
decltype(std::declval< Callable >()()) ResultOf
Type helper giving return type of a callable type.
std::function< std::vector< std::string >(int fd)> FdToArgsFn
Callback type used by SpawnProcess below.
void ExecProcess(const std::vector< std::string > &args)
Call execvp with vector args.
SFINAE helper, see using Require below.
Wrapper around callback function for compatibility with std::async.
AsyncCallable(AsyncCallable &&)=default
AsyncCallable(Callable &&callable)
~AsyncCallable() noexcept=default
AsyncCallable(const AsyncCallable &)=default
std::shared_ptr< DestructorCatcher< Callable > > m_callable
Needed for libc++/macOS compatibility.
DestructorCatcher(Params &&... params)
~DestructorCatcher() noexcept
Function parameter type for prioritizing overloaded function calls that would otherwise be ambiguous.
typename _Next::Second Second
typename _Next::First First
Type helper splitting a TypeList into two halves at position index.
Generic utility functions used by capnp code.
static constexpr size_t size
Analog to std::lock_guard that unlocks instead of locks.