1 /***************************************************************************
2 Copyright 2006 David Nolden <david.nolden.kdevelop@art-master.de>
3 ***************************************************************************/
5 /***************************************************************************
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 ***************************************************************************/
14 #ifndef QTSERIALIZATION_H
15 #define QTSERIALIZATION_H
17 #include "lib/network/serialization.h"
18 #include <boost/serialization/split_free.hpp>
19 #include <boost/serialization/level.hpp>
20 #include <boost/serialization/binary_object.hpp>
21 #include <QDataStream>
22 #include <QTextStream>
31 namespace serialization
{
32 template <class Archive
>
33 void load( Archive
& arch
, QByteArray
& b
, const unsigned int /*version*/ ) {
38 binary_object
o( b
.data(), b
.size() );
42 template <class Archive
>
43 void save( Archive
& arch
, const QByteArray
& b
, const unsigned int /*version*/ ) {
46 binary_object
o( const_cast<QByteArray
&>( b
).data(), b
.size() );
52 BOOST_SERIALIZATION_SPLIT_FREE( QByteArray
)
54 ///Usually uses a QDataStream to convert to a binary object, and stores that.
59 QSerialize( const Type
& t
) : m_t( const_cast<Type
&>( t
) ) {}
61 template <class Archive
>
62 void save( Archive
& arch
, unsigned int /*version*/ ) const {
64 QDataStream
s( &b
, QIODevice::WriteOnly
);
69 template <class Archive
>
70 void load( Archive
& arch
, unsigned int /*version*/ ) {
74 QDataStream
s( &b
, QIODevice::ReadOnly
);
78 BOOST_SERIALIZATION_SPLIT_MEMBER()
81 /**This function returns a temporary serialization-object that can be used to serialize Qt-Types using the boost-serialization-library. */
83 QSerialize
<Type
> qStore( const Type
& t
) {
84 return QSerialize
<Type
>( t
);
88 namespace serialization
{
90 template <class Archive
>
91 void serialize( Archive
& ar
, QString
& str
, const unsigned int /*version*/ ) {
92 QSerialize
<QString
> s( str
);
96 template <class Archive
>
97 void serialize( Archive
& ar
, QStringList
& t
, const unsigned int /*version*/ ) {
98 QSerialize
<QStringList
> s( t
);
102 template <class Archive
>
103 void serialize( Archive
& ar
, QVariant
& t
, const unsigned int /*version*/ ) {
104 QSerialize
<QVariant
> s( t
);
107 } // namespace serialization
110 ///Tell boost not to store type-information for QSerialize<T>
112 namespace serialization
{
114 struct implementation_level
< QSerialize
<T
> > {
115 typedef mpl::integral_c_tag tag
;
116 typedef mpl::int_
< object_serializable
> type
;
117 BOOST_STATIC_CONSTANT(
119 value
= implementation_level::type::value
125 BOOST_CLASS_IMPLEMENTATION(QString
, object_serializable
)
126 BOOST_CLASS_IMPLEMENTATION(QStringList
, object_serializable
)
127 BOOST_CLASS_IMPLEMENTATION(QVariant
, object_serializable
)
128 BOOST_CLASS_IMPLEMENTATION(QByteArray
, object_serializable
)
133 // kate: space-indent on; indent-width 2; tab-width 2; replace-tabs on