예제 #1
0
파일: hash.hpp 프로젝트: PutiZL/ironbee
    /**
     * Create new hash with custom hash and equal functions.
     *
     * @param[in] memory_manager Memory manager to use.
     * @param[in] slots          Initial size of hash.
     * @param[in] hash           Function to use to hash keys.
     * @param[in] equal          Function to use to compare keys.
     * @return Empty Hash.
     **/
    static
    Hash create(
        MemoryManager memory_manager,
        size_t        slots,
        key_hash_t    hash,
        key_equal_t   equal
    )
    {
        std::pair<ib_hash_function_t, void*> hash_trampoline;
        std::pair<ib_hash_equal_t, void*> equal_trampoline;
        ib_hash_t* h;

        hash_trampoline = make_c_trampoline<
            uint32_t(const char*, size_t, uint32_t)
        >(hash);
        equal_trampoline = make_c_trampoline<
            int(const char*, size_t, const char*, size_t)
        >(equal);

        memory_manager.register_cleanup(
            boost::bind(delete_c_trampoline, hash_trampoline.second)
        );
        memory_manager.register_cleanup(
            boost::bind(delete_c_trampoline, equal_trampoline.second)
        );
        throw_if_error(
            ib_hash_create_ex(
                &h, memory_manager.ib(), slots,
                hash_trampoline.first, hash_trampoline.second,
                equal_trampoline.first, equal_trampoline.second
            )
        );

        return Hash(h);
    }
예제 #2
0
TEST(TestMemoryManager, Callback)
{
    bool called = false;

    MemoryPoolLite mpl = MemoryPoolLite::create();
    MemoryManager mm = mpl;

    mm.register_cleanup(
        boost::bind(test_callback, boost::ref(called))
    );

    mpl.destroy();

    ASSERT_TRUE(called);
}