File: datastructures.cpp

package info (click to toggle)
fraqtive 0.4.3-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 988 kB
  • ctags: 1,249
  • sloc: cpp: 8,387; sh: 103; makefile: 45
file content (200 lines) | stat: -rw-r--r-- 5,480 bytes parent folder | download
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**************************************************************************
* This file is part of the Fraqtive program
* Copyright (C) 2004-2008 Michał Męciński
*
* 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.
**************************************************************************/

#include "datastructures.h"
#include "datafunctions.h"
#include "fraqtiveapplication.h"
#include "configurationdata.h"

#include <QDataStream>

QDataStream& operator <<( QDataStream& stream, const FractalType& type )
{
    stream << (qint8)type.m_fractal;
    if ( type.m_fractal == JuliaFractal )
        stream << type.m_parameter;

    stream << (qint8)type.m_exponentType;
    if ( type.m_exponentType == IntegralExponent )
        stream << (qint8)type.m_integralExponent;
    else if ( type.m_exponentType == RealExponent )
        stream << type.m_realExponent;

    stream << (qint8)type.m_variant;

    return stream;
}

QDataStream& operator >>( QDataStream& stream, FractalType& type )
{
    qint8 fractal, exponentType, exponent, variant;

    stream >> fractal;
    type.m_fractal = (Fractal)fractal;
    if ( fractal == JuliaFractal )
        stream >> type.m_parameter;

    stream >> exponentType;
    type.m_exponentType = (ExponentType)exponentType;

    if ( exponentType == IntegralExponent ) {
        stream >> exponent;
        type.m_integralExponent = exponent;
    } else if ( exponentType == RealExponent ) {
        stream >> type.m_realExponent;
    }

    stream >> variant;
    type.m_variant = (GeneratorCore::Variant)variant;

    return stream;
}

QDataStream& operator <<( QDataStream& stream, const Position& position )
{
    return stream
        << position.m_center
        << position.m_zoomFactor
        << position.m_angle;
}

QDataStream& operator >>( QDataStream& stream, Position& position )
{
    return stream
        >> position.m_center
        >> position.m_zoomFactor
        >> position.m_angle;
}

bool Gradient::isEmpty() const
{
    return m_red.isEmpty() || m_green.isEmpty() || m_blue.isEmpty();
}

QDataStream& operator <<( QDataStream& stream, const Gradient& gradient )
{
    return stream
        << gradient.m_red
        << gradient.m_green
        << gradient.m_blue;
}

QDataStream& operator >>( QDataStream& stream, Gradient& gradient )
{
    return stream
        >> gradient.m_red
        >> gradient.m_green
        >> gradient.m_blue;
}

QDataStream& operator <<( QDataStream& stream, const ColorMapping& mapping )
{
    return stream
        << mapping.m_mirrored
        << mapping.m_reversed
        << mapping.m_scale
        << mapping.m_offset;
}

QDataStream& operator >>( QDataStream& stream, ColorMapping& mapping )
{
    return stream
        >> mapping.m_mirrored
        >> mapping.m_reversed
        >> mapping.m_scale
        >> mapping.m_offset;
}

QDataStream& operator <<( QDataStream& stream, const GeneratorSettings& settings )
{
    return stream
        << settings.m_calculationDepth
        << settings.m_detailThreshold;
}

QDataStream& operator >>( QDataStream& stream, GeneratorSettings& settings )
{
    return stream
        >> settings.m_calculationDepth
        >> settings.m_detailThreshold;
}

QDataStream& operator <<( QDataStream& stream, const ViewSettings& settings )
{
    return stream << (qint8)settings.m_antiAliasing
        << (qint8)settings.m_meshResolution
        << settings.m_heightScale
        << settings.m_cameraZoom;
}

QDataStream& operator >>( QDataStream& stream, ViewSettings& settings )
{
    int version = fraqtive()->configuration()->dataVersion();

    if ( version < 2 )
        settings = DataFunctions::defaultViewSettings();

    qint8 antiAliasing;
    stream >> antiAliasing;
    settings.m_antiAliasing = (AntiAliasing)antiAliasing;

    if ( version >= 2 ) {
        qint8 resolution;
        stream >> resolution;
        settings.m_meshResolution = (Resolution)resolution;

        stream >> settings.m_heightScale
            >> settings.m_cameraZoom;
    }

    return stream;
}

QDataStream& operator <<( QDataStream& stream, const Bookmark& bookmark )
{
    return stream
        << bookmark.m_fractalType
        << bookmark.m_position;
}

QDataStream& operator >>( QDataStream& stream, Bookmark& bookmark )
{
    return stream
        >> bookmark.m_fractalType
        >> bookmark.m_position;
}

QDataStream& operator <<( QDataStream& stream, const Preset& preset )
{
    return stream
        << preset.m_gradient
        << preset.m_backgroundColor
        << preset.m_colorMapping;
}

QDataStream& operator >>( QDataStream& stream, Preset& preset )
{
    return stream
        >> preset.m_gradient
        >> preset.m_backgroundColor
        >> preset.m_colorMapping;
}

void registerDataStructures()
{
    qRegisterMetaTypeStreamOperators<FractalType>( "FractalType" );
    qRegisterMetaTypeStreamOperators<Position>( "Position" );
    qRegisterMetaTypeStreamOperators<Gradient>( "Gradient" );
    qRegisterMetaTypeStreamOperators<ColorMapping>( "ColorMapping" );
    qRegisterMetaTypeStreamOperators<GeneratorSettings>( "GeneratorSettings" );
    qRegisterMetaTypeStreamOperators<ViewSettings>( "ViewSettings" );
    qRegisterMetaTypeStreamOperators<Bookmark>( "Bookmark" );
    qRegisterMetaTypeStreamOperators<Preset>( "Preset" );
}