From 3dfa18a393a987353089859047d42ce51a4036c3 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 6 Sep 2018 13:27:14 +0100 Subject: [PATCH] Move C++ helpers into evmc/helpers.hpp --- Doxyfile | 2 +- examples/example_host.cpp | 19 +---------------- include/evmc/helpers.hpp | 44 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 include/evmc/helpers.hpp diff --git a/Doxyfile b/Doxyfile index d661526..c555c2f 100644 --- a/Doxyfile +++ b/Doxyfile @@ -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 = diff --git a/examples/example_host.cpp b/examples/example_host.cpp index f56bb54..7a8def4 100644 --- a/examples/example_host.cpp +++ b/examples/example_host.cpp @@ -7,28 +7,11 @@ #include "example_host.h" +#include #include -#include #include -/// The comparator for std::map. -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. -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 = {}; diff --git a/include/evmc/helpers.hpp b/include/evmc/helpers.hpp new file mode 100644 index 0000000..b35a080 --- /dev/null +++ b/include/evmc/helpers.hpp @@ -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 + +#include + +/// The comparator for std::map. +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. +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; +} + +/** @} */