Backend/Database/Serializable.cpp
/*!
 * @brief GList to GTable
 * @details Creates a GTable from a bundle
 * @return the GTable version of the bundle
 */
@brief GList to GTable
@details Creates a GTable from a bundle
@return the GTable version of the bundle
@brief GList to GTable @details Creates a GTable from a bundle @return the GTable version of the bundle
void Serializable::Deserialize(GTable& retTable, const GString& serial)
{
	GList cList;
	Deserialize(cList, serial);
	int rows = cList.getInt(0), columns = cList.getInt(1);
	char delimiter = cList.getChar(2);
	float min = cList.getFloat(3), max = cList.getFloat(4), range = cList.getFloat(5);
	int bundleIndex = 6; 
	int cIndex = bundleIndex;
	std::vector<GString> header;
	for (int i = 0; i < columns; ++i)
		header.push_back(cList.getString(cIndex + i));
	cIndex += columns;
	std::vector<int> outputColumns;
	for (int i = 0; i < columns; ++i)
	{
		int isOutputCol = cList.getString(cIndex + i) == GString("True");
		outputColumns.push_back(isOutputCol);
	}
	cIndex += columns;
	GTable cTable(delimiter);
	cTable.setMin(min);
	cTable.setMax(max);
	cTable.setRange(range);
	cTable.setHeaders(header);
	for (unsigned int i = 0; i < outputColumns.size(); ++i)
	{
		if(outputColumns[i])
			cTable.toggleOutput(i);
	}
	for (int i = 0; i < rows; ++i)
	{
		GList row;
		for (int j = 0; j < columns; ++j)
			row.addGType(cList[cIndex + j]);
		cTable.addRow(row);
		cIndex += columns;
	}
	int actual_size = cList.size();
	int expected_size = (rows + 2) * columns + bundleIndex;
	if (expected_size != actual_size)
	{
		printf("[SER] Bad GTable: Sizes(%d != %d)\n", actual_size, expected_size);
		return;
	}
	retTable = cTable;
}
void Serializable :: Deserialize ( GTable & retTable , const GString & serial ) { GList cList ; Deserialize ( cList , serial ) ; int rows = cList . getInt ( 0 ) , columns = cList . getInt ( 1 ) ; char delimiter = cList . getChar ( 2 ) ; float min = cList . getFloat ( 3 ) , max = cList . getFloat ( 4 ) , range = cList . getFloat ( 5 ) ; int bundleIndex = 6 ; int cIndex = bundleIndex ; std :: vector < GString > header ; for ( int i = 0 ; i < columns ; ++ i ) header . push_back ( cList . getString ( cIndex + i ) ) ; cIndex += columns ; std :: vector < int > outputColumns ; for ( int i = 0 ; i < columns ; ++ i ) { int isOutputCol = cList . getString ( cIndex + i ) == GString ( " " ) ; outputColumns . push_back ( isOutputCol ) ; } cIndex += columns ; GTable cTable ( delimiter ) ; cTable . setMin ( min ) ; cTable . setMax ( max ) ; cTable . setRange ( range ) ; cTable . setHeaders ( header ) ; for ( unsigned int i = 0 ; i < outputColumns . size ( ) ; ++ i ) { if ( outputColumns [ i ] ) cTable . toggleOutput ( i ) ; } for ( int i = 0 ; i < rows ; ++ i ) { GList row ; for ( int j = 0 ; j < columns ; ++ j ) row . addGType ( cList [ cIndex + j ] ) ; cTable . addRow ( row ) ; cIndex += columns ; } int actual_size = cList . size ( ) ; int expected_size = ( rows + 2 ) * columns + bundleIndex ; if ( expected_size != actual_size ) { printf ( " \n " , actual_size , expected_size ) ; return ; } retTable = cTable ; }
@brief GList to GTable
 @details Creates a GTable from a bundle
 @return the GTable version of the bundle
@brief GList to GTable @details Creates a GTable from a bundle @return the GTable version of the bundle
// metadata // Index to mark the end of the input args // the header // Because we cycled through the header // the output columns // Because we cycled through the output columns // Create the GTable schema // the contents // Because we cycled through another row