Esempio n. 1
0
void set_configuration_map_init_translators(
    ib_cfgmap_init_t& init,
    ib_mpool_t* mpool,
    configuration_map_init_getter_translator_t getter_translator,
    configuration_map_init_setter_translator_t setter_translator,
    bool data_is_handle
)
{
    if (data_is_handle) {
        init.fn_get = Hooks::cfgmap_handle_get;
        init.fn_set = Hooks::cfgmap_handle_set;
    }
    else {
        init.fn_get = Hooks::cfgmap_get;
        init.fn_set = Hooks::cfgmap_set;
    }
    init.cbdata_get = value_to_data(
        getter_translator,
        mpool
    );
    init.cbdata_set = value_to_data(
        setter_translator,
        mpool
    );
}
Esempio n. 2
0
Field Field::create_dynamic_byte_string(
    MemoryPool        pool,
    const char*       name,
    size_t            name_length,
    byte_string_get_t get,
    byte_string_set_t set
)
{
    return Internal::create_dynamic_field(
        pool,
        name, name_length,
        Field::BYTE_STRING,
        value_to_data(get, pool.ib()),
        value_to_data(set, pool.ib())
    );
}
Esempio n. 3
0
Field Field::create_dynamic_float(
    MemoryPool  pool,
    const char* name,
    size_t      name_length,
    float_get_t get,
    float_set_t set
)
{
    return Internal::create_dynamic_field(
        pool,
        name, name_length,
        Field::FLOAT,
        value_to_data(get, pool.ib()),
        value_to_data(set, pool.ib())
    );
}
Esempio n. 4
0
Field Field::create_dynamic_number(
    MemoryPool   pool,
    const char*  name,
    size_t       name_length,
    number_get_t get,
    number_set_t set
)
{
    return Internal::create_dynamic_field(
        pool,
        name, name_length,
        Field::NUMBER,
        value_to_data(get, pool.ib()),
        value_to_data(set, pool.ib())
    );
}
Esempio n. 5
0
Field Field::create_dynamic_time(
    MemoryPool   pool,
    const char*  name,
    size_t       name_length,
    time_get_t   get,
    time_set_t   set
)
{
    return Internal::create_dynamic_field(
        pool,
        name, name_length,
        Field::TIME,
        value_to_data(get, pool.ib()),
        value_to_data(set, pool.ib())
    );
}
Esempio n. 6
0
void MemoryPool::register_cleanup(cleanup_t f) const
{
    // We can't use this as the memory pool for value_to_data because then
    // the callback would be deleted before it is called.  The callback
    // itself will free it's own data.
    ib_status_t rc = ib_mpool_cleanup_register(
        ib(),
        Hooks::ibpp_memory_pool_cleanup,
        value_to_data(
            f,
            NULL // See above
        )
    );
    throw_if_error(rc);
}
Esempio n. 7
0
ConstTransformation ConstTransformation::create(
    MemoryPool       memory_pool,
    const char*      name,
    bool             handle_list,
    transformation_t transformation
)
{
    const ib_tfn_t* tfn;
    throw_if_error(ib_tfn_create(
        &tfn,
        memory_pool.ib(),
        name,
        handle_list,
        ibpp_transformation_translator,
        value_to_data(transformation, memory_pool.ib())
    ));

    return ConstTransformation(tfn);
}
Esempio n. 8
0
    Value eval_map(
        MemoryManager                  mm,
        const Functional::value_vec_t& secondary_args,
        boost::any&                    map_state,
        Value                          subvalue
    ) const
    {
        /* If the subvalue we've been given is NULL, likewise return a NULL
         * subvalue. We can't change anything. */
        if (! subvalue) {
            return Value();
        }

        if (subvalue.type() != Value::STRING) {
            return Value();
        }

        ConstByteString text = subvalue.as_string();
        boost::shared_ptr<vector<char> > result(new vector<char>());
        // Ensure that result.data() is non-null, even if we never insert
        // anything.
        result->reserve(1);

        // value_to_data() ensures that a copy is associated with the memory
        // pool and will be deleted when the memory pool goes away.
        value_to_data(result, mm.ib());

        boost::regex_replace(
            back_inserter(*result),
            text.const_data(), text.const_data() + text.length(),
            m_expression,
            m_replacement
        );

        return Value::create_string(
            mm,
            subvalue.name(), subvalue.name_length(),
            ByteString::create_alias(
                mm,
                result->data(), result->size()
            )
        );
    }