/****************************************************************************
Copyright (c) 2011-2013,WebJet Business Division,CYOU
http://www.genesis-3d.com.cn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
namespace ScriptGUI
{
///
/// HashID类
///
public struct HashID
{
private HashID(Int32 value)
{
id = value;
}
///
/// 判断两个哈希值是否相等
///
/// 哈希值
/// 哈希值
/// 相等true,不相等false
public static bool operator ==(HashID ls, HashID rs)
{
return ls.id == rs.id;
}
///
/// 判断两个哈希值是否不等
///
/// 哈希值
/// 哈希值
/// 不相等true,相等false
public static bool operator !=(HashID ls, HashID rs)
{
return ls.id != rs.id;
}
///
/// 隐式操作符
///
/// 整型哈希值
/// 哈希码
public static implicit operator HashID(int hash_id)
{
return new HashID(hash_id);
}
///
/// 判断对象哈希值是否相等
///
/// 指定的对象
/// 相等true,不相等false
public override bool Equals(object obj)
{
return ((obj is HashID) && (this == ((HashID)obj)));
}
///
/// 获得哈希值
///
/// 哈希值
public override int GetHashCode()
{
return id;
}
private Int32 id;
}
///
/// 自定义字符串类
///
public class FString
{
private FString(String str, HashID id)
{
mName = str;
mID = id;
}
///
/// 创建一个FString
///
/// 字符串
/// 创建后的FString
public static FString CreateString(String str)
{
if (null == str)
{
return null;
}
HashID id = str.GetHashCode();
return new FString(str, id);
}
///
/// 创建一个FString
///
/// 哈希码
/// 创建后的FString
public static FString CreateString(HashID hash_id)
{
return new FString(null, hash_id);
}
///
/// 隐式操作符
///
/// 普通字符串
/// 转换后的Fstring
public static implicit operator FString(String str)
{
return CreateString(str);
}
///
/// 判断两个FString 是否相等
///
/// FString
/// FString
/// 相等true,不相等false
internal static bool Equals(FString ls, FString rs)
{
if (ReferenceEquals(ls, null))
{
return ReferenceEquals(rs, null);
}
else if (ReferenceEquals(rs, null))
{
return false;
}
return (ls.mID == rs.mID);
}
///
/// 判断两个FString 是否相等
///
/// FString
/// FString
/// 相等true,不相等false
public static bool operator ==(FString ls, FString rs)
{
return Equals(ls, rs);
}
///
/// 判断两个FString 是否不相等
///
/// FString
/// FString
/// 不相等true,相等false
public static bool operator !=(FString ls, FString rs)
{
return !Equals(ls, rs);
}
///
/// 判断对象的FString是否相等
///
/// 指定的对象
/// 相等true,不相等false
public override bool Equals(object obj)
{
return (obj is FString) && (this == (obj as FString));
}
///
/// 获取哈希码
///
/// 哈希码
public override int GetHashCode()
{
return mID.GetHashCode();
}
public override string ToString()
{
return mName;
}
public FString GetCopy()
{
return CreateString(mName);
}
internal String Name
{
get
{
return mName;
}
}
private HashID mID;
private String mName;
//private static Dictionary mStringTable = new Dictionary();
}
}