// -*- C++ -*-
//
//  This file is part of Siena, a wide-area event notification system.
//  See http://www.cs.colorado.edu/serl/dot/siena.html
//
//  Author: Antonio Carzaniga <carzanig@cs.colorado.edu>
//  See the file AUTHORS for full details. 
//
//  Copyright (C) 1998-1999 University of Colorado
//
//  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 2
//  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, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
//  USA, or send email to serl@cs.colorado.edu.
//
//
// $Id: SimpleGraph.h,v 1.1 2002/06/12 17:05:28 carzanig Exp $
//
#ifndef _SimpleGraph_h
#define _SimpleGraph_h

using namespace std;

#include <string>
#include <map>
#include <set>

#include <gtk/gtk.h>

#include <Image.h>
#include <geometry.h>

class Node : public Point {
public:
    const Image *		image;

				Node(const Image *, int, int);
				Node(const Node &);
    Node &			operator = (const Node &);
};

typedef map<string, Node> NodesTable;

class Edge {
public:
    NodesTable::iterator	source;
    NodesTable::iterator	target;
	
				Edge(NodesTable::iterator s, 
				     NodesTable::iterator t);
	
    bool			operator == (const Edge &)		const;
    Edge &			operator = (const Edge &);
    bool			operator < (const Edge &)		const;
};

typedef set<Edge>	EdgesTable;

class SGraph {
private:
    NodesTable	nodes;
    EdgesTable	edges;

public:
    typedef NodesTable::iterator	n_iterator;
    typedef EdgesTable::iterator	e_iterator;

    typedef NodesTable::const_iterator	n_const_iterator;
    typedef EdgesTable::const_iterator	e_const_iterator;

    void	clear();

    n_iterator	add_node(const string &, const Image *, int x=-1, int y=-1);
    bool	remove_node(const string & name);
    bool	remove_node(n_iterator);

    bool	connect(const string &, const string &);
    bool	connect(n_iterator, n_iterator);

    bool	disconnect(const string & , const string &);
    bool	disconnect(n_iterator, n_iterator);

    n_iterator	find_node(const string &);
    n_iterator	find_node(const Point &);

    n_iterator	nodes_begin();
    n_iterator	nodes_end();

    //    e_iterator	edges_find(const string &, const string &);
    //    e_iterator	edges_find(const string &, const string &);
    e_iterator	edges_begin();
    e_iterator	edges_end();
};

#ifndef NO_INLINE
#include <SimpleGraph.icc>
#endif

#endif
