You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

106 lines
3.3 KiB

using System;
using System.Collections.Generic;
#if false
namespace Sog
{
public abstract class Cfg2KeyMgrTemplate<TManager, TKey1, TKey2, TItem> : Singleton<TManager>, IConfigManager
where TManager : class, new()
where TItem : ITabItemWith2Key<TKey1, TKey2>, new()
{
protected SortedList<TKey1, SortedList<TKey2, TItem>> m_ItemTable = new SortedList<TKey1, SortedList<TKey2, TItem>>();
protected int m_ErrorCount = 0;
public virtual SortedList<TKey1, SortedList<TKey2, TItem>> ItemTable { get { return m_ItemTable; } }
public void SetReadKeyOnlyInit(bool readKeyOnly)
{
//m_readKeyOnly = readKeyOnly;
}
public virtual void ReadComplete()
{
}
public virtual bool Init(string fileName, string fileContent)
{
m_ItemTable.Clear();
TabTextFile tf = new TabTextFile(fileName, fileContent);
while (tf.Next())
{
TItem item = new TItem();
if (item.ReadItem(tf) == false)
{
TraceLog.Error("Failed to init TabManager:{0}, read line error, line:{1}", this.ToString(), tf.CurrentLine);
m_ErrorCount++;
return false;
}
if (GetGroup(item.GetKey1()) == null)
{
m_ItemTable.Add(item.GetKey1(), new SortedList<TKey2, TItem>());
}
else if (m_ItemTable[item.GetKey1()].ContainsKey(item.GetKey2()))
{
TraceLog.Error("Failed to init TabManager:{0}, multi key1:{1}, key2:{2}, line:{2}",
this.ToString(), item.GetKey1(), item.GetKey2(), tf.CurrentLine);
m_ErrorCount++;
return false;
}
m_ItemTable[item.GetKey1()].Add(item.GetKey2(), item);
}
return true;
}
public virtual TItem GetConfig(TKey1 key1, TKey2 key2)
{
if (m_ItemTable.ContainsKey(key1) && m_ItemTable[key1].ContainsKey(key2))
{
return m_ItemTable[key1][key2];
}
return default(TItem);
}
public virtual int GetCountKey1(TKey1 key1)
{
int allCount = 0;
SortedList < TKey2, TItem > sortedList = new SortedList<TKey2, TItem>();
if (m_ItemTable.TryGetValue(key1,out sortedList))
{
allCount = sortedList.Count;
}
return allCount;
}
public virtual SortedList<TKey2, TItem> GetGroup(TKey1 key1)
{
if (m_ItemTable.ContainsKey(key1))
{
return m_ItemTable[key1];
}
return null;
}
public virtual bool Has(TKey1 key1, TKey2 key2)
{
return m_ItemTable.ContainsKey(key1) && m_ItemTable[key1].ContainsKey(key2);
}
public virtual SortedList<TKey2, TItem> this[TKey1 key1]
{
get { return GetGroup(key1); }
}
public virtual TItem this[TKey1 key1, TKey2 key2]
{
get { return GetConfig(key1, key2); }
}
public virtual int GetErrorCount()
{
return m_ErrorCount;
}
}
}
#endif