Listing 1: NETWORK.H — Template class network

// NOTE: portions of this listing are not shown here due to space
// constraints.  Full source code is available on the CUJ ftp site
//
// not shown: #includes, #defines, preprocessing directives
// ...

#if defined(__BORLANDC__) || (_MSC_VER >= 1100 )
    using namespace std;
#endif

template<class _NODE, class _ARC, class _A> ///
class network
{
public:
#if _MSC_VER < 1100
    struct _iArc;   
    struct _iNode;  
#endif

    typedef _A allocator_type;
    typedef allocator_type::size_type size_type;
    typedef network<_NODE, _ARC, _A> _Myt;

protected:
    allocator_type _alloc;

    // _iArc
#if _MSC_VER == 1100
    // defined outside class due to namespace resolution problems
    // with Microsoft Visual C++ 5.0
    typedef __Arc<_ARC, size_type> _iArc;
#else
    struct _iArc
    {
        _iArc() {}
        _iArc(const _ARC arc, size_type src, size_type dtn) :
            data(arc), source_node(src), destin_node(dtn) {}
        _ARC data;
        size_type source_node;
        size_type destin_node;
        bool operator==(const _iArc& net) const
            { return this==&net; }
        bool operator!=(const _iArc& net) const
            { return this!=&net; }
        bool operator< (const _iArc& net) const
            { return this<&net; }
        bool operator> (const _iArc& net) const
            { return this>&net; }
    };
#endif

/// typedef _A::rebind<_iArc>::other arc_allocator_type
    typedef allocator<_iArc>    arc_allocator_type;     ///
    // ARCLIST
    typedef list< _iArc , arc_allocator_type > ARCLIST;
    typedef ARCLIST::iterator       _arcIt;
    typedef ARCLIST::const_iterator _CarcIt;
    ARCLIST arc_list;

    // _iNode
#if _MSC_VER == 1100
    // defined outside class due to namespace resolution
    // problems with Microsoft Visual C++ 5.0
    typedef __Node<_NODE, _arcIt> _iNode;
#else
    struct _iNode   
        {
            _iNode() {}
            _iNode(const _NODE& n, const _arcIt& a) :
                        data(n), firstArcOut(a) {}
            _NODE data;
            _arcIt firstArcOut;
            bool operator==(const _iNode& net) const
                { return this==&net; }
            bool operator< (const _iNode& net) const
                { return this<&net; }
        };
#endif

    // ...

    // NODELIST
    typedef vector<_iNode, node_allocator_type > NODELIST; 
    typedef NODELIST::iterator          _nodeIt;
    typedef NODELIST::const_iterator    _CnodeIt;
    NODELIST node_list;

public:

    // not shown: various typedefs
    // ...

        // CLASS node_iterator

    class node_iterator : 
        public _Bidit<node_value_type, node_difference_type>
    {

    // ...


    };

        // CLASS const_node_iterator

    class const_node_iterator : 
        public _Bidit<node_value_type, node_difference_type> 
    {

    // ...

    };

    typedef reverse_bidirectional_iterator<const_node_iterator, 
        node_value_type, const_node_reference, const_node_pointer,
        node_difference_type>   const_reverse_node_iterator;
    typedef reverse_bidirectional_iterator<node_iterator, 
        node_value_type, node_reference, node_pointer, 
        node_difference_type>   reverse_node_iterator;

    // not shown: node iterator forwarding functions
    // ...

        // CLASS arc_iterator

    class arc_iterator : 
        public _Bidit<arc_value_type, arc_difference_type>
    {

    // ...

    };

    typedef reverse_bidirectional_iterator<const_arc_iterator, 
            arc_value_type, const_arc_reference, const_arc_pointer, 
            arc_difference_type>    const_reverse_arc_iterator;
    typedef reverse_bidirectional_iterator<arc_iterator, 
            arc_value_type, arc_reference, arc_pointer, 
            arc_difference_type>    reverse_arc_iterator;

    // not shown: arc iterator forwarding functions
    // ...

protected:
    _arcIt _end_arcs(node_iterator node)
        {
            // it at last node, return end of the arc list
            if( (node==(node_list.end()-1)) || 
                (node==(node_list.end())))
                return arc_list.end();
            // otherwise return first arc of next node
            return (*(++node)._Myit()).firstArcOut;
            }

    // not shown: remaining internal iterator functions
    // ...

public:

    // not shown: arc insertion & erasure functions,
    // node insertion & erasure functions,
    // auxiliary functions

public:
    network() {}
    ~network() {}
};
//End of File