/*
 * Copyright (c) 1999 Johnny C. Lam.
 * All rights reserved.
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  The author makes no representations
 * about the suitability of this software for any purpose.  It is
 * provided "as is" without express or implied warranty.
 */

// -*- C++ -*-

template <typename T, typename W>
inline
node
stl_graph<T,W>::add_node(const value_type& data)
{
    node n = _topology.new_node();
    _node_data[n] = data;
    return n;
}

template <typename T, typename W>
inline
edge
stl_graph<T,W>::add_edge(const node& src, const node& tgt,
			 const weight_type& data)
{
    edge e = _topology.new_edge(src, tgt);
    _edge_data[e] = data;
    return e;
}

template <typename T, typename W>
inline
void
stl_graph<T,W>::erase(const node& n)
{
    _node_data[n] = T();
    node::inout_edges_iterator e = n.inout_edges_begin();
    while (e != n.inout_edges_end()) {
	erase(*e);
	e = n.inout_edges_begin();
    }
    _topology.del_node(n);
}

template <typename T, typename W>
inline
void
stl_graph<T,W>::erase(const edge& e)
{
    _edge_data[e] = W();
    _topology.del_edge(e);
}

template <typename T, typename W>
inline
void
stl_graph<T,W>::e_clear()
{
    graph::edge_iterator e = _topology.edges_begin();
    while (e != _topology.edges_end()) {
	_topology.del_edge(*e);
	e = _topology.edges_begin();
    }
    _edge_data.init(_topology);
}

template <typename T, typename W>
inline
void
stl_graph<T,W>::n_clear()
{
    graph::node_iterator n = _topology.nodes_begin();
    while (n != _topology.nodes_end()) {
	_topology.del_node(*n);
	n = _topology.nodes_begin();
    }
    _node_data.init(_topology);
    _edge_data.init(_topology);
}

template <typename T, typename W>
inline
void
stl_graph<T,W>::clear()
{
    n_clear();
}
