Package org.kigalisim.engine.state
Class VariableManager
java.lang.Object
org.kigalisim.engine.state.VariableManager
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 Summary
ConstructorsConstructorDescriptionVariableManager(int contextLevel) Convenience constructor for creating a new variable manager at a specific context level.VariableManager(int contextLevel, Map<String, EngineNumber> globalContext, Map<String, EngineNumber> stanzaContext, Map<String, EngineNumber> applicationContext, Map<String, EngineNumber> substanceContext) Create a new variable manager. -
Method Summary
Modifier and TypeMethodDescriptionvoiddefineVariable(String name) Define a new variable in the current context level.getVariable(String name) Get the value of a variable already defined.getWithLevel(int contextLevel) Make a new variable manager occupying this namespace but at a different context level.voidsetVariable(String name, EngineNumber value) Set the value of a variable already defined.
-
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 usedglobalContext- Map from name of variable to value or null if no variables exist at that global levelstanzaContext- Map from name of variable to value or null if no variables exist at that stanza levelapplicationContext- Map from name of variable to value or null if no variables exist at that application levelsubstanceContext- 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
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
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
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 setvalue- The new value of the variable
-
getVariable
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
-