1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

* vector<bool> serialization

This commit is contained in:
mateuszb 2013-02-04 16:58:31 +00:00
parent e63747d2d2
commit 3c5d6dd79a

View File

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