|
35 | 35 |
|
36 | 36 | namespace PicoGK |
37 | 37 | { |
38 | | - public class CsvTable |
| 38 | + public interface IDataTable |
39 | 39 | { |
| 40 | + int nMaxColumnCount(); |
| 41 | + |
| 42 | + string strColumnId(int nColumn); |
| 43 | + |
| 44 | + bool bFindColumn( string strColumnName, |
| 45 | + out int nColumn); |
| 46 | + |
| 47 | + int nRowCount(); |
| 48 | + |
| 49 | + string strGetAt( int nRow, |
| 50 | + int nColumn); |
| 51 | + |
| 52 | + void SetColumnIds(IEnumerable<string> astrIds); |
| 53 | + |
| 54 | + void AddRow(IEnumerable<string> astrData); |
| 55 | + } |
| 56 | + public class CsvTable : IDataTable |
| 57 | + { |
| 58 | + public CsvTable(IEnumerable<string>? astrColumnIDs = null) |
| 59 | + { |
| 60 | + m_oColumnIDs = new(astrColumnIDs ?? []); |
| 61 | + } |
40 | 62 | public CsvTable( string strFilePath, |
41 | 63 | string strDelimiters = ",") |
42 | 64 | { |
@@ -167,7 +189,6 @@ public bool bGetAt( in string strKey, |
167 | 189 | { |
168 | 190 | return false; |
169 | 191 | } |
170 | | - |
171 | 192 |
|
172 | 193 | foreach (List<string> oColumns in m_oRows) |
173 | 194 | { |
@@ -207,6 +228,27 @@ public bool bFindColumn( string strColumnName, |
207 | 228 | return false; |
208 | 229 | } |
209 | 230 |
|
| 231 | + public string strColumnId(int nColumn) |
| 232 | + { |
| 233 | + if (nColumn > nMaxColumnCount()-1) |
| 234 | + return ""; |
| 235 | + |
| 236 | + return m_oColumnIDs[nColumn]; |
| 237 | + } |
| 238 | + |
| 239 | + public void SetColumnIds(IEnumerable<string> astrIds) |
| 240 | + { |
| 241 | + m_oColumnIDs = new(astrIds); |
| 242 | + m_nMaxColumnCount = int.Max(m_nMaxColumnCount, m_oColumnIDs.Count); |
| 243 | + } |
| 244 | + |
| 245 | + public void AddRow(IEnumerable<string> astrData) |
| 246 | + { |
| 247 | + List<string> oRow = new(astrData); |
| 248 | + m_oRows.Add(oRow); |
| 249 | + m_nMaxColumnCount = int.Max(m_nMaxColumnCount, oRow.Count); |
| 250 | + } |
| 251 | + |
210 | 252 | List<string> m_oColumnIDs; |
211 | 253 | List<List<string>> m_oRows = new List<List<string>>(); |
212 | 254 | int m_nKeyColumn = 0; |
|
0 commit comments