Exemplo n.º 1
0
/* Replace the old value with the new value.  Return the old value.
 * Passing in a null value into this routine has the effect of
 * removing the key from the KVP tree.
 */
static KvpValue *
kvp_frame_replace_slot_nc (KvpFrame * frame, const char * slot,
                           KvpValue * new_value)
{
    gpointer orig_key;
    gpointer orig_value = NULL;
    int      key_exists;

    if (!frame || !slot) return NULL;
    if (!init_frame_body_if_needed(frame)) return NULL; /* Error ... */

    key_exists = g_hash_table_lookup_extended(frame->hash, slot,
                 & orig_key, & orig_value);
    if (key_exists)
    {
        g_hash_table_remove(frame->hash, slot);
        qof_string_cache_remove(orig_key);
    }
    else
    {
        orig_value = NULL;
    }

    if (new_value)
    {
        g_hash_table_insert(frame->hash,
                            qof_string_cache_insert((gpointer) slot),
                            new_value);
    }

    return (KvpValue *) orig_value;
}
Exemplo n.º 2
0
static void
kvp_frame_copy_worker(gpointer key, gpointer value, gpointer user_data)
{
    KvpFrame * dest = (KvpFrame *)user_data;
    g_hash_table_insert(dest->hash,
                        qof_string_cache_insert(key),
                        static_cast<void*>(kvp_value_copy(static_cast<KvpValue*>(value))));
}
Exemplo n.º 3
0
KvpFrameImpl::KvpFrameImpl(const KvpFrameImpl & rhs) noexcept
{
    std::for_each(rhs.m_valuemap.begin(), rhs.m_valuemap.end(),
                  [this](const map_type::value_type & a)
    {
        auto key = static_cast<char *>(qof_string_cache_insert(a.first));
        auto val = new KvpValueImpl(*a.second);
        this->m_valuemap.insert({key,val});
    }
                 );
}
Exemplo n.º 4
0
QofCollection *
qof_book_get_collection (const QofBook *book, QofIdType entity_type)
{
    QofCollection *col;

    if (!book || !entity_type) return NULL;

    col = static_cast<QofCollection*>(g_hash_table_lookup (book->hash_of_collections, entity_type));
    if (!col)
    {
        col = qof_collection_new (entity_type);
        g_hash_table_insert(
            book->hash_of_collections,
            qof_string_cache_insert((gpointer) entity_type), col);
    }
    return col;
}
Exemplo n.º 5
0
static void
add_event_type (ComponentEventInfo *cei, QofIdTypeConst entity_type,
                QofEventId event_mask, gboolean or_in)
{
    QofEventId *mask;

    g_return_if_fail (cei);
    g_return_if_fail (cei->event_masks);
    g_return_if_fail (entity_type);

    mask = g_hash_table_lookup (cei->event_masks, entity_type);
    if (!mask)
    {
        char * key = qof_string_cache_insert ((gpointer) entity_type);
        mask = g_new0 (QofEventId, 1);
        g_hash_table_insert (cei->event_masks, key, mask);
    }

    if (or_in)
        *mask |= event_mask;
    else
        *mask = event_mask;
}
Exemplo n.º 6
0
KvpValue*
KvpFrameImpl::set(const char* key, KvpValue* value) noexcept
{
    if (!key) return nullptr;
    if (strchr(key, delim))
        return set(make_vector(key), value);
    KvpValue* ret {nullptr};
    auto spot = m_valuemap.find(key);
    if (spot != m_valuemap.end())
    {
        qof_string_cache_remove(spot->first);
        ret = spot->second;
        m_valuemap.erase(spot);
    }

    if (value)
    {
        auto cachedkey =
            static_cast<const char *>(qof_string_cache_insert(key));
        m_valuemap.insert({cachedkey,value});
    }

    return ret;
}