CDT  v4.2.0
инструменты разработчика
check.hpp
См. документацию.
1
5#pragma once
6
7#include <string>
8#include <string_view>
9
10namespace eosio {
11
12 namespace internal_use_do_not_use {
13 extern "C" {
14 __attribute__((eosio_wasm_import))
15 void eosio_assert( uint32_t test, const char* msg );
16
17 __attribute__((eosio_wasm_import))
18 void eosio_assert_message( uint32_t test, const char* msg, uint32_t msg_len );
19
20 __attribute__((eosio_wasm_import))
21 void eosio_assert_code( uint32_t test, uint64_t code );
22 }
23 }
24
42 inline void check(bool pred, std::string_view msg) {
43 if (!pred)
44 internal_use_do_not_use::eosio_assert_message(false, msg.data(), msg.size());
45 }
46
57 inline void check(bool pred, const char* msg) {
58 if (!pred) {
59 internal_use_do_not_use::eosio_assert(false, msg);
60 }
61 }
62
73 inline void check(bool pred, const std::string& msg) {
74 if (!pred) {
75 internal_use_do_not_use::eosio_assert_message(false, msg.data(), msg.size());
76 }
77 }
78
89 inline void check(bool pred, std::string&& msg) {
90 if (!pred) {
91 internal_use_do_not_use::eosio_assert_message(false, msg.data(), msg.size());
92 }
93 }
94
95
107 inline void check(bool pred, const char* msg, size_t n) {
108 if (!pred) {
109 internal_use_do_not_use::eosio_assert_message(false, msg, n);
110 }
111 }
112
124 inline void check(bool pred, const std::string& msg, size_t n) {
125 if (!pred) {
126 internal_use_do_not_use::eosio_assert_message(false, msg.data(), n);
127 }
128 }
129
140 inline void check(bool pred, uint64_t code) {
141 if (!pred) {
142 internal_use_do_not_use::eosio_assert_code(false, code);
143 }
144 }
145} // namespace eosio