This repository has been archived on 2024-07-15. You can view files and clone it, but cannot push or open issues or pull requests.
hedera/db/db-result-set.c

125 lines
2.9 KiB
C
Raw Normal View History

2013-10-11 23:07:35 +00:00
/*
* Copyright (C) 2012 - Juan Ferrer Toribio
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "db-result-set.h"
/**
* SECTION: db-result-set
* @Short_description:
* @Title: DbResultSet
* @See_also: #DbResult
**/
G_DEFINE_BOXED_TYPE (DbResultSet, db_result_set, db_result_set_copy, db_result_set_free);
/**
* db_result_set_new:
*
* Return value: the new #DbResultSet
**/
DbResultSet * db_result_set_new ()
{
DbResultSet * obj = g_new (DbResultSet, 1);
obj->results = NULL;
return obj;
}
/**
* db_result_set_take_nth:
* @obj: a #DbResultSet
* @n: the position of the result, counting from 0
*
* Gets the nth result and removes it from the resultset. The user is
* responsible for releasing the result with db_result_free().
*
* Return value: (transfer full): the #DbResult or %NULL if nth result doesn't exist
**/
DbResult * db_result_set_take_nth (DbResultSet * obj, guint n)
{
GSList * list;
g_return_val_if_fail (obj, NULL);
list = g_slist_nth (obj->results, n);
if (list)
{
DbResult * result = list->data;
obj->results = g_slist_delete_link (obj->results, list);
return result;
}
return NULL;
}
/**
* db_result_set_take_next:
* @obj: a #DbResultSet
*
* Gets the next result and removes it from the resultset. The user is
* responsible for releasing the result with db_result_free().
*
* Return value: (transfer full): the #DbResult or %NULL if no more results
**/
DbResult * db_result_set_take_next (DbResultSet * obj)
{
g_return_val_if_fail (obj, NULL);
return db_result_set_take_nth (obj, 0);
}
/**
* db_result_set_copy:
* @obj: a #DbResultSet
*
* Makes a copy of a #DbResultSet.
*
* Return value: a newly allocated #DbResultSet, with the same contents
**/
DbResultSet * db_result_set_copy (const DbResultSet * obj)
{
GSList * n;
DbResultSet * set;
g_return_val_if_fail (obj, NULL);
set = db_result_set_new ();
for (n = obj->results; n; n = n->next)
set->results = g_slist_append (set->results, db_result_copy (n->data));
return set;
}
/**
* db_result_set_free:
* @obj: a #DbResultSet
*
* Frees a #DbResultSet.
**/
void db_result_set_free (DbResultSet * obj)
{
GSList * n;
g_return_if_fail (obj);
for (n = obj->results; n; n = n->next)
db_result_free (n->data);
g_slist_free (obj->results);
g_free (obj);
}