mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	* vector<bool> serialization
This commit is contained in:
		| @@ -77,7 +77,8 @@ enum SerializationLvl | ||||
| 	Array, | ||||
| 	Pointer, | ||||
| 	Enum, | ||||
| 	Serializable | ||||
| 	Serializable, | ||||
| 	BooleanVector | ||||
| }; | ||||
|  | ||||
|  | ||||
| @@ -136,6 +137,24 @@ struct LoadBoolean | ||||
| 		s.loadBoolean(data); | ||||
| 	} | ||||
| }; | ||||
|  | ||||
| template<typename Ser> | ||||
| struct SaveBooleanVector | ||||
| { | ||||
| 	static void invoke(Ser &s, const bool &data) | ||||
| 	{ | ||||
| 		s.saveBooleanVector(data); | ||||
| 	} | ||||
| }; | ||||
| template<typename Ser> | ||||
| struct LoadBooleanVector | ||||
| { | ||||
| 	static void invoke(Ser &s, bool &data) | ||||
| 	{ | ||||
| 		s.loadBooleanVector(data); | ||||
| 	} | ||||
| }; | ||||
|  | ||||
| template<typename Ser,typename T> | ||||
| struct SavePrimitive | ||||
| { | ||||
| @@ -244,6 +263,10 @@ struct SerializationLevel | ||||
| 			boost::is_same<T, bool>, | ||||
| 			mpl::int_<Boolean>, | ||||
| 		//else | ||||
| 		typename mpl::eval_if< | ||||
| 			boost::is_same<T, std::vector<bool> >, | ||||
| 			mpl::int_<BooleanVector>, | ||||
| 		//else | ||||
| 		typename mpl::eval_if< | ||||
| 			boost::is_fundamental<T>, | ||||
| 			mpl::int_<Primitive>, | ||||
| @@ -275,6 +298,7 @@ struct SerializationLevel | ||||
| 		> | ||||
| 		> | ||||
| 		> | ||||
| 		> | ||||
| 		>::type type; | ||||
| 	static const int value = SerializationLevel::type::value; | ||||
| }; | ||||
| @@ -608,6 +632,9 @@ public: | ||||
| 			typename mpl::eval_if< mpl::equal_to<SerializationLevel<T>,mpl::int_<Boolean> >, | ||||
| 			mpl::identity<SaveBoolean<Serializer> >, | ||||
| 			//else if | ||||
| 			typename mpl::eval_if< mpl::equal_to<SerializationLevel<T>,mpl::int_<BooleanVector> >, | ||||
| 			mpl::identity<SaveBooleanVector<Serializer> >, | ||||
| 			//else if | ||||
| 			typename mpl::eval_if< mpl::equal_to<SerializationLevel<T>,mpl::int_<Primitive> >, | ||||
| 			mpl::identity<SavePrimitive<Serializer,T> >, | ||||
| 			//else if | ||||
| @@ -629,6 +656,7 @@ public: | ||||
| 			> | ||||
| 			> | ||||
| 			> | ||||
| 			> | ||||
| 			>::type typex; | ||||
| 		typex::invoke(* this->This(), data); | ||||
| 	} | ||||
| @@ -721,6 +749,12 @@ public: | ||||
| 		ui8 writ = static_cast<ui8>(data); | ||||
| 		*this << writ; | ||||
| 	} | ||||
| 	void saveBooleanVector(const std::vector<bool> & data) | ||||
| 	{ | ||||
| 		std::vector<ui8> convData; | ||||
| 		std::copy(data.begin(), data.end(), convData.begin()); | ||||
| 		saveSerializable(convData); | ||||
| 	} | ||||
| }; | ||||
|  | ||||
|  | ||||
| @@ -813,6 +847,9 @@ public: | ||||
| 			typename mpl::eval_if< mpl::equal_to<SerializationLevel<T>,mpl::int_<Boolean> >, | ||||
| 			mpl::identity<LoadBoolean<Serializer> >, | ||||
| 			//else if | ||||
| 			typename mpl::eval_if< mpl::equal_to<SerializationLevel<T>,mpl::int_<BooleanVector> >, | ||||
| 			mpl::identity<LoadBooleanVector<Serializer> >, | ||||
| 			//else if | ||||
| 			typename mpl::eval_if< mpl::equal_to<SerializationLevel<T>,mpl::int_<Primitive> >, | ||||
| 			mpl::identity<LoadPrimitive<Serializer,T> >, | ||||
| 			//else if | ||||
| @@ -834,6 +871,7 @@ public: | ||||
| 			> | ||||
| 			> | ||||
| 			> | ||||
| 			> | ||||
| 			>::type typex; | ||||
| 		typex::invoke(* this->This(), data); | ||||
| 	} | ||||
| @@ -1091,6 +1129,12 @@ public: | ||||
| 		*this >> read; | ||||
| 		data = static_cast<bool>(read); | ||||
| 	} | ||||
| 	void loadBooleanVector(std::vector<bool> & data) | ||||
| 	{ | ||||
| 		std::vector<ui8> convData; | ||||
| 		loadSerializable(convData); | ||||
| 		std::copy(convData.begin(), convData.end(), data.begin()); | ||||
| 	} | ||||
| }; | ||||
|  | ||||
| class DLL_LINKAGE CSaveFile | ||||
|   | ||||
		Reference in New Issue
	
	Block a user