ff_i_vars

Variable helper functions.

Get/set helpers for typed local variables with default-value support, and utilities for copying variable sets between objects.

int GetLocalBoolean(object oObject, string sVariable, int nDefault = FALSE)
Parameters:
  • oObject – The object

  • sVariable – Name of the local string variable holding “T”/”F” (or synonyms).

  • nDefault – Value returned when the variable is absent or empty. Defaults to FALSE.

Return TRUE/FALSE depending on the value “T” or “F”.

int GetRecursiveInt(object oObject, string sVariable, int nDefault = FALSE)
Parameters:
  • oObject – An object.

  • sVariable – Variable name.

  • nDefault – Value returned when no level has the variable set. Defaults to FALSE.

Read an int variable from oObject, then its area, then the module, returning the first non-zero value.

Source code

// @code

#include "ff_i_expect"


// -----------------------------------------------------------------------------

//! @brief Return TRUE/FALSE depending on the value "T" or "F".
//! @param oObject The object
//! @param sVariable Name of the local string variable holding "T"/"F" (or synonyms).
//! @param nDefault Value returned when the variable is absent or empty. Defaults to FALSE.
int GetLocalBoolean(object oObject, string sVariable, int nDefault = FALSE);
int GetLocalBoolean(object oObject, string sVariable, int nDefault = FALSE)
{
  Assert(nDefault == TRUE || nDefault == FALSE, __FILE__, __LINE__);

  string sValue = GetLocalString(oObject, sVariable);
  sValue = GetStringUpperCase(sValue);

  if (sValue == "Y" || sValue == "YES" || sValue == "TRUE" || sValue == "T")
    return TRUE;
  if (sValue == "N" || sValue == "NO" || sValue == "FALSE" || sValue == "F")
    return FALSE;

  Assert(sValue == "", __FILE__, __LINE__, GetName(GetArea(oObject)) + "::" + GetName(oObject));
  Assert(GetLocalInt(oObject, sVariable) == 0, __FILE__, __LINE__);

  return nDefault;
}


// -----------------------------------------------------------------------------

//! @brief Read an int variable from oObject, then its area, then the module, returning the first non-zero value.
//! @param oObject An object.
//! @param sVariable Variable name.
//! @param nDefault Value returned when no level has the variable set. Defaults to FALSE.
int GetRecursiveInt(object oObject, string sVariable, int nDefault = FALSE);
int GetRecursiveInt(object oObject, string sVariable, int nDefault = FALSE)
{
  int nValue = GetLocalInt(oObject, sVariable);
  if (nValue)
    return nValue;

  nValue = GetLocalInt(GetArea(oObject), sVariable);
  if (nValue)
    return nValue;

  nValue = GetLocalInt(GetModule(), sVariable);
  if (nValue)
    return nValue;
  return nDefault;
}