2
0
Эх сурвалжийг харах

Serializer: serialize small bitsets (32 bits)

Konstantin P 2 жил өмнө
parent
commit
e9a90a8cbf

+ 23 - 0
lib/serializer/BinaryDeserializer.h

@@ -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

+ 20 - 0
lib/serializer/BinarySerializer.h

@@ -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

+ 1 - 1
lib/serializer/CSerializer.h

@@ -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;
 	}