diff src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle-main/store/impl/logger/LoggingChildren.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 diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle-main/store/impl/logger/LoggingChildren.cs	Sun Oct 23 07:40:50 2016 +0900
@@ -0,0 +1,59 @@
+using System.Collections;
+using UnityEngine;
+
+public class LoggingChildren {
+	private TreeNode wrap;
+	private OperationLog log;
+
+	public LoggingChildren(TreeNode _wrap,OperationLog _log)
+	{
+		wrap = _wrap;
+		log = _log;
+	}
+
+	public int size()
+	{
+		Children children = wrap.getChildren();
+		return children.size();
+	}
+
+	public Either<Error,LoggingNode> edit(NodeOperation _op)
+	{
+		Either<Error,TreeNode> either = _op.invoke(wrap);
+		if(either.isA()){
+			return DefaultEither<Error,LoggingNode>.newA(either.a());
+		}
+
+		TreeNode newWrap = either.b();
+		OperationLog newLog = log.add(_op);
+		LoggingNode newLoggingNode = new LoggingNode(newWrap,newLog);
+		return DefaultEither<Error,LoggingNode>.newB(newLoggingNode);
+	}
+
+	public Either<Error,LoggingNode> addNewChildAt(int _pos)
+	{
+		Debug.Log ("in addNewChild");
+		NodeOperation addNewChildAt = new AppendChildAtOperation(_pos);
+		return edit(addNewChildAt);
+	}
+
+	public Either<Error,LoggingNode> deleteChildAt(int _pos)
+	{
+		NodeOperation deleteChildAt = new DeleteChildAtOperation(_pos);
+		return edit(deleteChildAt);
+	}
+
+	public Either<Error,LoggingNode> at(int _pos)
+	{
+		Children children = wrap.getChildren();
+		Either<Error,TreeNode> either = children.at(_pos);
+		if(either.isA()){
+			return DefaultEither<Error,LoggingNode>.newA(either.a());
+		}
+
+		TreeNode node = either.b();
+		LoggingNode logNode = new LoggingNode(node);
+		return DefaultEither<Error,LoggingNode>.newB(logNode);
+	}
+
+}