2018-09-23 12:15:14 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2023-02-22 18:43:48 +00:00
|
|
|
* (C) Copyright 2009-2024, Arnaud Roques
|
2018-09-23 12:15:14 +00:00
|
|
|
*
|
2023-02-22 18:43:48 +00:00
|
|
|
* Project Info: https://plantuml.com
|
2019-03-29 22:14:07 +00:00
|
|
|
*
|
2018-09-23 12:15:14 +00:00
|
|
|
* If you like this project or if you find it useful, you can support us at:
|
2019-03-29 22:14:07 +00:00
|
|
|
*
|
2023-02-22 18:43:48 +00:00
|
|
|
* https://plantuml.com/patreon (only 1$ per month!)
|
|
|
|
* https://plantuml.com/paypal
|
2019-03-29 22:14:07 +00:00
|
|
|
*
|
2018-09-23 12:15:14 +00:00
|
|
|
* This file is part of PlantUML.
|
|
|
|
*
|
|
|
|
* PlantUML is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PlantUML distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
|
|
* License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Original Author: Arnaud Roques
|
|
|
|
*
|
|
|
|
*/
|
2019-03-29 22:14:07 +00:00
|
|
|
package net.sourceforge.plantuml.tim;
|
2018-09-23 12:15:14 +00:00
|
|
|
|
|
|
|
import java.util.Collections;
|
2019-03-29 22:14:07 +00:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2019-05-24 19:59:31 +00:00
|
|
|
import java.util.Map.Entry;
|
2018-09-23 12:15:14 +00:00
|
|
|
import java.util.Set;
|
2019-05-24 19:59:31 +00:00
|
|
|
import java.util.TreeMap;
|
|
|
|
|
|
|
|
import net.sourceforge.plantuml.tim.expression.TValue;
|
2022-12-17 11:01:10 +00:00
|
|
|
import net.sourceforge.plantuml.utils.Log;
|
2018-09-23 12:15:14 +00:00
|
|
|
|
2020-03-03 22:29:34 +00:00
|
|
|
public class TMemoryGlobal extends ExecutionContexts implements TMemory {
|
2018-09-23 12:15:14 +00:00
|
|
|
|
2020-03-03 22:29:34 +00:00
|
|
|
private final Map<String, TValue> globalVariables = new HashMap<String, TValue>();
|
2019-08-26 17:07:21 +00:00
|
|
|
private final TrieImpl variables = new TrieImpl();
|
2018-09-23 12:15:14 +00:00
|
|
|
|
2020-03-03 22:29:34 +00:00
|
|
|
public TValue getVariable(String varname) {
|
2019-03-29 22:14:07 +00:00
|
|
|
return this.globalVariables.get(varname);
|
|
|
|
}
|
|
|
|
|
2019-05-24 19:59:31 +00:00
|
|
|
public void dumpDebug(String message) {
|
|
|
|
Log.error("[MemGlobal] Start of memory_dump " + message);
|
|
|
|
dumpMemoryInternal();
|
|
|
|
Log.error("[MemGlobal] End of memory_dump");
|
|
|
|
}
|
|
|
|
|
|
|
|
void dumpMemoryInternal() {
|
|
|
|
Log.error("[MemGlobal] Number of variable(s) : " + globalVariables.size());
|
2020-03-03 22:29:34 +00:00
|
|
|
for (Entry<String, TValue> ent : new TreeMap<String, TValue>(globalVariables).entrySet()) {
|
2019-05-24 19:59:31 +00:00
|
|
|
final String name = ent.getKey();
|
2020-03-03 22:29:34 +00:00
|
|
|
final TValue value = ent.getValue();
|
2019-05-24 19:59:31 +00:00
|
|
|
Log.error("[MemGlobal] " + name + " = " + value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-03 22:29:34 +00:00
|
|
|
public void putVariable(String varname, TValue value, TVariableScope scope) throws EaterException {
|
2019-05-24 19:59:31 +00:00
|
|
|
Log.info("[MemGlobal] Setting " + varname);
|
|
|
|
if (scope == TVariableScope.LOCAL) {
|
2020-03-03 22:29:34 +00:00
|
|
|
throw EaterException.unlocated("Cannot use local variable here");
|
2019-05-24 19:59:31 +00:00
|
|
|
}
|
2019-03-29 22:14:07 +00:00
|
|
|
this.globalVariables.put(varname, value);
|
|
|
|
this.variables.add(varname);
|
|
|
|
}
|
2018-09-23 12:15:14 +00:00
|
|
|
|
2019-05-24 19:59:31 +00:00
|
|
|
public void removeVariable(String varname) {
|
|
|
|
this.globalVariables.remove(varname);
|
|
|
|
this.variables.remove(varname);
|
|
|
|
}
|
|
|
|
|
2019-03-29 22:14:07 +00:00
|
|
|
public boolean isEmpty() {
|
|
|
|
return globalVariables.isEmpty();
|
2018-09-23 12:15:14 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 22:14:07 +00:00
|
|
|
public Set<String> variablesNames() {
|
|
|
|
return Collections.unmodifiableSet(globalVariables.keySet());
|
2018-09-23 12:15:14 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 22:14:07 +00:00
|
|
|
public Trie variablesNames3() {
|
|
|
|
return variables;
|
2018-09-23 12:15:14 +00:00
|
|
|
}
|
|
|
|
|
2020-03-03 22:29:34 +00:00
|
|
|
public TMemory forkFromGlobal(Map<String, TValue> input) {
|
2019-05-24 19:59:31 +00:00
|
|
|
return new TMemoryLocal(this, input);
|
2018-09-23 12:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|