Serious-Engine/Sources/Engine/Base/Serial.cpp
Ryan C. Gordon 1a2ccb8f50 Merge github.com:Croteam-Official/Serious-Engine
Conflicts:
	Sources/Ecc/Parser.cpp
	Sources/Ecc/Scanner.cpp
	Sources/Engine/Base/Scanner.cpp
	Sources/Engine/GameAgent/GameAgent.cpp
	Sources/Engine/Graphics/Gfx_wrapper.h
	Sources/Engine/Network/Network.cpp
	Sources/Engine/Sound/SoundDecoder.h
	Sources/Engine/Templates/HashTableTemplate.cpp
	Sources/Engine/Terrain/Terrain.h
	Sources/EntitiesMP/ParticleCloudsHolder.es
	Sources/EntitiesMP/ParticleCloudsMarker.es
	Sources/SeriousSam/CDCheck.h
	Sources/SeriousSam/Menu.cpp
	Sources/SeriousSam/MenuGadgets.cpp
	Sources/SeriousSam/SeriousSam.cpp
	Sources/SeriousSam/SplashScreen.cpp
	Sources/SeriousSam/StdH.cpp
	Sources/SeriousSam/StdH.h
	Sources/Shaders/StdH.cpp
2016-04-02 23:56:12 -04:00

163 lines
3.4 KiB
C++

/* Copyright (c) 2002-2012 Croteam Ltd.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as published by
the Free Software Foundation
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
#include "Engine/StdH.h"
#include <Engine/Base/Serial.h>
#include <Engine/Base/Stream.h>
#include <Engine/Base/CRCTable.h>
/*
* Default constructor.
*/
CSerial::CSerial( void) : ser_ctUsed(0) // not used initially
{
}
/*
* Destructor.
*/
CSerial::~CSerial( void)
{
// must not be used at all
ASSERT(ser_ctUsed == 0); // look at _strLastCleared for possible name
}
/*
* Clear the object.
*/
void CSerial::Clear(void)
{
// mark that you have changed
MarkChanged();
// clear the filename
ser_FileName.Clear();
}
/* Get the description of this object. */
CTString CSerial::GetDescription(void)
{
return "<no description>";
}
/*
* Load from file.
*/
void CSerial::Load_t(const CTFileName fnFileName) // throw char *
{
ASSERT(!IsUsed());
// mark that you have changed
MarkChanged();
// open a stream
CTFileStream istrFile;
istrFile.Open_t(fnFileName);
// read object from stream
Read_t(&istrFile);
// if still here (no exceptions raised)
// remember filename
ser_FileName = fnFileName;
}
/*
* Reload from file.
*/
void CSerial::Reload(void)
{
// mark that you have changed
MarkChanged();
CTFileName fnmOldName = ser_FileName;
Clear();
// try to
//try {
// open a stream
CTFileStream istrFile;
istrFile.Open_t(fnmOldName);
// read object from stream
Read_t(&istrFile);
// if there is some error while reloading
//} catch (char *strError) {
// quit the application with error explanation
//FatalError(TRANS("Cannot reload file '%s':\n%s"), (const char *) (CTString&)fnmOldName, strError);
//}
// if still here (no exceptions raised)
// remember filename
ser_FileName = fnmOldName;
}
/*
* Save to file.
*/
void CSerial::Save_t(const CTFileName fnFileName) // throw char *
{
// open a stream
CTFileStream ostrFile;
ostrFile.Create_t(fnFileName);
// write object to stream
Write_t(&ostrFile);
// if still here (no exceptions raised)
// remember new filename
ser_FileName = fnFileName;
}
/*
* Mark that object is used once more.
*/
void CSerial::MarkUsed(void)
{
// use count must not have dropped below zero
ASSERT(ser_ctUsed>=0);
// increment use count
ser_ctUsed++;
}
/*
* Mark that object is used once less.
*/
void CSerial::MarkUnused(void)
{
// decrement use count
ser_ctUsed--;
// use count must not have dropped below zero
ASSERT(ser_ctUsed>=0);
}
/*
* Check if object is used at least once.
*/
BOOL CSerial::IsUsed(void)
{
// use count must not have dropped below zero
ASSERT(ser_ctUsed>=0);
return ser_ctUsed>0;
}
INDEX CSerial::GetUsedCount(void)
{
return ser_ctUsed;
}
// gather the CRC of the file
void CSerial::AddToCRCTable(void)
{
// add the file to CRC table
CRCT_AddFile_t(ser_FileName);
}