Download Source Code

CCsvFile Class Reference

Class for reading comma separated value files. More...

#include <CsvFile.h>

List of all members.

Public Member Functions

LPCTSTR GetElementPtr (CSV_HROW hRow, LPCTSTR pCol, LPCTSTR pDef="")
 Gets a pointer to element string.
BOOL AddColumn (LPCTSTR pDescription, DWORD insert=MAXDWORD)
 Adds a column to the CSV file.
DWORD GetHeaderString (LPSTR buf, DWORD size)
 Returns the line that was determined to be the header strings.
DWORD GetRowString (DWORD row, LPSTR pRow, DWORD size)
 Copies the string associated with a particular row.
BOOL Copy (LPVOID buf, LPDWORD ptr, DWORD size, LPCTSTR str)
 Copies a string of specified size.
DWORD SaveToMem (LPBYTE buf, DWORD size)
 Writes the CSV file to a memory buffer.
BOOL SaveFile (LPCTSTR pFile)
 Saves the CSV file to disk.
BOOL LoadColumns (LPCTSTR pLine)
 Loads the column names from string.
BOOL AddLine (LPCTSTR pLine)
 Adds a line of data to the CSV file.
BOOL AllocateRows (DWORD size)
 Allocates the specified number of rows.
BOOL LoadFromMem (LPBYTE buf, DWORD size, BOOL bAdd=FALSE)
 Loads a CSV file from memory.
BOOL LoadFile (LPCTSTR pFile, BOOL bAdd=FALSE)
 Loads CSV file from disk file.
void Destroy ()
 Releases all resources associated with CSV.
BOOL AllocateColumns (DWORD columns)
 Allocates specified number of columns.
 CCsvFile ()
 Constructor.
virtual ~CCsvFile ()
 Destructor.
DWORD GetNumColumns ()
 Returns the number of columns.
DWORD GetNumRows ()
 Returns the number of rows.
LPBYTE * GetTablePtr ()
 Returns a pointer to the table data.
BOOL IsTable ()
 Returns non-zero if there is a valid data table.
CSV_HROW AppendNewRow ()
 Appends a new row to the current CSV file.
CSV_HROW GetRow (DWORD i)
 Returns a handle to the specified row.
LPBYTE GetRowElement (CSV_HROW hrow, DWORD i)
 Returns a pointer to the specified element.
LPCTSTR GetColDesc (DWORD i)
 Retreives a pointer to the column description string.
DWORD FindCol (LPCTSTR desc)
 Returns the index of the named column.
void SetRecordSize (DWORD rs)
 Sets the maximum size of a single CSV item.
DWORD GetRecordSize ()
 Returns the maximum size of a single CSV item.
void SetSep (BYTE sep)
 Sets the separator character for the CSV file.
BYTE GetSep ()
 Returns the current separator character for the CSV file.
void SetRowBlockSize (DWORD rbs)
 Sets the row block size.
DWORD GetRowBlockSize ()
 Returns the current row blocks size.
void SetSkip (DWORD s)
 Sets the number of lines to skip at the start of the CSV file.


Detailed Description

Class for reading comma separated value files.

This class provides simple functionality for working with CSV (Comma Separated Value) files.


Member Function Documentation

BOOL CCsvFile::AddColumn LPCTSTR  pDescription,
DWORD  insert = MAXDWORD
 

Adds a column to the CSV file.

Parameters:
[in] pDescription - Description of column
[in] insert - Index of column, MAXDWORD to append.
Returns:
Non-zero if success
See also:

BOOL CCsvFile::AddLine LPCTSTR  pLine  ) 
 

Adds a line of data to the CSV file.

Parameters:
[in] pLine - Pointer to string containing single line of CSV data.
Returns:
Non-zero if success.
See also:

BOOL CCsvFile::AllocateColumns DWORD  columns  ) 
 

Allocates specified number of columns.

Parameters:
[in] columns - Number of columns to allocate.
Returns:
Non-zero if success.
See also:

BOOL CCsvFile::AllocateRows DWORD  size  ) 
 

Allocates the specified number of rows.

Parameters:
[in] size - Number of rows to allocate.
Returns:
Non-zero if success.
See also:

BOOL CCsvFile::Copy LPVOID  buf,
LPDWORD  ptr,
DWORD  size,
LPCTSTR  str
 

Copies a string of specified size.

