mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-31 16:15:35 +00:00
a58f1a94e3
To construct serializer from given entities: * Data source/destination - any value that has to be serialized/deserialized, usually already existing type. * Format - functional object to define high level serialization logic to define specific format and data schema. Like order of fields, allocation. * Visitor - functional object to define low level serialization logic to operator on given data part. * BinaryWriter - copies given value into provided buffer. * BinaryReader - copies value into given destination from provided buffer. * SizeAccumulator - calculates required buffer size for given data.
41 lines
1 KiB
C++
41 lines
1 KiB
C++
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_SERIALIZATION_SIZEACCUMULATOR_H
|
|
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_SERIALIZATION_SIZEACCUMULATOR_H
|
|
|
|
#include <cstddef>
|
|
#include <type_traits>
|
|
|
|
namespace DetourNavigator::Serialization
|
|
{
|
|
class SizeAccumulator
|
|
{
|
|
public:
|
|
SizeAccumulator() = default;
|
|
|
|
SizeAccumulator(const SizeAccumulator&) = delete;
|
|
|
|
std::size_t value() const { return mValue; }
|
|
|
|
template <class Format, class T>
|
|
void operator()(Format&& format, const T& value)
|
|
{
|
|
if constexpr (std::is_arithmetic_v<T>)
|
|
mValue += sizeof(T);
|
|
else
|
|
format(*this, value);
|
|
}
|
|
|
|
template <class Format, class T>
|
|
auto operator()(Format&& format, const T* data, std::size_t count)
|
|
{
|
|
if constexpr (std::is_arithmetic_v<T>)
|
|
mValue += count * sizeof(T);
|
|
else
|
|
format(*this, data, count);
|
|
}
|
|
|
|
private:
|
|
std::size_t mValue = 0;
|
|
};
|
|
}
|
|
|
|
#endif
|