123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using System;
- using System.Collections.Generic;
- namespace wf
- {
- public abstract class CsvCommonDatabaseIDType<Data>
- {
- public abstract string csvTopCommonName { get; }
- public abstract string typeNameForErrorLog { get; }
- public int Count
- {
- get
- {
- this.Initialize();
- return this.commonIdManager.idMap.Count;
- }
- }
- public bool Contains(int id)
- {
- return this.commonIdManager.idMap.ContainsKey(id);
- }
- public Data GetData(int id)
- {
- this.Initialize();
- NDebug.Assert(this.basicDatas.ContainsKey(id), string.Concat(new object[]
- {
- this.typeNameForErrorLog,
- "\nID[",
- id,
- "]のデータは存在しません"
- }));
- return this.basicDatas[id];
- }
- public List<Data> GetAllDatas(bool onlyEnabled)
- {
- this.Initialize();
- List<Data> list = new List<Data>();
- foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in this.commonIdManager.idMap)
- {
- if (!onlyEnabled || this.commonIdManager.enabledIdList.Contains(keyValuePair.Key))
- {
- list.Add(this.basicDatas[keyValuePair.Key]);
- }
- }
- return list;
- }
- public bool IsEnabled(int id)
- {
- this.Initialize();
- return this.commonIdManager.enabledIdList.Contains(id);
- }
- public virtual bool Initialize()
- {
- if (this.commonIdManager != null)
- {
- return false;
- }
- this.commonIdManager = new CsvCommonIdManager(this.csvTopCommonName, this.typeNameForErrorLog, CsvCommonIdManager.Type.IdOnly, null);
- this.basicDatas = this.CreateData(this.commonIdManager);
- return true;
- }
- protected abstract Dictionary<int, Data> CreateData(CsvCommonIdManager createIds);
- public CsvCommonDatabaseIDType<Data>.CsvPair OpenCsvFromNameSuffix(string nameSuffix)
- {
- return this.OpenCsv(this.csvTopCommonName + "_" + nameSuffix + ".csv");
- }
- public CsvCommonDatabaseIDType<Data>.CsvPair OpenCsv(string fileName)
- {
- bool flag;
- return new CsvCommonDatabaseIDType<Data>.CsvPair(fileName, ref flag);
- }
- protected CsvCommonIdManager commonIdManager;
- protected Dictionary<int, Data> basicDatas;
- public class CsvPair : IDisposable
- {
- public CsvPair(string fileName, out bool openResult)
- {
- this.file = GameUty.FileSystem.FileOpen(fileName);
- this.csv = new CsvParser();
- openResult = (this.file != null && this.csv.Open(this.file));
- }
- public CsvPair(string fileName)
- {
- this.file = GameUty.FileSystem.FileOpen(fileName);
- this.csv = new CsvParser();
- this.csv.Open(this.file);
- }
- public CsvPair()
- {
- }
- ~CsvPair()
- {
- this.Dispose();
- }
- public void Dispose()
- {
- if (this.isDisposed)
- {
- return;
- }
- this.isDisposed = true;
- if (this.file != null)
- {
- this.file.Dispose();
- }
- if (this.csv != null)
- {
- this.csv.Dispose();
- }
- this.file = null;
- this.csv = null;
- GC.SuppressFinalize(this);
- }
- public AFileBase file;
- public CsvParser csv;
- private bool isDisposed;
- }
- }
- }
|