polserver/pol-core/pol/objecthash.h
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

84 lines
1.5 KiB
C++

/** @file
*
* @par History
*/
#ifndef __OBJECTHASH_H
#define __OBJECTHASH_H
#include <iosfwd>
#include <map>
#include <unordered_set>
#include <utility>
#include "../clib/rawtypes.h"
#include "reftypes.h"
namespace Pol
{
namespace Core
{
class UObject;
} // namespace Core
} // namespace Pol
namespace Pol
{
namespace Clib
{
class StreamWriter;
}
namespace Core
{
/*
template <class _Key> struct myhash { };
_STLP_TEMPLATE_nullptr struct myhash<UObject*> {
size_t operator()(UObject* obj) const { return obj->serial; }
};
*/
class ObjectHash
{
public:
typedef std::unordered_set<u32> ds;
typedef std::pair<u32, UObjectRef> hashpair;
typedef std::map<u32, UObjectRef> hs;
typedef hs::iterator OH_iterator;
typedef hs::const_iterator OH_const_iterator;
ObjectHash();
~ObjectHash();
bool Insert( UObject* obj );
bool Remove( u32 serial );
void Clear( bool shutdown = true );
void Reap();
UObject* Find( u32 serial );
u32 GetNextUnusedItemSerial();
u32 GetNextUnusedCharSerial();
void PrintContents( std::ofstream* os ) const;
hs::const_iterator begin() const;
hs::const_iterator end() const;
void ClearCharacterAccountReferences();
ds::const_iterator dirty_deleted_begin() const;
ds::const_iterator dirty_deleted_end() const;
void CleanDeleted();
void ClearDeleted();
void RegisterCleanDeletedSerial( u32 serial );
private:
hs hash;
OH_iterator reap_iterator;
ds dirty_deleted;
ds clean_deleted;
};
} // namespace Core
} // namespace Pol
#endif