Refactor save size calculation with SaveSizeCounter

SaveSizeCounter is introduced and used for calculating the save size of objects. The previous method of calculating save size directly in each class was replaced with a call to the SaveSizeCounter's calc method. This results in a cleaner, more maintainable code as the size calculation logic is now centralized in one class. It is more efficient and scalable as any changes to the calculation can be made in one place and will be reflected everywhere.
This commit is contained in:
IlushaShurupov 2023-08-01 07:41:09 +03:00 committed by Ilya Shurupov
parent a679ab1c4b
commit e0eb6e138d
6 changed files with 30 additions and 15 deletions

View file

@ -1,9 +1,32 @@
#pragma once
#include "Common.hpp"
#include "Archiver.hpp"
namespace tp {
class SaveSizeCounter : public ArchiverTemplate<false> {
public:
SaveSizeCounter() = default;
template < typename tType>
static ualni calc(const tType& val) {
SaveSizeCounter cnt;
cnt << val;
return cnt.mSize;
}
protected:
void writeBytes(const int1* val, ualni size) override { mSize += size; }
void readBytes(int1* val, ualni size) override {}
[[nodiscard]] ualni getSize() const { return mSize; }
private:
ualni mSize = 0;
};
// TODO
template <bool tRecursive>
class SizeCounter {