[Mathlib-commitlog] SF.net SVN: mathlib:[624] JMathLib/trunk/src/jmathlib/toolbox/general/ global.j
Status: Beta
Brought to you by:
st_mueller
|
From: <st_...@us...> - 2009-01-05 15:11:58
|
Revision: 624
http://mathlib.svn.sourceforge.net/mathlib/?rev=624&view=rev
Author: st_mueller
Date: 2009-01-05 15:11:55 +0000 (Mon, 05 Jan 2009)
Log Message:
-----------
changed handling of global variables
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/toolbox/general/global.java
Modified: JMathLib/trunk/src/jmathlib/toolbox/general/global.java
===================================================================
--- JMathLib/trunk/src/jmathlib/toolbox/general/global.java 2009-01-05 15:10:21 UTC (rev 623)
+++ JMathLib/trunk/src/jmathlib/toolbox/general/global.java 2009-01-05 15:11:55 UTC (rev 624)
@@ -23,20 +23,54 @@
debugLine("global "+operands[0].toString());
- debugLine("global: local variable:"+getVariables().isVariable(var.getName()));
+ debugLine("global: local variable:"+getLocalVariables().isVariable(var.getName()));
debugLine("global: global variable:"+getGlobalVariables().isVariable(var.getName()));
+ // this is the procedure for global variables:
+ // - normally all variables a local to each workspace
+ // - the "global" workspace is a totally separate workspace
+ // - each workspace which defines a variable as global will
+ // use the "global" workspace instead of its own local workspace
+ // - in case a variable is defined as "global" in one workspace and
+ // "local" in another workspace, the local workspace will work
+ // with the "local" variable whereas the "global-one" will work
+ // with the "global" variable
+ // -> ALL indidivual workspaces which like to use the "global"
+ // version of a variable need to call "global variable-name"
+
+
// check if variable is already created in global context
if (getGlobalVariables().isVariable(name))
{
// variable is already created in global context
- // check if current context already contains variable
- if (getVariables().isVariable(name))
+ // check if local context already contains variable
+ if (getLocalVariables().isVariable(name))
{
- // remove variable from current workspace
- getVariables().remove(name);
+ // variable is already created in local context
+
+ // remove variable from current workspace (may delete current value)
+ // create empty variable and set pointer to "global" property
+ getLocalVariables().remove(name);
+ getLocalVariables().createVariable(name);
+ getLocalVariables().getVariable(name).setGlobal(true);
+
+ getInterpreter().displayText("WARNING global: variable "+name+
+ " already existed in the local workspace. \n"+
+ " It has been overwritten with the value from"+
+ " the global workspace.\n" +
+ " please type: global variable\n"+
+ " before using a variable as global.");
}
+ else
+ {
+ // variable is not yet created in local context
+
+ // create empty variable and set "global" property
+ getLocalVariables().createVariable(name);
+ getLocalVariables().getVariable(name).setGlobal(true);
+
+ }
}
else
{
@@ -47,29 +81,26 @@
getGlobalVariables().getVariable(name).setGlobal(true);
// check if current context already contains variable
- if (getVariables().isVariable(name))
+ if (getLocalVariables().isVariable(name))
{
// current context already contains variable
- Variable varCurrent = getVariables().getVariable(name);
+ Variable varCurrent = getLocalVariables().getVariable(name);
getGlobalVariables().getVariable(name).assign(varCurrent.getData());
// remove variable, create new one and set variable to global
- getVariables().remove(name);
+ getLocalVariables().remove(name);
}
}
// create new variable in current context and set variable to global
- getVariables().createVariable(name);
- getVariables().getVariable(name).setGlobal(true);
+ getLocalVariables().createVariable(name);
+ getLocalVariables().getVariable(name).setGlobal(true);
debugLine("global:global var:"+name+" global="+getGlobalVariables().getVariable(name).isGlobal());
-
-
- debugLine("global:local var:"+name+" global="+getVariables().getVariable(name).isGlobal());
-
+ debugLine("global:local var:"+name+" global="+getLocalVariables().getVariable(name).isGlobal());
+
-
return null;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|