/*
 * traverse.h
 * Routines for traversing xml/rdf graphs.
 *
 * Copyright (C) Leni Mayo 2002
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License, version 2, as
 *	published by the Free Software Foundation.
 *	
 *	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, write to the Free Software
 *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef _TRAVERSE_H_
#define _TRAVERSE_H_

#include <glib.h>
#include <redland.h>

/* Data structure that's passed to the depth first traversal callback
*/
typedef struct
{
	GSList *pStack; /* list of (librdf_node *)'s representing a traversal from a root node */
	void   *pData;
} DftUserData;

typedef int (*DFT_CALLBACK)(librdf_model *pModel, librdf_node *pNode, DftUserData *pUserData);

void depth_first_traverse_start(librdf_model *pModel,
	GSList *pRootNodes,
	librdf_node *pGraphFrom,
	librdf_node *pGraphTo,
	DFT_CALLBACK fn_pre,
	DFT_CALLBACK fn_post,
	DftUserData *pUserData);

int depth_first_traverse(librdf_model *pModel,
	librdf_node *pGraphFrom,
	librdf_node *pGraphTo,
	librdf_node *pNode,
	DFT_CALLBACK fn_pre,
	DFT_CALLBACK fn_post,
	DftUserData *pUserData);

int acyclic_callback_pre(librdf_model *pModel, librdf_node *pNode, DftUserData *pUserData);
int stack_push_callback_pre(librdf_model *pModel, librdf_node *pNode, DftUserData *pUserData);
int stack_pop_callback_post(librdf_model *pModel, librdf_node *pNode, DftUserData *pUserData);

GSList * nodes_from_rdf_container(librdf_model *pModel, librdf_node *pContainer, librdf_node *pGraphTo);
GSList * listOfReferencedNode(librdf_model *pModel, librdf_node *pGraphNode, librdf_node *pGraphTo);

void testAcyclic(librdf_model *pModel, GSList **ppCycle, librdf_node *pGraphNode);

#endif /* _TRAVERSE_H_ */
