Backend/Database/GTable.cpp
/*!
 * @brief save GTable
 * @details save the GTable to a file
 * @param fname the file path at which to save the GTable data
 */
@brief save GTable
@details save the GTable to a file
@param fname the file path at which to save the GTable data
@brief save GTable @details save the GTable to a file @param fname the file path at which to save the GTable data
void GTable::save(const GString& fname) const
{
	if (fname.length() <= 0)
		return;
	FILE* fd = fopen(fname.c_str(), "w");
	if (fd != NULL)
	{
		for (unsigned int i = 0; i < header.size(); ++i)
		{
			GString word = header[i];
			fprintf(fd, "%s", word.c_str());
			if (i < header.size() - 1)
				fprintf(fd, ",");
		}
		fprintf(fd, "\n");
		 save it as the proper type
		for (unsigned int r = 0; r < numberOfRows(); ++r)
		{
			for (unsigned int c = 0; c < numberOfCols(); ++c)
			{
				GType cCell = getCell(r, c);
				if (cCell.getType() == GType::STRING_TYPE)
				{
					GString word = getCell(r, c);
					fprintf(fd, "%s", word.c_str());
				}
				else if (cCell.getType() == GType::CHAR_TYPE)
				{
					char word = getCell(r, c).getChar();
					fprintf(fd, "%c", word);
				}
				else if (cCell.getType() == GType::SHORT_TYPE)
				{
					short word = getCell(r, c).getShort();
					fprintf(fd, "%d", (int)word);
				}
				else if (cCell.getType() == GType::INT_TYPE)
				{
					int word = getCell(r, c).getInt();
					fprintf(fd, "%d", word);
				}
				else if (cCell.getType() == GType::LONG_TYPE)
				{
					int64_t word = getCell(r, c).getLong();
					fprintf(fd, "%ld", word);
				}
				else if (cCell.getType() == GType::FLOAT_TYPE)
				{
					float word = getCell(r, c).getFloat();
					fprintf(fd, "%f", word);
				}
				else if (cCell.getType() == GType::DOUBLE_TYPE)
				{
					double word = getCell(r, c).getDouble();
					fprintf(fd, "%f", word);
				}
				else if (cCell.getType() == GType::BOOLEAN_TYPE)
				{
					bool word = getCell(r, c).getBoolean();
					fprintf(fd, "%d", word ? 1 : 0);
				}
				if (c < numberOfCols() - 1)
					fprintf(fd, ",");
			}
			fprintf(fd, "\n");
		}
		fclose(fd);
	}
}
void GTable :: save ( const GString & fname ) const { if ( fname . length ( ) <= 0 ) return ; FILE * fd = fopen ( fname . c_str ( ) , " " ) ; if ( fd != NULL ) { for ( unsigned int i = 0 ; i < header . size ( ) ; ++ i ) { GString word = header [ i ] ; fprintf ( fd , " " , word . c_str ( ) ) ; if ( i < header . size ( ) - 1 ) fprintf ( fd , " " ) ; } fprintf ( fd , " \n " ) ; for ( unsigned int r = 0 ; r < numberOfRows ( ) ; ++ r ) { for ( unsigned int c = 0 ; c < numberOfCols ( ) ; ++ c ) { GType cCell = getCell ( r , c ) ; if ( cCell . getType ( ) == GType :: STRING_TYPE ) { GString word = getCell ( r , c ) ; fprintf ( fd , " " , word . c_str ( ) ) ; } else if ( cCell . getType ( ) == GType :: CHAR_TYPE ) { char word = getCell ( r , c ) . getChar ( ) ; fprintf ( fd , " " , word ) ; } else if ( cCell . getType ( ) == GType :: SHORT_TYPE ) { short word = getCell ( r , c ) . getShort ( ) ; fprintf ( fd , " " , ( int ) word ) ; } else if ( cCell . getType ( ) == GType :: INT_TYPE ) { int word = getCell ( r , c ) . getInt ( ) ; fprintf ( fd , " " , word ) ; } else if ( cCell . getType ( ) == GType :: LONG_TYPE ) { int64_t word = getCell ( r , c ) . getLong ( ) ; fprintf ( fd , " " , word ) ; } else if ( cCell . getType ( ) == GType :: FLOAT_TYPE ) { float word = getCell ( r , c ) . getFloat ( ) ; fprintf ( fd , " " , word ) ; } else if ( cCell . getType ( ) == GType :: DOUBLE_TYPE ) { double word = getCell ( r , c ) . getDouble ( ) ; fprintf ( fd , " " , word ) ; } else if ( cCell . getType ( ) == GType :: BOOLEAN_TYPE ) { bool word = getCell ( r , c ) . getBoolean ( ) ; fprintf ( fd , " " , word ? 1 : 0 ) ; } if ( c < numberOfCols ( ) - 1 ) fprintf ( fd , " " ) ; } fprintf ( fd , " \n " ) ; } fclose ( fd ) ; } }
@brief save GTable
 @details save the GTable to a file
 @param fname the file path at which to save the GTable data
@brief save GTable @details save the GTable to a file @param fname the file path at which to save the GTable data
// // save it as the proper type