예제 #1
0
bool SaveStateDescriptor::getBool(const Common::String &key) const {
	if (contains(key)) {
		Common::String value = getVal(key);
		if (value.equalsIgnoreCase("true") ||
			value.equalsIgnoreCase("yes") ||
			value.equals("1"))
			return true;
		if (value.equalsIgnoreCase("false") ||
			value.equalsIgnoreCase("no") ||
			value.equals("0"))
			return false;
		error("SaveStateDescriptor: %s '%s' has unknown value '%s' for boolean '%s'",
				save_slot().c_str(), description().c_str(), value.c_str(), key.c_str());
	}
	return false;
}
예제 #2
0
static void
save_slot( const gchar* key, KvpValue* value, gpointer data )
{
    slot_info_t* pSlot_info = (slot_info_t*)data;
    gsize curlen;

    g_return_if_fail( key != NULL );
    g_return_if_fail( value != NULL );
    g_return_if_fail( data != NULL );

    // Ignore if we've already run into a failure
    if ( !pSlot_info->is_ok )
    {
        return;
    }

    curlen = pSlot_info->path->len;
    pSlot_info->pKvpValue = value;
    if ( curlen != 0 )
    {
        (void)g_string_append( pSlot_info->path, "/" );
    }
    (void)g_string_append( pSlot_info->path, key );
    pSlot_info->value_type = kvp_value_get_type( value );

    switch ( pSlot_info->value_type )
    {
    case KVP_TYPE_FRAME:
    {
        KvpFrame* pKvpFrame = kvp_value_get_frame( value );
        GncGUID guid = guid_new_return();
        slot_info_t *pNewInfo = slot_info_copy( pSlot_info, &guid );
        KvpValue *oldValue = pSlot_info->pKvpValue;
        pSlot_info->pKvpValue = kvp_value_new_guid( &guid );
        pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be,
                            OP_DB_INSERT, TABLE_NAME,
                            TABLE_NAME, pSlot_info,
                            col_table );
        g_return_if_fail( pSlot_info->is_ok );
        kvp_frame_for_each_slot( pKvpFrame, save_slot, pNewInfo );
        kvp_value_delete( pSlot_info->pKvpValue );
        pSlot_info->pKvpValue = oldValue;
        g_string_free( pNewInfo->path, TRUE );
        g_slice_free( slot_info_t, pNewInfo );
    }
    break;
    case KVP_TYPE_GLIST:
    {
        GList *cursor;
        GncGUID guid = guid_new_return();
        slot_info_t *pNewInfo = slot_info_copy( pSlot_info, &guid );
        KvpValue *oldValue = pSlot_info->pKvpValue;
        pSlot_info->pKvpValue = kvp_value_new_guid( &guid );
        pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be,
                            OP_DB_INSERT, TABLE_NAME,
                            TABLE_NAME, pSlot_info,
                            col_table );
        g_return_if_fail( pSlot_info->is_ok );
        for (cursor = kvp_value_get_glist(value); cursor; cursor = cursor->next)
        {
            kvp_value *val = (kvp_value*)cursor->data;
            save_slot("", val, pNewInfo);
        }
        kvp_value_delete( pSlot_info->pKvpValue );
        pSlot_info->pKvpValue = oldValue;
        g_string_free( pNewInfo->path, TRUE );
        g_slice_free( slot_info_t, pNewInfo );
    }
    break;
    default:
    {
        pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be,
                            OP_DB_INSERT, TABLE_NAME,
                            TABLE_NAME, pSlot_info,
                            col_table );
    }
    break;
    }

    (void)g_string_truncate( pSlot_info->path, curlen );
}
예제 #3
0
static void
save_slot( const gchar* key, KvpValue* value, gpointer data )
{
    slot_info_t* pSlot_info = (slot_info_t*)data;
    gsize curlen;

    g_return_if_fail( key != NULL );
    g_return_if_fail( value != NULL );
    g_return_if_fail( data != NULL );

    // Ignore if we've already run into a failure
    if ( !pSlot_info->is_ok )
    {
        return;
    }

    curlen = pSlot_info->path->len;
    pSlot_info->pKvpValue = value;
    if ( curlen != 0 )
    {
        (void)g_string_append( pSlot_info->path, "/" );
    }
    (void)g_string_append( pSlot_info->path, key );
    pSlot_info->value_type = value->get_type();

    switch ( pSlot_info->value_type )
    {
    case KvpValue::Type::FRAME:
    {
        auto pKvpFrame = value->get<KvpFrame*>();
        auto guid = guid_new();
        slot_info_t *pNewInfo = slot_info_copy( pSlot_info, guid );
        KvpValue *oldValue = pSlot_info->pKvpValue;
        pSlot_info->pKvpValue = new KvpValue{guid};
        pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be,
                            OP_DB_INSERT, TABLE_NAME,
                            TABLE_NAME, pSlot_info,
                            col_table );
        g_return_if_fail( pSlot_info->is_ok );
        pKvpFrame->for_each_slot(save_slot, pNewInfo);
        delete pSlot_info->pKvpValue;
        pSlot_info->pKvpValue = oldValue;
        g_string_free( pNewInfo->path, TRUE );
        g_slice_free( slot_info_t, pNewInfo );
    }
    break;
    case KvpValue::Type::GLIST:
    {
        GncGUID guid = guid_new_return();
        slot_info_t *pNewInfo = slot_info_copy( pSlot_info, &guid );
        KvpValue *oldValue = pSlot_info->pKvpValue;
        pSlot_info->pKvpValue = new KvpValue{&guid};
        pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be,
                            OP_DB_INSERT, TABLE_NAME,
                            TABLE_NAME, pSlot_info,
                            col_table );
        g_return_if_fail( pSlot_info->is_ok );
        for (auto cursor = value->get<GList*>(); cursor; cursor = cursor->next)
        {
            auto val = static_cast<KvpValue*>(cursor->data);
            save_slot("", val, pNewInfo);
        }
        delete pSlot_info->pKvpValue;
        pSlot_info->pKvpValue = oldValue;
        g_string_free( pNewInfo->path, TRUE );
        g_slice_free( slot_info_t, pNewInfo );
    }
    break;
    default:
    {
        pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be,
                            OP_DB_INSERT, TABLE_NAME,
                            TABLE_NAME, pSlot_info,
                            col_table );
    }
    break;
    }

    (void)g_string_truncate( pSlot_info->path, curlen );
}
예제 #4
0
static void
save_slot (const char* key, KvpValue* value, gpointer data)
{
    slot_info_t* pSlot_info = (slot_info_t*)data;

    g_return_if_fail (value != NULL);
    g_return_if_fail (data != NULL);

    // Ignore if we've already run into a failure
    if (!pSlot_info->is_ok)
    {
        return;
    }
    auto curlen = pSlot_info->path.length();
    pSlot_info->pKvpValue = value;
    if (curlen != 0)
        pSlot_info->path += "/";

    pSlot_info->path += key;
    pSlot_info->value_type = value->get_type ();

    switch (pSlot_info->value_type)
    {
    case KvpValue::Type::FRAME:
    {
        auto pKvpFrame = value->get<KvpFrame*> ();
        auto guid = guid_new ();
        slot_info_t* pNewInfo = slot_info_copy (pSlot_info, guid);
        KvpValue* oldValue = pSlot_info->pKvpValue;
        pSlot_info->pKvpValue = new KvpValue {guid};
        pSlot_info->is_ok = pSlot_info->be->do_db_operation(OP_DB_INSERT,
                                                            TABLE_NAME,
                                                            TABLE_NAME,
                                                            pSlot_info,
                                                            col_table);
        g_return_if_fail (pSlot_info->is_ok);
        pKvpFrame->for_each_slot (save_slot, pNewInfo);
        delete pSlot_info->pKvpValue;
        pSlot_info->pKvpValue = oldValue;
        delete pNewInfo;
    }
    break;
    case KvpValue::Type::GLIST:
    {
        GncGUID* guid = guid_new ();
        slot_info_t* pNewInfo = slot_info_copy (pSlot_info, guid);
        KvpValue* oldValue = pSlot_info->pKvpValue;
        pSlot_info->pKvpValue = new KvpValue {guid};  // Transfer ownership!
        pSlot_info->is_ok = pSlot_info->be->do_db_operation(OP_DB_INSERT,
                                                            TABLE_NAME,
                                                            TABLE_NAME,
                                                            pSlot_info,
                                                            col_table);
        g_return_if_fail (pSlot_info->is_ok);
        for (auto cursor = value->get<GList*> (); cursor; cursor = cursor->next)
        {
            auto val = static_cast<KvpValue*> (cursor->data);
            save_slot ("", val, pNewInfo);
        }
        delete pSlot_info->pKvpValue;
        pSlot_info->pKvpValue = oldValue;
        delete pNewInfo;
    }
    break;
    default:
    {
        pSlot_info->is_ok = pSlot_info->be->do_db_operation (OP_DB_INSERT,
                                                             TABLE_NAME,
                                                             TABLE_NAME,
                                                             pSlot_info,
                                                             col_table);
    }
    break;
    }

    pSlot_info->path.erase(curlen);
}