Parameters:
[out] buf - Buffer pointer
[in,out] ptr - Location in buffer to copy string
[in] size - Size of buffer in buf
[in] str - String to copy into buffer
Returns:
Non-zero if success
See also:

DWORD CCsvFile::FindCol LPCTSTR  desc  )  [inline]
 

Returns the index of the named column.

Parameters:
[in] desc - Name of the column to find.
Returns:
Index of the specified column or MAXDWORD if not found.
See also:

LPCTSTR CCsvFile::GetColDesc DWORD  i  )  [inline]
 

Retreives a pointer to the column description string.

Parameters:
[in] i - Column index
Returns:
Pointer to string naming column.
See also:

LPCTSTR CCsvFile::GetElementPtr CSV_HROW  hRow,
LPCTSTR  pCol,
LPCTSTR  pDef = ""
 

Gets a pointer to element string.

Parameters:
[in] hRow - Handle to row
[in] pCol - Pointer to column name
[in] pDef - Default value for item
Returns:
Value string or pDef if failure
See also:

DWORD CCsvFile::GetHeaderString LPSTR  buf,
DWORD  size
 

Returns the line that was determined to be the header strings.

Parameters:
[out] buf - Pointer to header data
[in] size - Size of the buffer in buf
Returns:
Length of string in buf
See also:

CSV_HROW CCsvFile::GetRow DWORD  i  )  [inline]
 

Returns a handle to the specified row.

Parameters:
[in] i - Index of row
Returns:
Handle to row
See also:

LPBYTE CCsvFile::GetRowElement CSV_HROW  hrow,
DWORD  i
[inline]
 

Returns a pointer to the specified element.

Parameters:
[in] hrow - Handle to row
[in] i - Index of row element
Returns:
See also:

DWORD CCsvFile::GetRowString DWORD  row,
LPSTR  pRow,
DWORD  size
 

Copies the string associated with a particular row.

Parameters:
[in] row - Row index
[out] pRow - Pointer that receives row data
[in] size - Size of buffer in pRow
Returns:
Length of data in pRow
See also:

BOOL CCsvFile::LoadColumns LPCTSTR  pLine  ) 
 

Loads the column names from string.

Parameters:
[in] pLine - String containing column names
Returns:
Non-zero if success.
See also:

BOOL CCsvFile::LoadFile LPCTSTR  pFile,
BOOL  bAdd = FALSE
 

Loads CSV file from disk file.

Parameters:
[in] pFile - Pointer to filename
[in] bAdd - Set to non-zero to add data to current file.
Returns:
See also:

BOOL CCsvFile::LoadFromMem LPBYTE  buf,
DWORD  size,
BOOL  bAdd = FALSE
 

Loads a CSV file from memory.

Parameters:
[in] buf - Buffer containing CSV data.
[in] size - Size of the buffer in buf
[in] bAdd - Set to non-zero to add data to current file.
Returns:
Non-zero if success.
See also:

BOOL CCsvFile::SaveFile LPCTSTR  pFile  ) 
 

Saves the CSV file to disk.

Parameters:
[in] pFile - Disk filename.
Returns:
Non-zero if success.
See also:

DWORD CCsvFile::SaveToMem LPBYTE  buf,
DWORD  size
 

Writes the CSV file to a memory buffer.

Parameters:
[out] buf - Pointer to a memory buffer.
[in] size - Size of the buffer in buf
Returns:
Size of data written to buf.
See also:

void CCsvFile::SetRecordSize DWORD  rs  )  [inline]
 

Sets the maximum size of a single CSV item.

Parameters:
[in] rs - Maximum text string length

void CCsvFile::SetRowBlockSize DWORD  rbs  )  [inline]
 

Sets the row block size.

Parameters:
[in] rbs - Row block size

void CCsvFile::SetSep BYTE  sep  )  [inline]
 

Sets the separator character for the CSV file.

Parameters:
[in] sep - Row item separator. Usually ','

void CCsvFile::SetSkip DWORD  s  )  [inline]
 

Sets the number of lines to skip at the start of the CSV file.

Parameters:
[in] s - Number of lines to skip.
There is many times data that needs to be ignored at the start of a CSV file. Use this function to set the number of lines that should be ignored.


The documentation for this class was generated from the following files:
  • inc/CsvFile.h
  • CsvFile.cpp
Copyright Robert Umbehant
This documentation is covered by the LGPL