#pragma once
#include <xsi_application.h>
#include <xsi_string.h>
#include <xsi_value.h>

//************** save/get data
const CStatus GetSavedData(CString in_varname, LONG &out_val)
{
	CValue retval;
	CValueArray args(1);
	args[0] = in_varname;
	Application().ExecuteCommand( L"GetGlobal", args, retval );
	out_val = (LONG)retval;
#ifdef _DEBUG
	Application().LogMessage(L"Loading data:"+ in_varname + CString( out_val ) );
#endif
	return retval.IsEmpty() ? CStatus::Fail : CStatus::OK;
}	
CStatus GetSavedData(CString in_varname, double &out_val)
{
	CValue retval;
	CValueArray args(1);
	args[0] = in_varname;
	Application().ExecuteCommand( L"GetGlobal", args, retval );
	out_val = (double)retval;
#ifdef _DEBUG
	Application().LogMessage(L"Loading data:"+ in_varname + CString( out_val ) );
#endif
	return retval.IsEmpty() ? CStatus::Fail : CStatus::OK;
}	
const CStatus GetSavedData(CString in_varname, CRef &out_val)
{
	CValue retval;
	CValueArray args(1);
	args[0] = in_varname;
	Application().ExecuteCommand( L"GetGlobal", args, retval );
	out_val = retval;
#ifdef _DEBUG
	Application().LogMessage(L"Loading data:"+ in_varname + CString( out_val ) );
#endif
	return retval.IsEmpty() ? CStatus::Fail : CStatus::OK;
}

const void SaveData( LONG in_value,CString in_varname )
{
#ifdef _DEBUG
	Application().LogMessage(L"Saving data:"+ in_varname + CString( in_value ) );
#endif
	CValue retval;
	CValueArray args(2);
	args[0] = in_varname;
	args[1] = in_value;
	Application().ExecuteCommand( L"SetGlobal", args, retval );
}

const void SaveData( double in_value,CString in_varname )
{
#ifdef _DEBUG
	Application().LogMessage(L"Saving data:"+ in_varname + CString( in_value ) );
#endif
	CValue retval;
	CValueArray args(2);
	args[0] = in_varname;
	args[1] = CValue(in_value);
	Application().ExecuteCommand( L"SetGlobal", args, retval );
}