//========================================================================================================
// E library
//
// - State-machine functions (e.g. for reading hierarchical ASCII files
//
// AUTHOR:  Gabor Nagy
// DATE:    2014-Feb-26 23:20:34
//
// Copyright (C) 1996-2026 By Gabor Nagy. All rights reserved.
//========================================================================================================
#ifndef _EStateMachine_h
#define _EStateMachine_h


#if defined (__cplusplus) && (!(defined (__CPLUSLIBS)))
extern "C" {
#endif

//----------------------------------------------------------------
// State-machine (e.g. for reading hierarchical ASCII files
//----------------------------------------------------------------
static inline int E_PushState(MState* PDState)
{
	if(PDState->ValueStackPtr < VALUE_STACK_DEPTH - 1)
	{
		PDState->ValueStackPtr += 1;
		MValue*  LValue = PDState->ValueStack + PDState->ValueStackPtr;

		memset(LValue, 0, sizeof(MValue));
		return(E_SUCCESS);
	}
	else return(E_OVERFLOW);
}

static inline int E_PopState(MState* PDState)
{
	if(PDState->ValueStackPtr > 0) { PDState->ValueStackPtr -= 1;return(E_SUCCESS); }
	else return(E_UNDERFLOW);
}


#if defined (__cplusplus) && (!(defined (__CPLUSLIBS)))
}	// Close scope of 'extern "C"' declaration
#endif



#endif // _EStateMachine_h
