Made SaveFile symmetrical with LoadFile

Added overload taking a FILE pointer
Return error code (if any) instead of void
This commit is contained in:
Ken Miller 2012-04-09 23:32:26 -05:00
parent 8712757389
commit 81da1fb26b
2 changed files with 25 additions and 8 deletions

View File

@ -1407,7 +1407,7 @@ int XMLDocument::LoadFile( FILE* fp )
} }
void XMLDocument::SaveFile( const char* filename ) int XMLDocument::SaveFile( const char* filename )
{ {
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning ( push ) #pragma warning ( push )
@ -1417,14 +1417,21 @@ void XMLDocument::SaveFile( const char* filename )
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning ( pop ) #pragma warning ( pop )
#endif #endif
if ( fp ) { if ( !fp ) {
XMLPrinter stream( fp );
Print( &stream );
fclose( fp );
}
else {
SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, filename, 0 ); SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, filename, 0 );
return errorID;
} }
SaveFile(fp);
fclose( fp );
return errorID;
}
int XMLDocument::SaveFile( FILE* fp )
{
XMLPrinter stream( fp );
Print( &stream );
return errorID;
} }

View File

@ -1024,8 +1024,18 @@ public:
int LoadFile( FILE* ); int LoadFile( FILE* );
/** /**
Save the XML file to disk. Save the XML file to disk.
Returns XML_NO_ERROR (0) on success, or
an errorID.
*/ */
void SaveFile( const char* filename ); int SaveFile( const char* filename );
/**
Save the XML file to disk. You are responsible
for providing and closing the FILE*.
Returns XML_NO_ERROR (0) on success, or
an errorID.
*/
int SaveFile( FILE* );
bool ProcessEntities() const { return processEntities; } bool ProcessEntities() const { return processEntities; }