Ring Daemon 16.0.0
Loading...
Searching...
No Matches
libdevcore/Common.h
Go to the documentation of this file.
1/*
2 This file is part of cpp-ethereum.
3
4 cpp-ethereum is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 cpp-ethereum is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16*/
24#pragma once
25
26// way too many unsigned to size_t warnings in 32 bit build
27#ifdef _M_IX86
28#pragma warning(disable : 4244)
29#endif
30
31#if _MSC_VER && _MSC_VER < 1900
32#define _ALLOW_KEYWORD_MACROS
33#define noexcept throw()
34#endif
35
36#ifdef __INTEL_COMPILER
37#pragma warning(disable : 3682) // call through incomplete class
38#endif
39
40#include <map>
41#include <unordered_map>
42#include <vector>
43#include <set>
44#include <unordered_set>
45#include <functional>
46#include <string>
47#include <chrono>
48#include "vector_ref.h"
49
50// Quote a given token stream to turn it into a string.
51#define DEV_QUOTED_HELPER(s) #s
52#define DEV_QUOTED(s) DEV_QUOTED_HELPER(s)
53
54#define DEV_IGNORE_EXCEPTIONS(X) \
55 try { \
56 X; \
57 } catch (...) { \
58 }
59
60#define DEV_IF_THROWS(X) \
61 try { \
62 X; \
63 } catch (...)
64
65namespace dev {
66
67extern char const* Version;
68
69extern std::string const EmptyString;
70
71// Binary data types.
72using bytes = std::vector<uint8_t>;
75
76// Map types.
77using StringMap = std::map<std::string, std::string>;
78using BytesMap = std::map<bytes, bytes>;
79using HexMap = std::map<bytes, bytes>;
80
81// Hash types.
82using StringHashMap = std::unordered_map<std::string, std::string>;
83
84// String types.
85using strings = std::vector<std::string>;
86
87// Fixed-length string types.
88using string32 = std::array<char, 32>;
89
91template<class N>
92inline N
93diff(N const& _a, N const& _b)
94{
95 return std::max(_a, _b) - std::min(_a, _b);
96}
97
100{
101public:
102 ScopeGuard(std::function<void(void)> _f)
103 : m_f(_f)
104 {}
105 ~ScopeGuard() { m_f(); }
106
107private:
108 std::function<void(void)> m_f;
109};
110
111#ifdef _MSC_VER
112// TODO.
113#define DEV_UNUSED
114#else
115#define DEV_UNUSED __attribute__((unused))
116#endif
117
118enum class WithExisting : int { Trust = 0, Verify, Rescue, Kill };
119
120} // namespace dev
RAII utility class whose destructor calls a given function.
ScopeGuard(std::function< void(void)> _f)
A modifiable reference to an existing object or vector in memory.
Definition vector_ref.h:21
Definition Address.h:25
char const * Version
std::array< char, 32 > string32
std::vector< std::string > strings
std::map< bytes, bytes > BytesMap
std::map< std::string, std::string > StringMap
std::vector< uint8_t > bytes
std::string const EmptyString
std::map< bytes, bytes > HexMap
std::unordered_map< std::string, std::string > StringHashMap
N diff(N const &_a, N const &_b)