Skip to content

Commit

Permalink
fixed missing namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
kimsama committed May 23, 2016
1 parent be3cca7 commit ca46956
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 162 deletions.
1 change: 1 addition & 0 deletions Assets/QuickSheet/GDataPlugin/Templates/AssetFileClass.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using UnityEngine;
using UnityEditor;
using System.IO;
using UnityQuicksheet;

///
/// !!! Machine generated code !!!
Expand Down
1 change: 1 addition & 0 deletions Assets/QuickSheet/GDataPlugin/Templates/DataClass.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using UnityEngine;
using System.Collections;
using UnityQuicksheet;

///
/// !!! Machine generated code !!!
Expand Down
1 change: 1 addition & 0 deletions Assets/QuickSheet/GDataPlugin/Templates/Property.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[SerializeField]
string $FieldName;
using UnityQuicksheet;

[ExposeProperty]
public string $CapitalFieldName { get {return $FieldName; } set { $FieldName = value;} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityQuicksheet;

///
/// !!! Machine generated code !!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ using System.Text;
using GDataDB;
using GDataDB.Linq;

using UnityQuicksheet;

///
/// !!! Machine generated code !!!
///
Expand Down
98 changes: 51 additions & 47 deletions Assets/QuickSheet/Util/Cloner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,68 @@
using System.Collections;
using System.Reflection;

///
/// Cloner which do deep copy of an array or class instance.
///
/// See Also:
/// http://www.codeproject.com/Articles/38270/Deep-copy-of-objects-in-C
///
/// CAUTION:
/// For an inheritance case, deep copying all member fields of the ancestor are not tested.
///
public class Cloner
namespace UnityQuicksheet
{
public static T DeepCopy<T>(T obj)
{
if(obj==null)
throw new ArgumentNullException("Object cannot be null");
return (T)Process(obj);
}

static object Process(object obj)
///
/// Cloner which do deep copy of an array or class instance.
///
/// See Also:
/// http://www.codeproject.com/Articles/38270/Deep-copy-of-objects-in-C
///
/// CAUTION:
/// For an inheritance case, deep copying all member fields of the ancestor are not tested.
///
public class Cloner
{
if(obj==null)
return null;
Type type=obj.GetType();
if(type.IsValueType || type==typeof(string))
public static T DeepCopy<T>(T obj)
{
return obj;
if (obj == null)
throw new ArgumentNullException("Object cannot be null");
return (T)Process(obj);
}
else if(type.IsArray)

static object Process(object obj)
{
Type elementType=Type.GetType(
type.FullName.Replace("[]",string.Empty));

var array=obj as Array;
Array copied=Array.CreateInstance(elementType,array.Length);
for(int i=0; i<array.Length; i++)
if (obj == null)
return null;
Type type = obj.GetType();
if (type.IsValueType || type == typeof(string))
{
copied.SetValue(Process(array.GetValue(i)),i);
return obj;
}
return Convert.ChangeType(copied,obj.GetType());
}
else if(type.IsClass)
{
object toret=Activator.CreateInstance(obj.GetType());

FieldInfo[] fields=type.GetFields(BindingFlags.Public |
BindingFlags.NonPublic|BindingFlags.Instance);
else if (type.IsArray)
{
Type elementType = Type.GetType(
type.FullName.Replace("[]", string.Empty));

foreach(FieldInfo field in fields)
var array = obj as Array;
Array copied = Array.CreateInstance(elementType, array.Length);
for (int i = 0; i < array.Length; i++)
{
copied.SetValue(Process(array.GetValue(i)), i);
}
return Convert.ChangeType(copied, obj.GetType());
}
else if (type.IsClass)
{
object fieldValue=field.GetValue(obj);
if(fieldValue==null)
continue;
field.SetValue(toret,Process(fieldValue));
object toret = Activator.CreateInstance(obj.GetType());

FieldInfo[] fields = type.GetFields(BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Instance);

foreach (FieldInfo field in fields)
{
object fieldValue = field.GetValue(obj);
if (fieldValue == null)
continue;
field.SetValue(toret, Process(fieldValue));
}
return toret;
}
return toret;
else
throw new ArgumentException("Unknown type");
}
else
throw new ArgumentException("Unknown type");

}

}
193 changes: 98 additions & 95 deletions Assets/QuickSheet/Util/CsvParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,130 +4,133 @@
using System.IO;
using System.Text;

public enum TokenType
namespace UnityQuicksheet
{
Comma,
Quote,
Value
}

public class Token
{
public Token(TokenType type, string value)
public enum TokenType
{
Value = value;
Type = type;
Comma,
Quote,
Value
}

public String Value { get; private set; }
public TokenType Type { get; private set; }
}

public class StreamTokenizer : IEnumerable<Token>
{
private TextReader _reader;

public StreamTokenizer(TextReader reader)
public class Token
{
_reader = reader;
public Token(TokenType type, string value)
{
Value = value;
Type = type;
}

public String Value { get; private set; }
public TokenType Type { get; private set; }
}

public IEnumerator<Token> GetEnumerator()
public class StreamTokenizer : IEnumerable<Token>
{
String line;
StringBuilder value = new StringBuilder();
private TextReader _reader;

while ((line = _reader.ReadLine()) != null)
public StreamTokenizer(TextReader reader)
{
foreach (Char c in line)
_reader = reader;
}

public IEnumerator<Token> GetEnumerator()
{
String line;
StringBuilder value = new StringBuilder();

while ((line = _reader.ReadLine()) != null)
{
switch (c)
foreach (Char c in line)
{
case '\'':
case '"':
if (value.Length > 0)
{
yield return new Token(TokenType.Value, value.ToString());
value.Length = 0;
}
yield return new Token(TokenType.Quote, c.ToString());
break;
case ',':
if (value.Length > 0)
{
yield return new Token(TokenType.Value, value.ToString());
value.Length = 0;
}
yield return new Token(TokenType.Comma, c.ToString());
break;
default:
value.Append(c);
break;
switch (c)
{
case '\'':
case '"':
if (value.Length > 0)
{
yield return new Token(TokenType.Value, value.ToString());
value.Length = 0;
}
yield return new Token(TokenType.Quote, c.ToString());
break;
case ',':
if (value.Length > 0)
{
yield return new Token(TokenType.Value, value.ToString());
value.Length = 0;
}
yield return new Token(TokenType.Comma, c.ToString());
break;
default:
value.Append(c);
break;
}
}
}
}
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}

public class CsvParser : IEnumerable<String>
{
private StreamTokenizer _tokenizer;

public CsvParser(Stream data)
public class CsvParser : IEnumerable<String>
{
_tokenizer = new StreamTokenizer(new StreamReader(data));
}
private StreamTokenizer _tokenizer;

public CsvParser(String data)
{
_tokenizer = new StreamTokenizer(new StringReader(data));
}
public CsvParser(Stream data)
{
_tokenizer = new StreamTokenizer(new StreamReader(data));
}

public IEnumerator<string> GetEnumerator()
{
Boolean inQuote = false;
StringBuilder result = new StringBuilder();
public CsvParser(String data)
{
_tokenizer = new StreamTokenizer(new StringReader(data));
}

foreach (Token token in _tokenizer)
public IEnumerator<string> GetEnumerator()
{
switch (token.Type)
Boolean inQuote = false;
StringBuilder result = new StringBuilder();

foreach (Token token in _tokenizer)
{
case TokenType.Comma:
if (inQuote)
{
switch (token.Type)
{
case TokenType.Comma:
if (inQuote)
{
result.Append(token.Value);
}
else
{
yield return result.ToString();
result.Length = 0;
}
break;
case TokenType.Quote:
// Toggle quote state
inQuote = !inQuote;
break;
case TokenType.Value:
result.Append(token.Value);
}
else
{
yield return result.ToString();
result.Length = 0;
}
break;
case TokenType.Quote:
// Toggle quote state
inQuote = !inQuote;
break;
case TokenType.Value:
result.Append(token.Value);
break;
default:
throw new InvalidOperationException("Unknown token type: " + token.Type);
break;
default:
throw new InvalidOperationException("Unknown token type: " + token.Type);
}
}

if (result.Length > 0)
{
yield return result.ToString();
}
}

if (result.Length > 0)
IEnumerator IEnumerable.GetEnumerator()
{
yield return result.ToString();
return GetEnumerator();
}
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
Loading

0 comments on commit ca46956

Please sign in to comment.