Skip to content

Commit

Permalink
Update PicoGK_Csv.cs
Browse files Browse the repository at this point in the history
Added abstract IDataTable interface and extended CsvTable functions (adding Rows, setting ColumnIDs, etc.)
  • Loading branch information
LinKayser committed Oct 2, 2024
1 parent 210bffa commit 99df767
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions PicoGK_Csv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,30 @@

namespace PicoGK
{
public class CsvTable
public interface IDataTable
{
int nMaxColumnCount();

string strColumnId(int nColumn);

bool bFindColumn( string strColumnName,
out int nColumn);

int nRowCount();

string strGetAt( int nRow,
int nColumn);

void SetColumnIds(IEnumerable<string> astrIds);

void AddRow(IEnumerable<string> astrData);
}
public class CsvTable : IDataTable
{
public CsvTable(IEnumerable<string>? astrColumnIDs = null)
{
m_oColumnIDs = new(astrColumnIDs ?? []);
}
public CsvTable( string strFilePath,
string strDelimiters = ",")
{
Expand Down Expand Up @@ -167,7 +189,6 @@ public bool bGetAt( in string strKey,
{
return false;
}


foreach (List<string> oColumns in m_oRows)
{
Expand Down Expand Up @@ -207,6 +228,27 @@ public bool bFindColumn( string strColumnName,
return false;
}

public string strColumnId(int nColumn)
{
if (nColumn > nMaxColumnCount()-1)
return "";

return m_oColumnIDs[nColumn];
}

public void SetColumnIds(IEnumerable<string> astrIds)
{
m_oColumnIDs = new(astrIds);
m_nMaxColumnCount = int.Max(m_nMaxColumnCount, m_oColumnIDs.Count);
}

public void AddRow(IEnumerable<string> astrData)
{
List<string> oRow = new(astrData);
m_oRows.Add(oRow);
m_nMaxColumnCount = int.Max(m_nMaxColumnCount, oRow.Count);
}

List<string> m_oColumnIDs;
List<List<string>> m_oRows = new List<List<string>>();
int m_nKeyColumn = 0;
Expand Down

0 comments on commit 99df767

Please sign in to comment.