Skip to content

Commit 99df767

Browse files
committed
Update PicoGK_Csv.cs
Added abstract IDataTable interface and extended CsvTable functions (adding Rows, setting ColumnIDs, etc.)
1 parent 210bffa commit 99df767

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

PicoGK_Csv.cs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,30 @@
3535

3636
namespace PicoGK
3737
{
38-
public class CsvTable
38+
public interface IDataTable
3939
{
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+
}
4062
public CsvTable( string strFilePath,
4163
string strDelimiters = ",")
4264
{
@@ -167,7 +189,6 @@ public bool bGetAt( in string strKey,
167189
{
168190
return false;
169191
}
170-
171192

172193
foreach (List<string> oColumns in m_oRows)
173194
{
@@ -207,6 +228,27 @@ public bool bFindColumn( string strColumnName,
207228
return false;
208229
}
209230

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+
210252
List<string> m_oColumnIDs;
211253
List<List<string>> m_oRows = new List<List<string>>();
212254
int m_nKeyColumn = 0;

0 commit comments

Comments
 (0)