view src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle-main/store/impl/logger/LoggingAttributes.cs @ 10:abe0c247f5a5

Add Network module. but, unComplete NetworkDefaultJungleTreeEditor.cs
author Kazuma Takeda <kazuma-arashi@hotmail.co.jp>
date Sun, 23 Oct 2016 07:40:50 +0900
parents
children
line wrap: on
line source

using UnityEngine;

public class LoggingAttributes {

	private TreeNode wrap;
	private OperationLog log;

	public LoggingAttributes(TreeNode _wrap,OperationLog _log)
	{
		wrap = _wrap;
		log = _log;
	}	

	public byte[] get(string _key)
	{
		TreeNodeAttributes attributes = wrap.getAttributes();
		return attributes.get(_key);
	}

	private Either<Error,LoggingNode> edit(NodeOperation _op)
	{
		Either<Error,TreeNode> either = _op.invoke(wrap);
		if(either.isA()){
			Debug.Log ("faild put");
			return DefaultEither<Error,LoggingNode>.newA(either.a());
		}

		TreeNode newNode = either.b();
		OperationLog newLog = log.add(_op); 
		LoggingNode newLogNode = new LoggingNode(newNode,newLog);

		return DefaultEither<Error,LoggingNode>.newB(newLogNode);
	}

	public Either<Error,LoggingNode> delete(string _key)
	{

		DeleteAttributeOperation deleteAttribute = new DeleteAttributeOperation(_key);
		return edit(deleteAttribute);
	}

	public Either<Error,LoggingNode> put(string _key, byte[] _value)
	{
		PutAttributeOperation putAttribute = new PutAttributeOperation(_key,_value);
		return edit(putAttribute);
	}

}