Class VariableManager

java.lang.Object
org.kigalisim.engine.state.VariableManager

public class VariableManager extends Object
Internal object which manages user defined variables at different scopes.

Manages variable storage and retrieval across different context levels, supporting variable shadowing and scope traversal.

  • Constructor Details

    • VariableManager

      public VariableManager(int contextLevel, Map<String,EngineNumber> globalContext, Map<String,EngineNumber> stanzaContext, Map<String,EngineNumber> applicationContext, Map<String,EngineNumber> substanceContext)
      Create a new variable manager.
      Parameters:
      contextLevel - The context level constant at which this manager will be used
      globalContext - Map from name of variable to value or null if no variables exist at that global level
      stanzaContext - Map from name of variable to value or null if no variables exist at that stanza level
      applicationContext - Map from name of variable to value or null if no variables exist at that application level
      substanceContext - Map from name of variable to value or null if no variables exist at that substance level
    • VariableManager

      public VariableManager(int contextLevel)
      Convenience constructor for creating a new variable manager at a specific context level.
      Parameters:
      contextLevel - The context level constant at which this manager will be used
  • Method Details

    • getWithLevel

      public VariableManager getWithLevel(int contextLevel)
      Make a new variable manager occupying this namespace but at a different context level.
      Parameters:
      contextLevel - Constant describing the new context level. If this matches the current context level, it is assumed adjacent to the current context.
      Returns:
      VariableManager at the given context level
    • defineVariable

      public void defineVariable(String name)
      Define a new variable in the current context level.

      Define a new variable in the current context level where an error will be thrown if a variable of the same name exists at this context level.

      Parameters:
      name - The name of the variable to define
    • setVariable

      public void setVariable(String name, EngineNumber value)
      Set the value of a variable already defined.

      Set the value of a variable already defined where an error will be thrown if a variable of this name has not been defined or is not accessible from the current scope.

      Parameters:
      name - The name of the variable to be set
      value - The new value of the variable
    • getVariable

      public EngineNumber getVariable(String name)
      Get the value of a variable already defined.

      Get the value of a variable already defined such that an error will be thrown if a variable of this name has not been defined or is not accessible from the current scope.

      Parameters:
      name - The name of the variable to be retrieved
      Returns:
      Current value of this variable