HooksRegistrar& HooksRegistrar::transaction_data( Engine::state_event_e event, transaction_data_t f ) { if (f.empty()) { BOOST_THROW_EXCEPTION(einval() << errinfo_what( "Empty functional passed to hook registrarion." )); } throw_if_error( ib_hook_txdata_register( m_engine.ib(), static_cast<ib_state_event_type_t>(event), &Internal::Hooks::transaction_data, value_to_data<transaction_data_t>( f, m_engine.main_memory_pool().ib() ) ) ); return *this; }
void check_type(Field::type_e expected, Field::type_e actual) { if (expected != actual) { BOOST_THROW_EXCEPTION( einval() << errinfo_what( "Expected field type " + type_as_s(expected) + " but is field type " + type_as_s(actual) ) ); } }
/** * Back element of list. * * @return Back element of list. * @throw enoent if list is empty. **/ T back() const { if (empty()) { BOOST_THROW_EXCEPTION( enoent() << errinfo_what( "Trying to fetch back of empty list." ) ); } return *rbegin(); }
void* MemoryPool::calloc(size_t count, size_t size) const { void* memory = ib_mpool_calloc(ib(), count, size); if (! memory) { BOOST_THROW_EXCEPTION( ealloc() << errinfo_what( "ib_mpool_calloc() returned NULL" ) ); } return memory; }
MemoryPool MemoryPool::create( const char* name, MemoryPool parent ) { if (! parent) { BOOST_THROW_EXCEPTION( einval() << errinfo_what( "Singular parent provided to memory pool." ) ); } return Internal::create_memory_pool(name, parent.ib()); }
std::string ConstField::to_s() const { switch (type()) { case TIME: return boost::lexical_cast<std::string>(value_as_time()); case NUMBER: return boost::lexical_cast<std::string>(value_as_number()); case FLOAT: return boost::lexical_cast<std::string>(value_as_float()); case NULL_STRING: return std::string(value_as_null_string()); case BYTE_STRING: return value_as_byte_string().to_s(); default: BOOST_THROW_EXCEPTION( einval() << errinfo_what( "ConstField::to_s() does not support field type: " + Internal::type_as_s(type()) ) ); } }
ib_status_t field_dynamic_set( ib_field_t* field, const void* arg, size_t arg_length, void* in_value, void* cbdata ) { const char* carg = reinterpret_cast<const char*>(arg); // No engine available. try { switch (field->type) { case IB_FTYPE_TIME: data_to_value<Field::time_set_t>(cbdata)( Field(field), carg, arg_length, *reinterpret_cast<const uint64_t*>(in_value) ); break; case IB_FTYPE_NUM: data_to_value<Field::number_set_t>(cbdata)( Field(field), carg, arg_length, *reinterpret_cast<const int64_t*>(in_value) ); break; case IB_FTYPE_FLOAT: data_to_value<Field::float_set_t>(cbdata)( Field(field), carg, arg_length, *reinterpret_cast<const long double*>(in_value) ); break; case IB_FTYPE_NULSTR: data_to_value<Field::null_string_set_t>(cbdata)( Field(field), carg, arg_length, reinterpret_cast<const char*>(in_value) ); break; case IB_FTYPE_BYTESTR: { // Const cast, but then immeidately store as const. const ConstByteString value( reinterpret_cast<const ib_bytestr_t*>(in_value) ); data_to_value<Field::byte_string_set_t>(cbdata)( Field(field), carg, arg_length, value ); break; } case IB_FTYPE_LIST: { const ib_list_t* value = reinterpret_cast<const ib_list_t*>(in_value); data_to_value< Internal::dynamic_list_setter_translator_t >(cbdata)( Field(field), carg, arg_length, value ); break; } default: BOOST_THROW_EXCEPTION( einval() << errinfo_what( "Unsupported field type: " + type_as_s(field->type) ) ); } } catch (...) { return convert_exception(); } return IB_OK; }
ib_status_t field_dynamic_get( const ib_field_t* field, void* out_val, const void* arg, size_t arg_length, void* cbdata ) { // We will only pass this as as a const reference. ConstField fieldpp(field); const char* carg = reinterpret_cast<const char*>(arg); // No engine available. ib_status_t rc = IB_OK; try { switch (field->type) { case IB_FTYPE_TIME: { ib_time_t* n = reinterpret_cast<ib_time_t*>(out_val); *n = data_to_value<Field::time_get_t>(cbdata)( fieldpp, carg, arg_length ); return IB_OK; } case IB_FTYPE_NUM: { ib_num_t* n = reinterpret_cast<ib_num_t*>(out_val); *n = data_to_value<Field::number_get_t>(cbdata)( fieldpp, carg, arg_length ); return IB_OK; } case IB_FTYPE_FLOAT: { ib_float_t* u = reinterpret_cast<ib_float_t*>(out_val); *u = data_to_value< Field::float_get_t >(cbdata)( fieldpp, carg, arg_length ); return IB_OK; } case IB_FTYPE_NULSTR: { const char** ns = reinterpret_cast<const char**>(out_val); *ns = data_to_value< Field::null_string_get_t >(cbdata)( fieldpp, carg, arg_length ); return IB_OK; } case IB_FTYPE_BYTESTR: { const ib_bytestr_t** bs = reinterpret_cast<const ib_bytestr_t**>(out_val); *bs = data_to_value< Field::byte_string_get_t >(cbdata)( fieldpp, carg, arg_length ).ib(); return IB_OK; } case IB_FTYPE_LIST: { const ib_list_t** l = reinterpret_cast<const ib_list_t**>(out_val); *l = data_to_value< Internal::dynamic_list_getter_translator_t >(cbdata)( fieldpp, carg, arg_length ); return IB_OK; } default: BOOST_THROW_EXCEPTION( einval() << errinfo_what( "Unsupported field type: " + type_as_s(field->type) ) ); } } catch (...) { return convert_exception(); } // If we got here, it is in error. assert(rc != IB_OK); return rc; }