
/*
**  This file forms part of the GOBLIN C++ Class Library.
**
**  Written by Christian Fremuth-Paeger, September 1999.
**  
**  Copying, compiling, distribution and modification
**  of this source code is permitted only in accordance
**  with the GOBLIN general licence information.
*/             


#if !defined(_SPSSTRUC_H_)

#define _SPSSTRUC_H_

#include <genstruc.h>


class sparseGraphStructure : public genericGraphStructure
{
protected:

    TNode           ni;          // Number of layout nodes 

    TNode*          SN;          // Array of start nodes
    TArc*           right;       // Array of right incidences
    TArc*           left;        // Array of left incidences
    TArc*           first;       // Array of first incidences

    TNode*          align;       // Alignment of arc labels
    TNode*          interpolate; // Next interpolation point

    TFloat*         sub;         // Subgraph arc capacities

public:

    sparseGraphStructure(abstractMixedGraph &,TOption = 0) throw();
    ~sparseGraphStructure() throw();

    void            ReadIncidences(goblinImport &) throw(ERParse);
    void            ReadLayout(goblinImport &) throw(ERParse);
    
    void            ReSize(TNode,TArc) throw(ERRejected);
    
    void            ReDimension(TNode,TNode,TArc) throw(ERRejected);
    
    unsigned long   Size() throw();
    unsigned long   Allocated() throw();

    
    // *************************************************************** //
    //                    Graph manipulation methods                   //
    // *************************************************************** //
    
    TArc            InsertArc(TNode,TNode,TCap,TCap,TFloat)
                        throw(ERRange,ERRejected);
    TArc            InsertArc(TNode,TNode) throw(ERRange,ERRejected);
    TNode           InsertNode() throw(ERRejected);
    TNode           InsertArtificalNode() throw(ERRejected);
    TNode           InsertAlignmentPoint(TArc)
                        throw(ERRejected,ERRange);
    TNode           InsertBendNode(TNode) throw(ERRejected,ERRange);
    
    void            SwapArcs(TArc,TArc) throw(ERRange);
    void            SwapNodes(TNode,TNode) throw(ERRange);
    void            FlipArc(TArc a) throw(ERRange)
                        {SwapArcs(a,a^1);};
    void            CancelArc(TArc) throw(ERRange,ERRejected);
    void            CancelNode(TNode) throw(ERRange);
    void            ReleaseBendNodes(TArc) throw(ERRange);
    void            DeleteArc(TArc) throw(ERRange);
    void            DeleteNode(TNode) throw(ERRange);
    void            DeleteArcs() throw();
    void            DeleteNodes() throw();
    void            ContractArc(TArc) throw(ERRange,ERRejected);
    void            IdentifyNodes(TNode,TNode) throw(ERRange,ERRejected);

    
    // *************************************************************** //
    //           Management of Node and Arc Incidences                 //
    // *************************************************************** //
    
    TNode           StartNode(TArc) throw(ERRange,ERRejected);
    TNode           EndNode(TArc) throw(ERRange,ERRejected);
    
    TArc            Right(TArc) throw(ERRange);
    TArc            Left(TArc) throw(ERRange,ERFatal);
    TArc            First(TNode) throw(ERRange);
    void            SetFirst(TNode,TArc) throw(ERRange,ERFatal);
    
    TNode           NI() throw()
                        {return ni;};
    virtual TNode   Align(TArc) throw(ERRange);
    bool            CAlign() throw()
                        {return align==NULL;};
    virtual TNode   Interpolate(TNode) throw(ERRange);
    bool            CInterpolate() throw()
                        {return interpolate==NULL;};
    
    void            ReleaseIncidences() throw();

    
    // *************************************************************** //
    //           Subgraph Management                                   //
    // *************************************************************** //

    void            NewSubgraph() throw(ERRejected);
    void            ReleaseSubgraph() throw();

    TFloat          Sub(TArc) throw(ERRange);
    void            AddArc(TArc,TFloat) throw(ERRange,ERRejected);
    void            OmitArc(TArc,TFloat) throw(ERRange,ERRejected);
    
};                           


#endif
