Revision: 20787
          http://sourceforge.net/p/jmol/code/20787
Author:   hansonr
Date:     2015-09-22 04:52:10 +0000 (Tue, 22 Sep 2015)
Log Message:
-----------
Jmol.___JmolVersion="14.3.16_2015.09.21b"

new feature: x = @a
  -- deep copy for a = array or associative array
  -- @a for string variable still gets the value of the variable named by a
    
note: "deepCopy":

 function deepCopy(a) {
  switch (a.type) {
  case "hash":
    var b = {};
    for (var key in a)
      b[key] = deepCopy(a[key]);
    return b;
  case "array":
    var b = [];
    for (var j = a.length; j > 0; --j) 
      b[j] = deepCopy(a[j]);
    return b;
  default:
    return a;
  }
}


new feature: for allows one continuation line, as in JavaScript and Java
  -- for example:
        for (i = 1; i <= 3; i++)
          print i;

bug fix: for (key in hash){...} fails upon functional iteration (deepCopy)
  -- code was reusing the FOR variable when it should have been caching it in 
the context stack
  

Modified Paths:
--------------
    trunk/Jmol/src/org/jmol/script/SV.java
    trunk/Jmol/src/org/jmol/script/ScriptExpr.java
    trunk/Jmol/src/org/jmol/viewer/Jmol.properties

Modified: trunk/Jmol/src/org/jmol/script/SV.java
===================================================================
--- trunk/Jmol/src/org/jmol/script/SV.java      2015-09-22 04:03:42 UTC (rev 
20786)
+++ trunk/Jmol/src/org/jmol/script/SV.java      2015-09-22 04:52:10 UTC (rev 
20787)
@@ -1458,6 +1458,7 @@
 
   /**
    * Turn the string "({3:5})" into a bitset
+   * @param x 
    * 
    * @param bs
    * @return a bitset or a string converted to one
@@ -1671,4 +1672,36 @@
     }
   }
 
+  @SuppressWarnings("unchecked")
+  public static Object deepCopy(Object v, boolean isHash) {
+    if (isHash) {
+      Map<String, SV> vnew = new Hashtable<String, SV>();
+      Map<String, SV> vold = (Map<String, SV>) v;
+      for (Entry<String, SV> e : vold.entrySet()) {
+        SV vm = e.getValue();
+        switch (vm.tok) {
+        case hash:
+        case varray:
+          vm = newV(vm.tok, deepCopy(vm.value, vm.tok == hash));
+          break;
+        }
+        vnew.put(e.getKey(), vm);
+      }
+      return vnew;
+    }
+    Lst<SV> vnew2 = new Lst<SV>();
+    Lst<SV> vold2 = (Lst<SV>) v;
+    for (int i = 0, n = vold2.size(); i < n; i++) {
+      SV vm = vold2.get(i);
+      switch (vm.tok) {
+      case hash:
+      case varray:
+        vm = newV(vm.tok, deepCopy(vm.value, vm.tok == hash));
+        break;
+      }
+      vnew2.addLast(vm);
+    }
+    return vnew2;
+  }
+
 }

Modified: trunk/Jmol/src/org/jmol/script/ScriptExpr.java
===================================================================
--- trunk/Jmol/src/org/jmol/script/ScriptExpr.java      2015-09-22 04:03:42 UTC 
(rev 20786)
+++ trunk/Jmol/src/org/jmol/script/ScriptExpr.java      2015-09-22 04:52:10 UTC 
(rev 20787)
@@ -2530,12 +2530,16 @@
         } else if (v instanceof M34) {
           fixed[j] = SV.newV(v instanceof M4 ? T.matrix4f : T.matrix3f, v);
         } else if (v instanceof Map<?, ?>) {
-          fixed[j] = SV.newV(T.hash, v);
+          fixed[j] = SV.newV(T.hash, (isExpression ? v : SV.deepCopy(v, 
true)));
         } else if (v instanceof ScriptContext) {
           fixed[j] = SV.newV(T.hash, ((ScriptContext) v).getFullMap());
         } else if (v instanceof Lst<?>) {
           // if v is a list, we check to to see if it is an array of 
           // bitsets, and it if is, we OR all those.
+          if (!isExpression) {
+            fixed[j] = SV.newV(T.varray, SV.deepCopy(v, false));
+            break;
+          }
           Lst<SV> sv = (Lst<SV>) v;
           BS bs = null;
           for (int k = 0; k < sv.size(); k++) {

Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties
===================================================================
--- trunk/Jmol/src/org/jmol/viewer/Jmol.properties      2015-09-22 04:03:42 UTC 
(rev 20786)
+++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties      2015-09-22 04:52:10 UTC 
(rev 20787)
@@ -63,6 +63,30 @@
 
 Jmol.___JmolVersion="14.3.16_2015.09.21b"
 
+new feature: x = @a
+  -- deep copy for a = array or associative array
+  -- @a for string variable still gets the value of the variable named by a
+    
+note: "deepCopy":
+
+ function deepCopy(a) {
+  switch (a.type) {
+  case "hash":
+    var b = {};
+    for (var key in a)
+      b[key] = deepCopy(a[key]);
+    return b;
+  case "array":
+    var b = [];
+    for (var j = a.length; j > 0; --j) 
+      b[j] = deepCopy(a[j]);
+    return b;
+  default:
+    return a;
+  }
+}
+
+
 new feature: for allows one continuation line, as in JavaScript and Java
   -- for example:
        for (i = 1; i <= 3; i++)

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to