polserver/pol-core/clib/streamsaver.cpp
turleypol 08bd3c7ce5
Savefile rewrite (#601)
* rewrite of saving, replaced operator way with a generic add method, thus
not everywhere the formating of the savefiles is hardcoded.
since its the last spot which uses the old formating lib, remobed the
lib

* removed cmake of old format lib

* testscripts for load/save of UObject,Item,Armor,Weapon

* fixed: member faster_cast_recovery and faster_cast_recovery_mod getter returned
a wrong value

* wrong/missing docs

* test containers, lockable, map, spellbooks
fixed save bug in map and spellbook
removed ancient savestrategy experiments

* added corpse test
splitted testfiles

* fixed loading (ancient bug) and saving (PR bug) of Reportables
added tests for houses, boats, accounts and chars

* fixed include

* fix shutdown leak

* added npc tests
upload complete coretest folder also on failure

* do not write and load RegisteredHouse for NPCs two times
readded extra newline between accounts

* tests for guild, party, realm
added resource cfgs, but a test is not really possible since nothing of
interest is stored

* added datafile, storage test

* activated resource loading, 25year old bug, but since the stored values
are senseless it makes no real difference.
added a few wtf comments
catch all exceptions during formatting of log lines

* replaced .write with explixit .begin, .end and .comment.
for leftovers.txt the StreamSaver was also used, since the format is
different use directly ofstream

* added corechanges
2024-01-24 18:49:06 +01:00

77 lines
1.3 KiB
C++

#include <fstream>
#include <iostream>
#include <string>
#include "streamsaver.h"
namespace Pol
{
namespace Clib
{
const std::size_t flush_limit = 10000; // 500;
void StreamWriter::flush_test()
{
if ( _buf.size() >= flush_limit ) // guard against to big objects
flush();
}
StreamWriter::StreamWriter( std::ofstream* stream )
: _stream( stream ),
#if 0
_fs_time( 0 ),
#endif
_stream_name()
{
}
StreamWriter::~StreamWriter()
{
#if 0
if ( !_buf.empty() )
{
Tools::HighPerfTimer t;
*_stream << _buf;
_fs_time += t.ellapsed();
}
ERROR_PRINTLN( "streamwriter {} io time {}", _stream_name, _fs_time.count() );
#else
if ( !_buf.empty() && _stream )
*_stream << _buf;
#endif
}
void StreamWriter::init( const std::string& filepath )
{
if ( _stream )
{
_stream->exceptions( std::ios_base::failbit | std::ios_base::badbit );
_stream->open( filepath.c_str(), std::ios::out | std::ios::trunc );
}
_stream_name = filepath;
}
void StreamWriter::flush()
{
#if 0
Tools::HighPerfTimer t;
#endif
if ( !_buf.empty() && _stream )
{
*_stream << _buf;
_buf.clear();
}
#if 0
_fs_time += t.ellapsed( );
#endif
}
void StreamWriter::flush_file()
{
flush();
if ( _stream )
_stream->flush();
}
} // namespace Clib
} // namespace Pol