Fabcoin Core  0.16.2
P2P Digital Currency
Precompiled.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 */
22 #pragma once
23 
24 #include <unordered_map>
25 #include <functional>
26 #include <libdevcore/CommonData.h>
27 #include <libdevcore/Exceptions.h>
28 
29 namespace dev
30 {
31 namespace eth
32 {
33 
34 using PrecompiledExecutor = std::function<std::pair<bool, bytes>(bytesConstRef _in)>;
35 
36 DEV_SIMPLE_EXCEPTION(ExecutorNotFound);
37 
39 {
40 public:
42  static PrecompiledExecutor const& executor(std::string const& _name);
43 
45  static PrecompiledExecutor registerPrecompiled(std::string const& _name, PrecompiledExecutor const& _exec) { return (get()->m_execs[_name] = _exec); }
47  static void unregisterPrecompiled(std::string const& _name) { get()->m_execs.erase(_name); }
48 
49 private:
50  static PrecompiledRegistrar* get() { if (!s_this) s_this = new PrecompiledRegistrar; return s_this; }
51 
52  std::unordered_map<std::string, PrecompiledExecutor> m_execs;
54 };
55 
56 // TODO: unregister on unload with a static object.
57 #define ETH_REGISTER_PRECOMPILED(Name) static std::pair<bool, bytes> __eth_registerPrecompiledFunction ## Name(bytesConstRef _in); static PrecompiledExecutor __eth_registerPrecompiledFactory ## Name = ::dev::eth::PrecompiledRegistrar::registerPrecompiled(#Name, &__eth_registerPrecompiledFunction ## Name); static std::pair<bool, bytes> __eth_registerPrecompiledFunction ## Name
58 
59 }
60 }
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
std::unordered_map< std::string, PrecompiledExecutor > m_execs
Definition: Precompiled.h:52
static PrecompiledExecutor registerPrecompiled(std::string const &_name, PrecompiledExecutor const &_exec)
Register an executor. In general just use ETH_REGISTER_PRECOMPILED.
Definition: Precompiled.h:45
static PrecompiledExecutor const & executor(std::string const &_name)
Get the executor object for _name function or.
Definition: Precompiled.cpp:34
std::function< std::pair< bool, bytes >(bytesConstRef _in)> PrecompiledExecutor
Definition: Precompiled.h:34
static void unregisterPrecompiled(std::string const &_name)
Unregister an executor. Shouldn&#39;t generally be necessary.
Definition: Precompiled.h:47
static PrecompiledRegistrar * s_this
Definition: Precompiled.h:53
DEV_SIMPLE_EXCEPTION(InvalidSealEngine)