View Javadoc

1   /*
2    * Copyright (c) 2001, Zoltan Farkas All Rights Reserved.
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this program; if not, write to the Free Software
16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17   */
18  
19  package net.sf.zel.vm;
20  
21  import java.util.HashMap;
22  import net.sf.zel.math.ExtendedMathContext;
23  
24  /**
25   * the memory implementation of the ZEL vm.
26   * @author zoly
27   */
28  public final class Memory extends HashMap
29  {
30      /**
31       * get a value from memory
32       */
33      public Object getValue(final String name) throws ParseException, ZExecutionException
34      {
35          return Program.getValue(this, name);
36      }
37  
38      /**
39       * add value to the memory (uses vm)
40       * @param name String
41       * @param value String
42       * @throws Exception
43       */
44      public void addValue(final String name, final Object value, final ExtendedMathContext mc) throws ParseException, ZExecutionException
45      {
46          Program.addValue(this, name, value, mc);
47      }
48  
49      public  void addValue(final String name, final Object value) throws ParseException, ZExecutionException
50      {
51          addValue(name, value, ExtendedMathContext.CURRENT_EXTENDED_MATH_CONTEXT.get());
52      }
53      /**
54       * Link hierarchical memory
55       * @param name String
56       * @param value Map
57       * @throws Exception
58       */
59      public  void linkMem(final String name, final java.util.Map value) throws ParseException, ZExecutionException
60      {
61          Program.linkMem(this, name, value);
62      }
63  
64  
65  
66      /**
67       * dump the core for this memory
68       */
69      public  String dumpCore()
70      {
71          return Program.dumpCore("[root]", this, 1, -1);
72      }
73  
74      /**
75       * dump the core for this maxLevel
76       */
77      public  String dumpCore(final int maxLevel)
78      {
79          return Program.dumpCore("[root]", this, 1, maxLevel + 1);
80      }
81  
82      /**
83       * to string for debug purposes, limited to descend max 2 levels
84       */
85      @Override
86      public String toString()
87      {
88          return dumpCore(2);
89      }
90  }