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


#if !defined(_CONTEXT_H_)

#define _CONTEXT_H_

#include <globals.h>


#if defined(_LINUX_GCC_)

const unsigned long goblinRandMax   = RAND_MAX;

#else

const unsigned long goblinRandMax   = (RAND_MAX+1)*(RAND_MAX+1);

#endif



class goblinAbstractObject
{
public:

    virtual char *          Display() throw(ERFile,ERRejected) = 0;
    virtual char *          Label() throw() = 0;
    virtual unsigned long   Size() throw() = 0;
    virtual char            IsGraphObject() {return 0;};
    virtual objectType      ClassID() throw() {return IDUnknown;};

};


class goblinController
{
friend class goblinExport;
private:
    
    unsigned long   size;
    unsigned long   maxSize;
    
    char        externalPrecision;
    char        externalFloatLength;
    TNode       maxNode;
    TArc        maxArc;
    long int    maxInt;
    
    int     savedLogMeth;
    int     savedLogMem;
    int     savedLogMan;
    int     savedLogIO;
    int     savedLogRes;
    int     savedLogWarn;
    int     savedTraceLevel;

    unsigned short logLevel;
    int            breakPoint;
    unsigned long  traceCounter;
    
    char        isDefault;
    
public:

    goblinController() throw();
    goblinController(goblinController&) throw();
    ~goblinController() throw();
    
    
    int             FindParam(int pc,char *pStr[],char *token) throw();
    void            Configure(int ParamCount,char* ParamStr[]) throw();

    void            ReadConfiguration(char *) throw(ERFile,ERParse);
    void            WriteConfiguration(char *) throw(ERFile);
    
    char *          objectExtension;

    TNode           sourceNode;
    TNode           targetNode;
    TNode           rootNode;
    
    // *************************************************************** //
    //           Memory Management                                     //
    // *************************************************************** //
    
    char            checkMem;

    unsigned long   Size() throw();
    unsigned long   MaxSize() throw() {return maxSize;};
    void            IncreaseSize(unsigned long) throw();
    void            DecreaseSize(unsigned long) throw();


    // *************************************************************** //
    //           Object Management                                     //
    // *************************************************************** //

    goblinAbstractObject *  masterObject;
    THandle                 masterHandle;
    THandle                 objCounter;
    goblinAbstractObject ** pObject;

    THandle         InsertObject(goblinAbstractObject*) throw(ERRejected);
    goblinAbstractObject* ObjectPointer(THandle) throw(ERRejected);
    void            DeleteObject(THandle) throw(ERRejected);
    void            StripObjects() throw();
    void            SetMaster(THandle) throw(ERRejected);
    THandle         Master() throw(ERCheck);
    char *          Label() throw();

    // *************************************************************** //
    //           Logging                                               //
    // *************************************************************** //

    int     logMeth;
    int     logMem;
    int     logMan;
    int     logIO;
    int     logRes;
    int     logWarn;

    int     logDepth;
    
    void IncreaseLogLevel() throw(ERRejected);
    void DecreaseLogLevel() throw(ERRejected);
    void SuppressLogging() throw();
    void RestoreLogging() throw();
    ostream &Log() throw() {return clog;};
    ostream &Error(THandle,char * = NULL) throw();
    ostream &Align() throw();

    
    // *************************************************************** //
    //           Graph Browser                                         //
    // *************************************************************** //

    int    displayMode;
    int    hiddenObjects;
    
    int    xShift;
    int    yShift;
    double xZoom;
    double yZoom;
    
    int    nodeSize;
    int    arrowSize;
    int    legenda;
    int    nodeSep;

    int    nodeStyle;
    int    nodeLabels;
    int    nodeColours;
    int    arcStyle;
    int    arcLabels;
    int    arcLabels2;
    int    arrows;
    int    arrowColours;
    int    subgraph;
    int    predecessors;

    
    // *************************************************************** //
    //           Tracing                                               //
    // *************************************************************** //

    int             traceLevel;
    int             traceData;
    int             threshold;
    int             fileCounter;
    int             traceStep;

    void    Ping(THandle HH,unsigned long priority) throw(ERRejected);
    void    ResetCounters() throw();
    void    IncreaseCounter()
        {if (fileCounter<10000) fileCounter++; else fileCounter = 0;};
    ostream &Display() throw();

    
    // *************************************************************** //
    //           Selection of mathematical methods                     //
    // *************************************************************** //

    int     methFailSave;
    int     methGeometry;
    int     methSearch;
    int     methAdjacency;
    int     methMaxFlow;
    int     methMinCFlow;
    int     methMinCCirc;
    int     methMinTree;
    int     meth1Tree;
    int     methMaxBalFlow;
    int     methBNS;
    int     methDSU;
    int     methPQ;
    int     methTSP;
    int     methLocal;
    int     methSolve;
    int     methMinCBalFlow;
    int     methPrimalDual;
    int     methModLength;
    int     methCandidates;
    int     methColour;

    int     maxBBIterations;
    int     maxBBNodes;

    
    // *************************************************************** //
    //           Random Generators                                     //
    // *************************************************************** //
    
    unsigned long   Rand(unsigned long) throw(ERRange);
    TFloat          Rand() throw();
    void            SetRandomBounds(long int,long int) throw(ERRejected);

    int     randMin;
    int     randMax;
    
    int     randUCap;
    int     randLCap;
    int     randLength;
    int     randGeometry;
    int     randParallels;
    
    
    // Precision and External Number Formats
        
    TFloat  epsilon;
    TFloat  tolerance;
    
    void    SetExternalPrecision(char) throw(ERRejected);
    void    SetMaxInt(long int) throw(ERRejected);
    long int MaxInt() throw() {return maxInt;};
    void    SetMaxArc(TArc) throw(ERRejected);
    TArc    MaxArc() throw() {return maxArc;};
    void    SetMaxNode(TNode) throw(ERRejected);
    TNode   MaxNode() throw() {return maxNode;};

    char    ExternalLength(TFloat) throw();
    
    int     signalHalt;

};


extern goblinController goblinDefaultContext;


#endif
