mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-03 13:01:33 +02:00
Serializer: serialize small bitsets (32 bits)
This commit is contained in:
parent
6ff83e6f16
commit
e9a90a8cbf
@ -550,6 +550,29 @@ public:
|
||||
for(ui32 i = 0; i < length; i++)
|
||||
load(data.data()[i]);
|
||||
}
|
||||
template <std::size_t T>
|
||||
void load(std::bitset<T> &data)
|
||||
{
|
||||
static_assert(T <= 64);
|
||||
if constexpr (T <= 16)
|
||||
{
|
||||
uint16_t read;
|
||||
load(read);
|
||||
data = read;
|
||||
}
|
||||
else if constexpr (T <= 32)
|
||||
{
|
||||
uint32_t read;
|
||||
load(read);
|
||||
data = read;
|
||||
}
|
||||
else if constexpr (T <= 64)
|
||||
{
|
||||
uint64_t read;
|
||||
load(read);
|
||||
data = read;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CLoadFile : public IBinaryReader
|
||||
|
@ -364,6 +364,26 @@ public:
|
||||
for(ui32 i = 0; i < length; i++)
|
||||
save(data.data()[i]);
|
||||
}
|
||||
template <std::size_t T>
|
||||
void save(const std::bitset<T> &data)
|
||||
{
|
||||
static_assert(T <= 64);
|
||||
if constexpr (T <= 16)
|
||||
{
|
||||
auto writ = static_cast<uint16_t>(data.to_ulong());
|
||||
save(writ);
|
||||
}
|
||||
else if constexpr (T <= 32)
|
||||
{
|
||||
auto writ = static_cast<uint32_t>(data.to_ulong());
|
||||
save(writ);
|
||||
}
|
||||
else if constexpr (T <= 64)
|
||||
{
|
||||
auto writ = static_cast<uint64_t>(data.to_ulong());
|
||||
save(writ);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CSaveFile : public IBinaryWriter
|
||||
|
@ -54,7 +54,7 @@ struct VectorizedObjectInfo
|
||||
class DLL_LINKAGE CSerializer
|
||||
{
|
||||
template<typename T>
|
||||
static si32 idToNumber(const T &t, typename boost::enable_if<boost::is_convertible<T,si32> >::type * dummy = 0)
|
||||
static si32 idToNumber(const T &t, typename std::enable_if<std::is_convertible<T,si32>::value>::type * dummy = 0)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user