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



    sparseGraphStructure &Struct() throw() {return X;};
    
    bool            IsSparse() throw()
                        {return true;};

    void            ReSize(TNode nn,TArc mm) throw()
                        {X.ReSize(nn,mm);};
    
    TNode           StartNode(TArc a) throw(ERRange)
                        {return X.StartNode(a);};
    TNode           EndNode(TArc a) throw(ERRange)
                        {return X.EndNode(a);};
    
    TArc            First(TNode v) throw(ERRange)
                        {return X.First(v);};
    void            SetFirst(TNode v,TArc a) throw(ERRange,ERRejected)
                        {X.SetFirst(v,a);};
    TArc            Right(TArc a,TNode v = NoNode) throw(ERRange)
                        {return X.Right(a);};
    void            SetRight(TArc a1,TArc a2) throw(ERRange,ERRejected)
                        {X.SetRight(a1,a2);};

    TNode           Align(TArc a) throw(ERRange)
                        {return X.Align(a);};
    bool            CAlign() throw()
                        {return X.CAlign();};
    TNode           Interpolate(TNode v) throw(ERRange)
                        {return X.Interpolate(v);};
    bool            CInterpolate() throw()
                        {return X.CInterpolate();};

    void            FlipArc(TArc a) throw(ERRange)
                        {X.FlipArc(a);};

    void            CancelArc(TArc a) throw(ERRange,ERRejected)
                        {X.CancelArc(a);};
    void            CancelNode(TNode v) throw(ERRange)
                        {X.CancelNode(v);};

    bool            HiddenNode(TNode v) throw(ERRange)
                        {return X.HiddenNode(v);};
    bool            HiddenArc(TArc a) throw(ERRange)
                        {return X.HiddenArc(a);};
    
    bool Planarize() throw (ERRejected)
    {
        OpenFold(ModPlanarity,NO_INDENT);

        LogEntry(LOG_METH,"Computing planar embedding...");

        // Store the regions in terms of arc predecessor lists
        // Reserve memory for n additional arcs
        TArc *predArc = new TArc[2*(m+n)];

        bool ret = PlanarityDMP64(predArc);
        
        if (ret)
        {
            OpenFold();
            LogEntry(LOG_METH,"Updating incidence lists...");

            X.Planarize(predArc);

            CloseFold();
        }

        delete[] predArc;

        if (ret) LogEntry(LOG_RES, "...Graph is planar");
        else LogEntry(LOG_RES, "...Graph is non-planar");

        // Add code for resorting the incidence lists here

        CloseFold(ModPlanarity,NO_INDENT);

        return ret;
    }


    void GrowExteriorFace() throw(ERRejected)
    {
        aExterior = X.GrowExteriorFace();
    }


    TNode InsertNode() throw(ERRejected)
    {
        n++;
        TNode ret = X.InsertNode();
        
        ReleaseAdjacencies();
        ReleasePartition();
        ReleaseDegrees();
       
        if (colour!=NULL)
        {
            colour = (TNode*)GoblinRealloc(colour,n*sizeof(TNode));
            colour[n-1] = NoNode;
        }
        
        if (d!=NULL)
        {
            d = (TFloat*)GoblinRealloc(d,n*sizeof(TFloat));
            d[n-1] = InfFloat;
        }

        if (pi!=NULL)
        {
            pi = (TFloat*)GoblinRealloc(pi,n*sizeof(TFloat));
            pi[n-1] = 0;
        }

        if (P!=NULL)
        {
            P = (TArc*)GoblinRealloc(P,n*sizeof(TArc));
            P[n-1] = NoArc;
        }
        
        return ret;
    }

    
    TNode InsertAlignmentPoint(TArc a) throw(ERRejected,ERRange)
    {
        ni++;
        return X.InsertAlignmentPoint(a);
    }


    TNode InsertBendNode(TNode v) throw(ERRejected,ERRange)
    {
        ni++;
        return X.InsertBendNode(v);
    }


    void ExplicitParallels() throw(ERRejected)
    {
        X.ExplicitParallels();
        m = X.M();
        
        if (Dim()>0) AutoArcAlignment();
    }


    void DeleteArcs() throw()
    {
        X.DeleteArcs();
        m = X.M();
        ni = X.NI();
    }
    
    
    void DeleteNodes() throw()
    {
        X.DeleteNodes();
        n = X.N();
        m = X.M();
        ni = X.NI();
    }

    void  ReleaseBendNodes(TArc a) throw(ERRange)
    {
        X.ReleaseBendNodes(a);
        ni = X.NI();
    }


    void  ReleaseAll() throw()
    {
        ReleaseAdjacencies();
        ReleaseEmbedding();
        ReleaseDegrees();
        ReleaseLabels();
        ReleasePotentials();
        ReleasePredecessors();
        ReleaseColours();
        ReleasePartition();
    }

    
    #include <genincl.h>
