grim/gplate
Clone
Summary
Browse
Changes
Graph
some more testing migration stuff.
2012-09-04, Gary Kramlich
7f8e0e4f250f
some more testing migration stuff.
Variables aren't done yet
/*
* GPlate - GObject based templating library
* Copyright (C) 2007-2012 Gary Kramlich <grim@reaperworld.com>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include
<gplate/gplate-collection.h>
/******************************************************************************
* Helpers
*****************************************************************************/
static
gboolean
gplate_collection_default_remove_all
(
GPlateCollection
*
collection
)
{
GPlateIterator
*
iter
=
NULL
;
gboolean
ret
=
TRUE
;
iter
=
gplate_collection_get_iterator
(
collection
);
if
(
!
GPLATE_IS_ITERATOR
(
iter
))
return
FALSE
;
while
(
gplate_iterator_has_next
(
iter
))
{
GPlateVariable
*
variable
=
NULL
;
variable
=
gplate_iterator_next
(
iter
);
if
(
!
GPLATE_IS_VARIABLE
(
variable
))
{
/* the iterator is out of sync, assume we're not going to get
* everything.
*/
ret
=
FALSE
;
continue
;
}
/* try to remove the variable, if it fails set ret to FALSE */
if
(
!
gplate_collection_remove_variable
(
collection
,
variable
))
ret
=
FALSE
;
}
return
ret
;
}
/******************************************************************************
* GPlateCollection API
*****************************************************************************/
GType
gplate_collection_get_gtype
(
void
)
{
static
GType
type
=
0
;
if
(
type
==
0
)
{
static
const
GTypeInfo
info
=
{
sizeof
(
GPlateCollectionIface
),
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
0
,
0
,
NULL
,
};
type
=
g_type_register_static
(
G_TYPE_INTERFACE
,
"GPlateCollection"
,
&
info
,
0
);
}
return
type
;
}
/**
* gplate_collection_find_variable:
* @collection: The #GPlateCollection.
* @name: The name of the #GPlateVariable to find.
*
* Finds a #GPlateVariable in @collection.
*
* Return Value: The #GPlateVariable if found, or NULL.
*/
GPlateVariable
*
gplate_collection_find_variable
(
const
GPlateCollection
*
collection
,
const
gchar
*
name
)
{
GPlateCollectionIface
*
iface
=
NULL
;
g_return_val_if_fail
(
GPLATE_IS_COLLECTION
(
collection
),
NULL
);
iface
=
GPLATE_COLLECTION_GET_IFACE
(
collection
);
if
(
iface
&&
iface
->
find_variable
)
return
iface
->
find_variable
(
collection
,
name
);
return
NULL
;
}
/**
* gplate_collection_lookup:
* @collection: The #GPlateCollection.
* @name: The name of the #GPlateVariable to lookup.
*
* Looks up a @name in @collection and returns it's value.
*
* Return Value: The value of @name, or NULL.
*/
const
gchar
*
gplate_collection_lookup
(
const
GPlateCollection
*
collection
,
const
gchar
*
name
)
{
GPlateVariable
*
var
=
NULL
;
g_return_val_if_fail
(
GPLATE_IS_COLLECTION
(
collection
),
NULL
);
g_return_val_if_fail
(
name
,
NULL
);
var
=
gplate_collection_find_variable
(
collection
,
name
);
g_return_val_if_fail
(
GPLATE_IS_VARIABLE
(
var
),
NULL
);
return
gplate_variable_get_value
(
var
);
}
/**
* gplate_collection_add_variable:
* @collection: The #GPlateCollection.
* @variable: The #GPlateVariable.
*
* Adds @variable to @collection.
*
* Note: The collection will assume the reference of @variable. If you need to
* keep @variable around, reference it with #g_object_ref.
*
* Return Value: TRUE on success, otherwise FALSE.
*/
gboolean
gplate_collection_add_variable
(
GPlateCollection
*
collection
,
GPlateVariable
*
variable
)
{
const
gchar
*
name
=
NULL
;
gboolean
ret
=
FALSE
;
g_return_val_if_fail
(
GPLATE_IS_COLLECTION
(
collection
),
FALSE
);
g_return_val_if_fail
(
GPLATE_IS_VARIABLE
(
variable
),
FALSE
);
name
=
gplate_variable_get_name
(
variable
);
ret
=
gplate_collection_add_variable_with_name
(
collection
,
name
,
variable
);
return
ret
;
}
/**
* gplate_collection_add_variable_with_name:
* @collection: The #GPlateCollection.
* @name: The name to use for this variable in the collection.
* @variable: The #GPlateVariable.
*
* Adds @variable to @collection with a name of @name.
*
* This function should not be used directly, aside from iterators and other
* functions that need to rename a variable.
*
* Note: The collection will assume the reference of @variable. If you need to
* keep @variable around, reference it with #g_object_ref.
*
* Return Value: TRUE on success, otherwise FALSE.
*/
gboolean
gplate_collection_add_variable_with_name
(
GPlateCollection
*
collection
,
const
gchar
*
name
,
GPlateVariable
*
variable
)
{
GPlateCollectionIface
*
iface
=
NULL
;
g_return_val_if_fail
(
GPLATE_IS_COLLECTION
(
collection
),
FALSE
);
g_return_val_if_fail
(
name
,
FALSE
);
g_return_val_if_fail
(
GPLATE_IS_VARIABLE
(
variable
),
FALSE
);
iface
=
GPLATE_COLLECTION_GET_IFACE
(
collection
);
if
(
iface
&&
iface
->
add_variable_with_name
)
return
iface
->
add_variable_with_name
(
collection
,
name
,
variable
);
return
FALSE
;
}
/**
* gplate_collection_remove_variable:
* @collection: The #GPlateCollection.
* @variable: The #GPlateVariable.
*
* Removes @variable from @collection.
*
* Return Value: TRUE on success, otherwise FALSE.
*/
gboolean
gplate_collection_remove_variable
(
GPlateCollection
*
collection
,
GPlateVariable
*
variable
)
{
GPlateCollectionIface
*
iface
=
NULL
;
g_return_val_if_fail
(
GPLATE_IS_COLLECTION
(
collection
),
FALSE
);
iface
=
GPLATE_COLLECTION_GET_IFACE
(
collection
);
if
(
iface
&&
iface
->
remove_variable
)
return
iface
->
remove_variable
(
collection
,
variable
);
return
FALSE
;
}
/**
* gplate_collection_remove_all:
* @collection: The #GPlateCollection.
*
* Removes all variables from @collection.
*
* Return Value: TRUE if all variables remove, FALSE if all of the variables
* could not be removed.
*/
gboolean
gplate_collection_remove_all
(
GPlateCollection
*
collection
)
{
GPlateCollectionIface
*
iface
=
NULL
;
g_return_val_if_fail
(
GPLATE_IS_COLLECTION
(
collection
),
FALSE
);
iface
=
GPLATE_COLLECTION_GET_IFACE
(
collection
);
if
(
iface
&&
iface
->
remove_all
)
return
iface
->
remove_all
(
collection
);
return
gplate_collection_default_remove_all
(
collection
);
}
/**
* gplate_collection_get_iterator:
* @collection: The #GPlateCollection.
*
* Gets an iterator to the elements in @collection.
*
* Return Value: A new #GPlateIterator initialized to the first element of
* @collection.
*/
GPlateIterator
*
gplate_collection_get_iterator
(
GPlateCollection
*
collection
)
{
GPlateCollectionIface
*
iface
=
NULL
;
g_return_val_if_fail
(
GPLATE_IS_COLLECTION
(
collection
),
NULL
);
iface
=
GPLATE_COLLECTION_GET_IFACE
(
collection
);
if
(
iface
&&
iface
->
get_iterator
)
return
iface
->
get_iterator
(
collection
);
return
NULL
;
}