using UnityEngine; using System.Collections; using System.Collections.Generic; using System; using System.Text; using System.Runtime.Serialization.Formatters.Binary; using System.IO; namespace JungleDB { public class DefaultTreeNodeAttribute : TreeNodeAttributes { public List children; public TreeMap attrs; public DefaultTreeNodeAttribute(List _children, TreeMap _attrs){ children = _children; attrs = _attrs; } public TreeMap getAttributesAsRawMap(){ return attrs; } public Either delete(string _key) { if (_key == null) { return DefaultEither.newA (NodeEditorError.NULL_VALUE_NOT_ALLOWED); } if (null == attrs.getRoot()) { return DefaultEither.newA(NodeEditorError.DELETE_KEY_NOT_FOUND); } TreeMap newMap = attrs.delete(_key); TreeNode newNode = new DefaultTreeNode(children, newMap); return DefaultEither.newB(newNode); } public Either put(string _key, object _value){ if (_key == null || _value == null) { return DefaultEither.newA (NodeEditorError.NULL_VALUE_NOT_ALLOWED); } TreeMap newMap = attrs.put (_key, _value); TreeNode newNode = new DefaultTreeNode (children, newMap); return DefaultEither.newB (newNode); } public object get(string _key) { if (_key == null) return null; object op = attrs.get(_key); if (op != null) return op; return null; } public T get (string _key) { if (_key == null) return default(T); T op = (T)attrs.get (_key); if (op != null) return op; return default(T); } public string getString(string key) { return attrs.get(key).ToString(); } /// /// Gets the bytes. /// need Serializable to class. /// /// byte[] /// Key. public byte[] getBytes(string key) { var formatter = new BinaryFormatter(); object source = attrs.get (key); using (var stream = new MemoryStream()) { formatter.Serialize(stream, source); return stream.ToArray(); } } public IEnumerator getKeys(){ return attrs.keys (); } } }