|
Packit Service |
f02b19 |
/*
|
|
Packit Service |
f02b19 |
* gnome-keyring
|
|
Packit Service |
f02b19 |
*
|
|
Packit Service |
f02b19 |
* Copyright (C) 2010 Stefan Walter
|
|
Packit Service |
f02b19 |
*
|
|
Packit Service |
f02b19 |
* This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
f02b19 |
* it under the terms of the GNU Lesser General Public License as
|
|
Packit Service |
f02b19 |
* published by the Free Software Foundation; either version 2.1 of
|
|
Packit Service |
f02b19 |
* the License, or (at your option) any later version.
|
|
Packit Service |
f02b19 |
*
|
|
Packit Service |
f02b19 |
* This program is distributed in the hope that it will be useful, but
|
|
Packit Service |
f02b19 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
f02b19 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
f02b19 |
* Lesser General Public License for more details.
|
|
Packit Service |
f02b19 |
*
|
|
Packit Service |
f02b19 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
f02b19 |
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit Service |
f02b19 |
*/
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
#include "config.h"
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
#include "gcr-comparable.h"
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
#include <string.h>
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
/**
|
|
Packit Service |
f02b19 |
* SECTION:gcr-comparable
|
|
Packit Service |
f02b19 |
* @title: GcrComparable
|
|
Packit Service |
f02b19 |
* @short_description: Interface for comparing objects
|
|
Packit Service |
f02b19 |
*
|
|
Packit Service |
f02b19 |
* The #GcrComparable interface is implemented by objects when they should be
|
|
Packit Service |
f02b19 |
* comparable against one another.
|
|
Packit Service |
f02b19 |
*/
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
/**
|
|
Packit Service |
f02b19 |
* GcrComparable:
|
|
Packit Service |
f02b19 |
*
|
|
Packit Service |
f02b19 |
* The #GcrComparable interface is implemented by comparable objects.
|
|
Packit Service |
f02b19 |
*/
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
/**
|
|
Packit Service |
f02b19 |
* GcrComparableIface:
|
|
Packit Service |
f02b19 |
* @parent: type interface
|
|
Packit Service |
f02b19 |
* @compare: Compare whether tow objects represent the same thing.
|
|
Packit Service |
f02b19 |
*
|
|
Packit Service |
f02b19 |
* The interface to implement for #GcrComparable
|
|
Packit Service |
f02b19 |
*/
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
typedef GcrComparableIface GcrComparableInterface;
|
|
Packit Service |
f02b19 |
G_DEFINE_INTERFACE (GcrComparable, gcr_comparable, G_TYPE_OBJECT);
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
static void
|
|
Packit Service |
f02b19 |
gcr_comparable_default_init (GcrComparableIface *iface)
|
|
Packit Service |
f02b19 |
{
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
}
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
/**
|
|
Packit Service |
f02b19 |
* gcr_comparable_compare:
|
|
Packit Service |
f02b19 |
* @self: The comparable object
|
|
Packit Service |
f02b19 |
* @other: (allow-none): Another comparable object
|
|
Packit Service |
f02b19 |
*
|
|
Packit Service |
f02b19 |
* Compare whether two objects represent the same thing. The return value can
|
|
Packit Service |
f02b19 |
* also be used to sort the objects.
|
|
Packit Service |
f02b19 |
*
|
|
Packit Service |
f02b19 |
* Returns: Zero if the two objects represent the same thing, non-zero if not.
|
|
Packit Service |
f02b19 |
*/
|
|
Packit Service |
f02b19 |
gint
|
|
Packit Service |
f02b19 |
gcr_comparable_compare (GcrComparable *self, GcrComparable *other)
|
|
Packit Service |
f02b19 |
{
|
|
Packit Service |
f02b19 |
g_return_val_if_fail (GCR_IS_COMPARABLE (self), -1);
|
|
Packit Service |
f02b19 |
g_return_val_if_fail (GCR_COMPARABLE_GET_INTERFACE (self)->compare, -1);
|
|
Packit Service |
f02b19 |
g_return_val_if_fail (G_IS_OBJECT (self), -1);
|
|
Packit Service |
f02b19 |
return GCR_COMPARABLE_GET_INTERFACE (self)->compare (self, other);
|
|
Packit Service |
f02b19 |
}
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
/**
|
|
Packit Service |
f02b19 |
* gcr_comparable_memcmp: (skip)
|
|
Packit Service |
f02b19 |
* @mem1: (array length=size1) (element-type guint8): First block of memory
|
|
Packit Service |
f02b19 |
* @size1: Length of first block
|
|
Packit Service |
f02b19 |
* @mem2: (array length=size2) (element-type guint8): Second block of memory
|
|
Packit Service |
f02b19 |
* @size2: Length of second block
|
|
Packit Service |
f02b19 |
*
|
|
Packit Service |
f02b19 |
* Compare two blocks of memory. The return value can be used to sort
|
|
Packit Service |
f02b19 |
* the blocks of memory.
|
|
Packit Service |
f02b19 |
*
|
|
Packit Service |
f02b19 |
* Returns: Zero if the blocks are identical, negative if first
|
|
Packit Service |
f02b19 |
* less than secend, possitive otherwise.
|
|
Packit Service |
f02b19 |
*/
|
|
Packit Service |
f02b19 |
gint
|
|
Packit Service |
f02b19 |
gcr_comparable_memcmp (gconstpointer mem1,
|
|
Packit Service |
f02b19 |
gsize size1,
|
|
Packit Service |
f02b19 |
gconstpointer mem2,
|
|
Packit Service |
f02b19 |
gsize size2)
|
|
Packit Service |
f02b19 |
{
|
|
Packit Service |
f02b19 |
gint result;
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
if (mem1 == mem2 && size1 == size2)
|
|
Packit Service |
f02b19 |
return 0;
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
if (!mem1)
|
|
Packit Service |
f02b19 |
return 1;
|
|
Packit Service |
f02b19 |
if (!mem2)
|
|
Packit Service |
f02b19 |
return -1;
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
result = memcmp (mem1, mem2, MIN (size1, size2));
|
|
Packit Service |
f02b19 |
if (result != 0)
|
|
Packit Service |
f02b19 |
return result;
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
if (size1 == size2)
|
|
Packit Service |
f02b19 |
return 0;
|
|
Packit Service |
f02b19 |
if (size1 < size2)
|
|
Packit Service |
f02b19 |
return -1;
|
|
Packit Service |
f02b19 |
return 1;
|
|
Packit Service |
f02b19 |
}
|