mirror of
https://github.com/fraillt/bitsery.git
synced 2026-10-23 17:20:58 +00:00
default values
This commit is contained in:
@@ -58,6 +58,20 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*
|
||||
* default overloads
|
||||
*/
|
||||
template<size_t VSIZE = 0, typename T, size_t N>
|
||||
Deserializer& defaultV(T& v, const std::array<T,N>& defValues) {
|
||||
size_t index;
|
||||
_reader.template readBits(index, calcRequiredBits<size_t>({}, N + 1));
|
||||
if (index)
|
||||
v = defValues[index-1];
|
||||
else
|
||||
ProcessAnyType<VSIZE>::serialize(*this, v);
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* text overloads
|
||||
*/
|
||||
|
||||
@@ -57,6 +57,17 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*
|
||||
* default overloads
|
||||
*/
|
||||
template<size_t VSIZE = 0, typename T, size_t N>
|
||||
Serializer& defaultV(const T& v, const std::array<T,N>& defValues) {
|
||||
auto index = findDefault(v, defValues);
|
||||
_writter.template writeBits(index, calcRequiredBits<size_t>({}, N + 1));
|
||||
if (!index)
|
||||
ProcessAnyType<VSIZE>::serialize(*this, v);
|
||||
};
|
||||
|
||||
/*
|
||||
* text overloads
|
||||
*/
|
||||
@@ -211,5 +222,20 @@ auto getRangeValue(const T& v, const RangeSpec<T>& r) {
|
||||
return static_cast<VT>(ratio * maxUint);
|
||||
};
|
||||
|
||||
/*
|
||||
* functions for default
|
||||
*/
|
||||
|
||||
template <typename T, size_t N>
|
||||
size_t findDefault(const T& v, const std::array<T,N>& defValues) {
|
||||
auto index{1u};
|
||||
for (auto& d:defValues) {
|
||||
if (d == v)
|
||||
return index;
|
||||
++index;
|
||||
}
|
||||
return 0u;
|
||||
};
|
||||
|
||||
|
||||
#endif //TMP_SERIALIZER_H
|
||||
|
||||
@@ -59,7 +59,6 @@ SERIALIZE(Y)
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
TEST(SerializeObject, GeneralConceptTest) {
|
||||
//std::string buf;
|
||||
SerializationContext ctx;
|
||||
|
||||
Reference in New Issue
Block a user