using System; using System.Collections.Generic; #if false namespace Sog { public abstract class Cfg2KeyMgrTemplate : Singleton, IConfigManager where TManager : class, new() where TItem : ITabItemWith2Key, new() { protected SortedList> m_ItemTable = new SortedList>(); protected int m_ErrorCount = 0; public virtual SortedList> 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()); } 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(); if (m_ItemTable.TryGetValue(key1,out sortedList)) { allCount = sortedList.Count; } return allCount; } public virtual SortedList 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 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