Skylicht Engine
Loading...
Searching...
No Matches
Skylicht::CXMLTableData Class Reference

Table adapter that maps spreadsheet rows to serializable objects. More...

#include <Utils/XMLSpreadsheet/CXMLTableData.h>

Public Member Functions

 CXMLTableData (CXMLSpreadsheet::SSheet *sheet)
 Construct a table adapter for a sheet.
virtual ~CXMLTableData ()
 Destroy the table adapter.
void addColumn (const char *name)
 Append a column mapping.
void insertColumn (const char *name, u32 position)
 Insert a column mapping at a position.
void removeColumn (u32 index)
 Remove a column mapping.
const char * getColumn (u32 index)
 Get a column mapping name.
u32 getNumColumn ()
 Get the number of mapped columns.
u32 getNumRow ()
 Get the number of rows in the source sheet.
u32 fetchData (std::function< CObjectSerializable *()> creatorFunc, std::vector< CObjectSerializable * > &data, u32 fromRow, int count)
 Create and fill serializable objects from sheet rows.
void copyRowToObject (CXMLSpreadsheet::SRow *row, CObjectSerializable *data)
 Copy one spreadsheet row into a serializable object.
template<class T>
void freeData (std::vector< T * > &data)
 Delete all pointers in a fetched data vector and clear it.
template<class T>
u32 fetchData (std::vector< T * > &data, u32 fromRow, int count)
 Create and fill typed serializable objects from sheet rows.

Protected Attributes

std::vector< std::string > m_column
CXMLSpreadsheet::SSheetm_sheet

Detailed Description

Table adapter that maps spreadsheet rows to serializable objects.

Columns define the property names used when copying row values into CObjectSerializable instances.

Constructor & Destructor Documentation

◆ CXMLTableData()

Skylicht::CXMLTableData::CXMLTableData ( CXMLSpreadsheet::SSheet * sheet)

Construct a table adapter for a sheet.

Parameters
sheetSource sheet. The adapter does not own this pointer.

Member Function Documentation

◆ addColumn()

void Skylicht::CXMLTableData::addColumn ( const char * name)

Append a column mapping.

Parameters
nameSerializable property name for the column.

◆ copyRowToObject()

void Skylicht::CXMLTableData::copyRowToObject ( CXMLSpreadsheet::SRow * row,
CObjectSerializable * data )

Copy one spreadsheet row into a serializable object.

Parameters
rowSource row.
dataDestination serializable object.

◆ fetchData() [1/2]

u32 Skylicht::CXMLTableData::fetchData ( std::function< CObjectSerializable *()> creatorFunc,
std::vector< CObjectSerializable * > & data,
u32 fromRow,
int count )

Create and fill serializable objects from sheet rows.

Parameters
creatorFuncFunction that creates a new serializable object.
dataReceives created objects. Ownership is transferred to the caller.
fromRowFirst row index to fetch.
countMaximum number of rows to fetch, or a non-positive value for all rows.
Returns
Number of objects appended to data.

◆ fetchData() [2/2]

template<class T>
u32 Skylicht::CXMLTableData::fetchData ( std::vector< T * > & data,
u32 fromRow,
int count )
inline

Create and fill typed serializable objects from sheet rows.

T must derive from CObjectSerializable.

Template Parameters
TObject type to allocate.
Parameters
dataReceives created objects. Ownership is transferred to the caller.
fromRowFirst row index to fetch.
countMaximum number of rows to fetch, or a non-positive value for all rows.
Returns
Number of objects appended to data, or 0 if T is not serializable.

◆ freeData()

template<class T>
void Skylicht::CXMLTableData::freeData ( std::vector< T * > & data)
inline

Delete all pointers in a fetched data vector and clear it.

Template Parameters
TObject type stored in the vector.
Parameters
dataVector of owned pointers.

◆ getColumn()

const char * Skylicht::CXMLTableData::getColumn ( u32 index)
inline

Get a column mapping name.

Parameters
indexZero-based column index.
Returns
Column name.

◆ getNumColumn()

u32 Skylicht::CXMLTableData::getNumColumn ( )
inline

Get the number of mapped columns.

Returns
Column count.

◆ getNumRow()

u32 Skylicht::CXMLTableData::getNumRow ( )
inline

Get the number of rows in the source sheet.

Returns
Row count.

◆ insertColumn()

void Skylicht::CXMLTableData::insertColumn ( const char * name,
u32 position )

Insert a column mapping at a position.

Parameters
nameSerializable property name for the column.
positionZero-based insertion position.

◆ removeColumn()

void Skylicht::CXMLTableData::removeColumn ( u32 index)

Remove a column mapping.

Parameters
indexZero-based column index.

The documentation for this class was generated from the following file: