Fix no newlines warnings. Patch by Peter Oberndorfer
[kdevelopdvcssupport.git] / plugins / teamwork / qtserialization.h
blob4de60b71edd1667442f4a9d9c4fa1e97ba845dec
1 /***************************************************************************
2 Copyright 2006 David Nolden <david.nolden.kdevelop@art-master.de>
3 ***************************************************************************/
5 /***************************************************************************
6 * *
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. *
11 * *
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>
23 #include <QByteArray>
24 #include <QVariant>
25 #include <vector>
26 #include <QString>
27 #include <string>
28 #include <iostream>
30 namespace boost {
31 namespace serialization {
32 template <class Archive>
33 void load( Archive & arch, QByteArray& b, const unsigned int /*version*/ ) {
34 uint size;
35 arch & size;
36 b.resize( size );
38 binary_object o( b.data(), b.size() );
39 arch & o;
42 template <class Archive>
43 void save( Archive & arch, const QByteArray& b, const unsigned int /*version*/ ) {
44 uint size = b.size();
45 arch & size;
46 binary_object o( const_cast<QByteArray&>( b ).data(), b.size() );
47 arch & o;
52 BOOST_SERIALIZATION_SPLIT_FREE( QByteArray )
54 ///Usually uses a QDataStream to convert to a binary object, and stores that.
55 template <class Type>
56 class QSerialize {
57 Type& m_t;
58 public:
59 QSerialize( const Type& t ) : m_t( const_cast<Type&>( t ) ) {}
61 template <class Archive>
62 void save( Archive& arch, unsigned int /*version*/ ) const {
63 QByteArray b;
64 QDataStream s( &b, QIODevice::WriteOnly );
65 s << m_t;
66 arch & b;
69 template <class Archive>
70 void load( Archive& arch, unsigned int /*version*/ ) {
71 QByteArray b;
72 arch & b;
74 QDataStream s( &b, QIODevice::ReadOnly );
75 s >> m_t;
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. */
82 template <class Type>
83 QSerialize<Type> qStore( const Type& t ) {
84 return QSerialize<Type>( t );
87 namespace boost {
88 namespace serialization {
90 template <class Archive>
91 void serialize( Archive & ar, QString& str, const unsigned int /*version*/ ) {
92 QSerialize<QString> s( str );
93 ar & s;
96 template <class Archive>
97 void serialize( Archive & ar, QStringList& t, const unsigned int /*version*/ ) {
98 QSerialize<QStringList> s( t );
99 ar & s;
102 template <class Archive>
103 void serialize( Archive & ar, QVariant& t, const unsigned int /*version*/ ) {
104 QSerialize<QVariant> s( t );
105 ar & s;
107 } // namespace serialization
108 } // namespace
110 ///Tell boost not to store type-information for QSerialize<T>
111 namespace boost {
112 namespace serialization {
113 template <class T>
114 struct implementation_level< QSerialize<T> > {
115 typedef mpl::integral_c_tag tag;
116 typedef mpl::int_< object_serializable > type;
117 BOOST_STATIC_CONSTANT(
118 int,
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)
131 #endif
133 // kate: space-indent on; indent-width 2; tab-width 2; replace-tabs on