My favorites | Sign in
Project Home Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/********************************************\
*
* Sire - Molecular Simulation Framework
*
* Copyright (C) 2009 Christopher Woods
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* For full details of the license please see the COPYING file
* that should have come with this distribution.
*
* You can contact the authors via the developer's mailing list
* at http://siremol.org
*
\*********************************************/

#ifndef SIREN_DATASTREAM_H
#define SIREN_DATASTREAM_H

#include "stream.h"

SIREN_BEGIN_HEADER

namespace Siren
{

class SharedDataRegistry;

/** This is a streaming class that is used to help stream implicitly shared data.
This class ensures that only a single copy of the implicitly shared data is actually
written to the stream, thus reducing data bloat, and also preserving the shared data
of the objects when they are read back into the program.

@author Christopher Woods
*/
class SIREN_EXPORT DataStream : public ImplementsHandle<DataStream,Stream>
{
public:
DataStream();
DataStream(QIODevice *d);
DataStream(QByteArray *a, QIODevice::OpenMode mode);
DataStream(const QByteArray &a);

DataStream(QDataStream &ds);

DataStream(const DataStream &other);

~DataStream();

DataStream& operator=(const DataStream &other);

bool operator==(const DataStream &other) const;
bool operator!=(const DataStream &other) const;

DataStream& operator&(bool &b);

DataStream& operator&(qint8 &i);
DataStream& operator&(quint8 &i);
DataStream& operator&(quint16 &i);
DataStream& operator&(qint16 &i);
DataStream& operator&(qint32 &i);
DataStream& operator&(quint64 &i);
DataStream& operator&(qint64 &i);
DataStream& operator&(quint32 &i);

DataStream& operator&(float &f);
DataStream& operator&(double &f);

uint hashCode() const;
QString toString() const;

protected:
void startItem(const QString &type_name);
int startArray(const QString &type_name, int count);
int startSet(const QString &type_name, int count);
int startMap(const QString &key_type, const QString &value_type,
int count, bool allow_duplicates);

void nextData(const char *data_name);
void nextBase();

void nextIndex(int i);

void nextEntry();

void nextKey();
void nextValue();

void endItem(const QString &type_name);
void endArray(const QString &type_name);
void endSet(const QString &type_name);
void endMap(const QString &key_type, const QString &value_type);

int readReference();
void createReference(int id);

void startTarget(int id);
void endTarget(int id);

int readStringReference();
void createStringReference(int id);

QString readString(int id);
void writeString(int id, const QString &text);

int readBlobReference();
void createBlobReference(int id);

QByteArray readBlob(int id);
void writeBlob(int id, const QByteArray &blob);

int readClassID(const QString &class_name, int &version);
void writeClassID(const QString &class_name, int id, int version);

QString peekNextType();

int readMagic();
void writeMagic(int magic);

private:
void registerDataStream();

/** Shared pointer to a datastream is one had to be created */
boost::shared_ptr<QDataStream> ds_ptr;

/** The version number of the DataStream format */
int ds_version;

/** Reference to the active datastream */
QDataStream *ds;
};

} // end of namespace Siren

Q_DECLARE_METATYPE( Siren::DataStream )

SIREN_EXPOSE_CLASS( Siren::DataStream )

SIREN_END_HEADER

#endif

Change log

r1108 by chryswoods on Nov 25, 2009   Diff
I've updated the metatype system so that
it works fully for Primitive and Handle
types.
Now Number and String work (and
.getClass() works for them too!)

The only test failures from sirentest are
Logger, DataStream and XMLStream, who all
complain that I haven't yet written unit
tests for them!

Go to: 
Sign in to write a code review

Older revisions

r1103 by chryswoods on Nov 21, 2009   Diff
I am making progress writing the
XMLStream class...

Siren is broken

r1102 by chryswoods on Nov 20, 2009   Diff
I've got Siren compiled and linked,
and have got (most) of the python
wrappers working.
The code works, to an extent, but
there are quite a few problems and
...
r1100 by chryswoods on Nov 19, 2009   Diff
I've fixed the streaming bug on AIX -
I had forgot the prototype for
SireCAS::Constant, so the
ExBase streaming functions were called
directly in place of the
...
All revisions of this file

File info

Size: 4385 bytes, 153 lines
Powered by Google Project Hosting