forked from blue/lmdbal
some more docs, doc build fix
This commit is contained in:
parent
161a850088
commit
7b26d57ab6
6 changed files with 85 additions and 10 deletions
|
@ -21,6 +21,21 @@
|
|||
|
||||
#include "serializer.h"
|
||||
|
||||
/**
|
||||
* \class LMDBAL::Serializer
|
||||
*
|
||||
* A class that is constructed in every LMDBAL::Storage
|
||||
* to serialize or deserialize keys and values.
|
||||
*
|
||||
* It serializes to and deserializes from <a class="el" href="http://www.lmdb.tech/doc/group__mdb.html#structMDB__val">MDB_val</a>MDB_val
|
||||
*
|
||||
* \tparam K type of the keys of the storage
|
||||
* \tparam V type of the values of the storage
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Creates an empty Serializer
|
||||
*/
|
||||
template<class T>
|
||||
LMDBAL::Serializer<T>::Serializer() :
|
||||
bytes(),
|
||||
|
@ -30,6 +45,13 @@ LMDBAL::Serializer<T>::Serializer() :
|
|||
buffer.open(QIODevice::ReadWrite);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Creates a Serializer with some data in it
|
||||
*
|
||||
* The data automatically gets serialized
|
||||
*
|
||||
* \param[in] value - a value that is assigned to the serializer
|
||||
*/
|
||||
template<class T>
|
||||
LMDBAL::Serializer<T>::Serializer(const T& value) :
|
||||
bytes(),
|
||||
|
@ -40,11 +62,23 @@ LMDBAL::Serializer<T>::Serializer(const T& value) :
|
|||
_setData(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Destoys the serializer
|
||||
*/
|
||||
template<class T>
|
||||
LMDBAL::Serializer<T>::~Serializer() {
|
||||
buffer.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sets the data to the seriazer
|
||||
*
|
||||
* This is a normal way to seriaze value
|
||||
*
|
||||
* \param[in] value - a value you want to serialize
|
||||
*
|
||||
* \returns serialized value
|
||||
*/
|
||||
template<class T>
|
||||
MDB_val LMDBAL::Serializer<T>::setData(const T& value) {
|
||||
clear();
|
||||
|
@ -52,6 +86,15 @@ MDB_val LMDBAL::Serializer<T>::setData(const T& value) {
|
|||
return getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Deserializes value
|
||||
*
|
||||
* This is a normal way to deseriaze value
|
||||
*
|
||||
* \param[in] value - a value you want to deserialize
|
||||
*
|
||||
* \returns deserialized value
|
||||
*/
|
||||
template<class T>
|
||||
T LMDBAL::Serializer<T>::deserialize(const MDB_val& value) {
|
||||
T result;
|
||||
|
@ -60,6 +103,14 @@ T LMDBAL::Serializer<T>::deserialize(const MDB_val& value) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Deserializes value
|
||||
*
|
||||
* This is a normal way to deseriaze value
|
||||
*
|
||||
* \param[in] value - a value you want to deserialize
|
||||
* \param[out] result - deserialized value
|
||||
*/
|
||||
template<class T>
|
||||
void LMDBAL::Serializer<T>::deserialize(const MDB_val& value, T& result) {
|
||||
clear();
|
||||
|
@ -67,11 +118,21 @@ void LMDBAL::Serializer<T>::deserialize(const MDB_val& value, T& result) {
|
|||
stream >> result;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Private function that handles serialization
|
||||
*
|
||||
* \param[in] value - a value you want to serialize
|
||||
*/
|
||||
template<class T>
|
||||
void LMDBAL::Serializer<T>::_setData(const T& value) {
|
||||
stream << value;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Clears the state of serializer
|
||||
*
|
||||
* Normally you don't need to call this function
|
||||
*/
|
||||
template<class T>
|
||||
void LMDBAL::Serializer<T>::clear() {
|
||||
if (buffer.pos() > 0) {
|
||||
|
@ -79,6 +140,15 @@ void LMDBAL::Serializer<T>::clear() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the data if it already was serialized
|
||||
*
|
||||
* Normally you don't need to call this function
|
||||
*
|
||||
* This may be usefull if you called LMDBAL::Serilizer::setData() but lost the result
|
||||
*
|
||||
* \returns Serialized data
|
||||
*/
|
||||
template<class T>
|
||||
MDB_val LMDBAL::Serializer<T>::getData() {
|
||||
MDB_val val;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue