Move C++ helpers into evmc/helpers.hpp

This commit is contained in:
Alex Beregszaszi 2018-09-06 13:27:14 +01:00 committed by Paweł Bylica
parent 7cfc2bf39e
commit 3dfa18a393
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
3 changed files with 46 additions and 19 deletions

View File

@ -100,7 +100,7 @@ WARN_LOGFILE =
# Configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = \
include/evmc/evmc.h include/evmc/loader.h include/evmc/helpers.h include/evmc/utils.h include/evmc/instructions.h \
include/evmc/evmc.h include/evmc/helpers.h include/evmc/helpers.hpp include/evmc/loader.h include/evmc/utils.h include/evmc/instructions.h \
docs/
INPUT_ENCODING = UTF-8
FILE_PATTERNS =

View File

@ -7,28 +7,11 @@
#include "example_host.h"
#include <evmc/helpers.hpp>
#include <evmc/helpers.h>
#include <cstring>
#include <map>
/// The comparator for std::map<evmc_address, ...>.
bool operator<(const evmc_address& a, const evmc_address& b)
{
return std::memcmp(a.bytes, b.bytes, sizeof(a)) < 0;
}
/// The comparator for std::map<evmc_bytes32, ...>.
bool operator<(const evmc_bytes32& a, const evmc_bytes32& b)
{
return std::memcmp(a.bytes, b.bytes, sizeof(a)) < 0;
}
bool operator==(const evmc_bytes32& a, const evmc_bytes32& b)
{
return std::memcmp(a.bytes, b.bytes, sizeof(a)) == 0;
}
struct account
{
evmc_uint256be balance = {};

44
include/evmc/helpers.hpp Normal file
View File

@ -0,0 +1,44 @@
/* EVMC: Ethereum Client-VM Connector API.
* Copyright 2018 The EVMC Authors.
* Licensed under the Apache License, Version 2.0. See the LICENSE file.
*/
/**
* EVMC C++ helpers
*
* A collection of helpers (overloaded operators) for using EVMC effectively in C++.
*
* @defgroup cpphelpers EVMC C++ helpers
* @{
*/
#pragma once
#include <evmc/evmc.h>
#include <cstring>
/// The comparator for std::map<evmc_address, ...>.
bool operator<(const evmc_address& a, const evmc_address& b)
{
return std::memcmp(a.bytes, b.bytes, sizeof(a)) < 0;
}
/// The comparator for std::map<evmc_bytes32, ...>.
bool operator<(const evmc_bytes32& a, const evmc_bytes32& b)
{
return std::memcmp(a.bytes, b.bytes, sizeof(a)) < 0;
}
/// The comparator for equality.
bool operator==(const evmc_address& a, const evmc_address& b)
{
return std::memcmp(a.bytes, b.bytes, sizeof(a)) == 0;
}
/// The comparator for equality.
bool operator==(const evmc_bytes32& a, const evmc_bytes32& b)
{
return std::memcmp(a.bytes, b.bytes, sizeof(a)) == 0;
}
/** @} */