Backend/Database/Serializable.cpp
/*!
 * @brief GList to GObject
 * @details Creates a GObject from a bundle
 * @return the GObject version of the bundle
 */
@brief GList to GObject
@details Creates a GObject from a bundle
@return the GObject version of the bundle
@brief GList to GObject @details Creates a GObject from a bundle @return the GObject version of the bundle
void Serializable::Deserialize(GObject& retObj, const GString& serial)
{
	GList cList;
	Deserialize(cList, serial);
	unsigned int memberTablesCount = cList.getInt(0);
	int cIndex = 1;
	int rows = cList.getInt(cIndex + 0), columns = cList.getInt(cIndex + 1);
	char delimiter = cList.getChar(cIndex + 2);
	float min = cList.getFloat(cIndex + 3), max = cList.getFloat(cIndex + 4), range = cList.getFloat(cIndex + 5);
	int bundleIndex = cIndex + 6; 
	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 members(delimiter);
	members.setMin(min);
	members.setMax(max);
	members.setRange(range);
	members.setHeaders(header);
	for (unsigned int i = 0; i < outputColumns.size(); ++i)
	{
		if(outputColumns[i])
			members.toggleOutput(i);
	}
	for (int i = 0; i < rows; ++i)
	{
		GList row;
		for (int j = 0; j < columns; ++j)
			row.addGType(cList[cIndex + j]);
		members.addRow(row);
		cIndex += columns;
	}
	int top_actual_size = cIndex;
	int top_expected_size = (rows + 2) * columns + bundleIndex;
	if (top_expected_size != top_actual_size)
	{
		printf("[SER] Bad GObject: Sizes(%d != %d)\n", top_actual_size, top_expected_size);
		return;
	}
	 IN THE LOOP
	GObject cObject;
	cObject.setMembers(members);
	for(unsigned int mCounter = 0; mCounter < memberTablesCount; ++mCounter)
	{
		int rows = cList.getInt(cIndex + 0), columns = cList.getInt(cIndex + 1);
		char delimiter = cList.getChar(cIndex + 2);
		float min = cList.getFloat(cIndex + 3), max = cList.getFloat(cIndex + 4), range = cList.getFloat(cIndex + 5);
		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 = cIndex;
		int expected_size = (rows + 2) * columns + top_actual_size;
		top_actual_size = expected_size; 
		if (expected_size != actual_size)
		{
			printf("[SER] Bad GObject GTable[%d]: Sizes(%d != %d)\n", mCounter, actual_size, expected_size);
			return;
		}
	}
	retObj = cObject;
}
void Serializable :: Deserialize ( GObject & retObj , const GString & serial ) { GList cList ; Deserialize ( cList , serial ) ; unsigned int memberTablesCount = cList . getInt ( 0 ) ; int cIndex = 1 ; int rows = cList . getInt ( cIndex + 0 ) , columns = cList . getInt ( cIndex + 1 ) ; char delimiter = cList . getChar ( cIndex + 2 ) ; float min = cList . getFloat ( cIndex + 3 ) , max = cList . getFloat ( cIndex + 4 ) , range = cList . getFloat ( cIndex + 5 ) ; int bundleIndex = cIndex + 6 ; 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 members ( delimiter ) ; members . setMin ( min ) ; members . setMax ( max ) ; members . setRange ( range ) ; members . setHeaders ( header ) ; for ( unsigned int i = 0 ; i < outputColumns . size ( ) ; ++ i ) { if ( outputColumns [ i ] ) members . toggleOutput ( i ) ; } for ( int i = 0 ; i < rows ; ++ i ) { GList row ; for ( int j = 0 ; j < columns ; ++ j ) row . addGType ( cList [ cIndex + j ] ) ; members . addRow ( row ) ; cIndex += columns ; } int top_actual_size = cIndex ; int top_expected_size = ( rows + 2 ) * columns + bundleIndex ; if ( top_expected_size != top_actual_size ) { printf ( " \n " , top_actual_size , top_expected_size ) ; return ; } GObject cObject ; cObject . setMembers ( members ) ; for ( unsigned int mCounter = 0 ; mCounter < memberTablesCount ; ++ mCounter ) { int rows = cList . getInt ( cIndex + 0 ) , columns = cList . getInt ( cIndex + 1 ) ; char delimiter = cList . getChar ( cIndex + 2 ) ; float min = cList . getFloat ( cIndex + 3 ) , max = cList . getFloat ( cIndex + 4 ) , range = cList . getFloat ( cIndex + 5 ) ; 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 = cIndex ; int expected_size = ( rows + 2 ) * columns + top_actual_size ; top_actual_size = expected_size ; if ( expected_size != actual_size ) { printf ( " \n " , mCounter , actual_size , expected_size ) ; return ; } } retObj = cObject ; }
@brief GList to GObject
 @details Creates a GObject from a bundle
 @return the GObject version of the bundle
@brief GList to GObject @details Creates a GObject from a bundle @return the GObject version of the bundle
//TODO: REPLACE THIS BLOCK WITH GTABLE DSERIALIZE CALL // Add the members // 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 //TODO: REPLACE THIS BLOCK WITH GTABLE DSERIALIZE CALL IN THE LOOP // Create the cObject we will return from the members // Now we add the member GTables // metadata // 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 // for the next iteration of the mCounter