// $Source: /usr/local/SimSoft/SoftShop/ExeContx/execontx.h,v $
// $Revision: 1.14 $
// $Author: baum $
// $Date: 2001/11/29 15:52:23 $
//
// Login name of the user who locked the revision
// $Locker:  $
// Tag name used to checkout the file
// $Name:  $
// State assigned to revision
// $State: Exp $
//
//
// $Log: execontx.h,v $
// Revision 1.14  2001/11/29 15:52:23  baum
// -In Kalender.cpp und Kalender.h Handsteuerung eingebaut
//


#if !defined _EXECONTX_H
#define _EXECONTX_H


#include <setjmp.h>


#ifdef _EXECONTX_CPP
#  undef _impexp
#  define _impexp __declspec(dllexport)
#elif defined BUILD_EXECONTEXT_DLL
#  undef _impexp
#  define _impexp 
#else
#  undef _impexp
#  define _impexp __declspec(dllimport)
#endif

#if defined __GNUC__ || defined __hpux
#  undef _impexp
#  define _impexp
#endif


class _impexp ExeContxt
  {
  public:
    // constructors
    ExeContxt ();

    // set fixed end of stack to the parameter's value
    ExeContxt (char* stackStart);

    // destructor
    ~ExeContxt ();

    // set fixed end of stack to the parameter's value and return it
    char* setStackStart (char*);

    // return true, if usage has been prepared (StackStart set), else false
    bool isUsable () const;

    // save Stack and Registers, return 0 upon save, non-0 upon restore
    int save ();

    // restore Stack and Registers, return is non-0 return from save
    void restore ();

    // call save () for "this" and restore () for "to"
    void switchTo (ExeContxt& to);

    // return true if verbose-Mode is on, else false
    static bool isVerbose ();

    // set verbose-Mode to newVal, return its previous value
    static bool setVerbose (bool newVal = false);

    // setting/cleaning things up
    static void setup ();
    static void cleanup ();
    static bool isInitialized ();

  private:
    // copy constructor (declared, but not defined)
    ExeContxt (const ExeContxt&);

    // assignment operator (declared, but not defined)
    ExeContxt& operator = (const ExeContxt&);

    // reserve space for a stack to be saved and later restored
    unsigned getMemory (unsigned bytes = 0);

    // return the memory allocated for the stack
    void freeMemory ();

    // save the stack
    void saveStack (char mark = 0);

    // restore stack and registers
    void restoreStackAndRegs (char mark = 0);

    // data members
    // SaverESP und SaverEBP muessen die ersten data-member bleiben
    // da die asm-Teile in execontx.cpp davon abhaengen
#if defined __BORLANDC__
    void* SaverESP;
    void* SaverEBP;
    void* SaverEBX;
    void* SaverESI;
    void* SaverEDI;
#else
    jmp_buf Regs;
#endif
    char* StackFix;
    char* StackFloat;
    unsigned MemStart;
    unsigned MemSize;

    // these are needed for memory-management
    static unsigned UnitSize;
    static unsigned UnitsAdd;
    static unsigned UnitsTotal;
    static char* Memory;
    static char* Flags;
    static bool Verbose;
    static bool IsInitialized;
  };	// class ExeContxt


#endif	// !defined _EXECONTX_H

//	$FileName: ExeContx.h $	ends
