src/types.cpp

Sun, 07 Jul 2013 16:46:30 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sun, 07 Jul 2013 16:46:30 +0300
changeset 358
7885fa5b09c5
parent 322
5e701c3c3d8e
child 380
e442d9b7c251
permissions
-rw-r--r--

restyle..

230
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
1 /*
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
2 * LDForge: LDraw parts authoring CAD
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
3 * Copyright (C) 2013 Santeri Piippo
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
4 *
230
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
5 * This program is free software: you can redistribute it and/or modify
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
6 * it under the terms of the GNU General Public License as published by
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
8 * (at your option) any later version.
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
9 *
230
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
10 * This program is distributed in the hope that it will be useful,
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
13 * GNU General Public License for more details.
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
14 *
230
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
15 * You should have received a copy of the GNU General Public License
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
17 */
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
18
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
19 #include <QObject>
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
20 #include <QStringList>
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
21 #include <QTextStream>
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
22 #include <qfile.h>
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <assert.h>
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include "common.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "types.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "misc.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
28 const File nullfile;
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
29
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
30 str DoFormat( vector<StringFormatArg> args )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
31 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
32 assert( args.size() >= 1 );
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
33 str text = args[0].value();
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
34
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
35 for( uchar i = 1; i < args.size(); ++i )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
36 text = text.arg( args[i].value() );
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
37
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
38 return text;
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
39 }
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
40
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
41 vertex::vertex( double x, double y, double z )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
42 {
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
43 m_coords[X] = x;
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
44 m_coords[Y] = y;
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
45 m_coords[Z] = z;
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
46 }
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
47
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 // =============================================================================
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
49 void vertex::move( const vertex& other )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
50 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
51 for( const Axis ax : g_Axes )
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
52 m_coords[ax] += other[ax];
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
53 }
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
54
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 // =============================================================================
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
56 vertex vertex::midpoint( const vertex& other )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
57 {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 vertex mid;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
60 for( const Axis ax : g_Axes )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
61 mid[ax] = ( m_coords[ax] + other[ax] ) / 2;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 return mid;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 // =============================================================================
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
67 str vertex::stringRep( bool mangled ) const
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
68 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
69 str fmtstr = "%1 %2 %3";
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
70 if( mangled )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
71 fmtstr = "(%1, %2, %3)";
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
72
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
73 return fmt( fmtstr, coord( X ), coord( Y ), coord( Z ));
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 // =============================================================================
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
77 void vertex::transform( matrix matr, vertex pos )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
78 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
79 double x2 = ( matr[0] * x()) + ( matr[1] * y()) + ( matr[2] * z()) + pos[X];
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
80 double y2 = ( matr[3] * x()) + ( matr[4] * y()) + ( matr[5] * z()) + pos[Y];
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
81 double z2 = ( matr[6] * x()) + ( matr[7] * y()) + ( matr[8] * z()) + pos[Z];
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
83 x() = x2;
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
84 y() = y2;
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
85 z() = z2;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
88 vertex vertex::operator-() const
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
89 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
90 return vertex( -m_coords[X], -m_coords[Y], -m_coords[Z] );
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
91 }
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
92
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
93 bool vertex::operator!= ( const vertex& other ) const
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
94 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
95 return !operator== ( other );
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
96 }
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
97
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
98 double& vertex::operator[]( const Axis ax )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
99 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
100 return coord( ( ushort ) ax );
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
101 }
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
102
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
103 const double& vertex::operator[]( const Axis ax ) const
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
104 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
105 return coord( ( ushort ) ax );
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
106 }
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
107
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
108 double& vertex::operator[]( const int ax )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
109 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
110 return coord( ax );
219
70eb948a2b02 Added ability to set the depth value to something else than 0.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
111 }
70eb948a2b02 Added ability to set the depth value to something else than 0.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
112
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
113 const double& vertex::operator[]( const int ax ) const
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
114 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
115 return coord( ax );
219
70eb948a2b02 Added ability to set the depth value to something else than 0.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
116 }
70eb948a2b02 Added ability to set the depth value to something else than 0.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
117
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
118 bool vertex::operator== ( const vertex& other ) const
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
119 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
120 return coord( X ) == other[X] &&
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
121 coord( Y ) == other[Y] &&
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
122 coord( Z ) == other[Z];
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
123 }
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
124
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
125 vertex& vertex::operator/= ( const double d )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
126 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
127 for( const Axis ax : g_Axes )
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
128 m_coords[ax] /= d;
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
129
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
130 return *this;
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
131 }
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
132
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
133 vertex vertex::operator/ ( const double d ) const
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
134 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
135 vertex other( *this );
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
136 return other /= d;
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
137 }
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
138
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
139 vertex& vertex::operator+= ( const vertex& other )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
140 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
141 move( other );
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
142 return *this;
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
143 }
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
144
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
145 vertex vertex::operator+ ( const vertex& other ) const
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
146 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
147 vertex newvert( *this );
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
148 newvert.move( other );
268
778eed342ee4 Make LDMatrixObject's transform and pos members properties
Santeri Piippo <crimsondusk64@gmail.com>
parents: 261
diff changeset
149 return newvert;
778eed342ee4 Make LDMatrixObject's transform and pos members properties
Santeri Piippo <crimsondusk64@gmail.com>
parents: 261
diff changeset
150 }
778eed342ee4 Make LDMatrixObject's transform and pos members properties
Santeri Piippo <crimsondusk64@gmail.com>
parents: 261
diff changeset
151
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
152 int vertex::operator< ( const vertex& other ) const
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
153 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
154 if( operator==( other ))
261
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
155 return false;
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
156
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
157 if( coord( X ) < other[X] )
261
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
158 return true;
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
159
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
160 if( coord( X ) > other[X] )
261
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
161 return false;
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
162
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
163 if( coord( Y ) < other[Y] )
261
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
164 return true;
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
165
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
166 if( coord( Y ) > other[Y] )
261
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
167 return false;
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
168
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
169 return coord( Z ) < other[Z];
261
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
170 }
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
171
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
172 // =============================================================================
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
173 matrix::matrix( double vals[] )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
174 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
175 for( short i = 0; i < 9; ++i )
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
176 m_vals[i] = vals[i];
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
177 }
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
178
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
179 matrix::matrix( double fillval )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
180 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
181 for( short i = 0; i < 9; ++i )
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
182 m_vals[i] = fillval;
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
183 }
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
184
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
185 matrix::matrix( initlist<double> vals )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
186 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
187 assert( vals.size() == 9 );
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
188 memcpy( &m_vals[0], &( *vals.begin() ), sizeof m_vals );
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
189 }
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
190
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
191 void matrix::puts() const
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
192 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
193 for( short i = 0; i < 3; ++i )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
194 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
195 for( short j = 0; j < 3; ++j )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
196 print( "%1\t", m_vals[( i * 3 ) + j] );
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
197
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
198 print( "\n" );
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
199 }
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
200 }
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
201
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
202 // =============================================================================
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
203 str matrix::stringRep() const
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
204 {
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
205 str val;
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
206
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
207 for( short i = 0; i < 9; ++i )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
208 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
209 if( i > 0 )
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
210 val += ' ';
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
211
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
212 val += ftoa( m_vals[i] );
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
213 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214
310
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 288
diff changeset
215 return val;
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
216 }
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
217
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
218 // =============================================================================
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
219 void matrix::zero()
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
220 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
221 memset( &m_vals[0], 0, sizeof( double ) * 9 );
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
222 }
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
223
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
224 // =============================================================================
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
225 matrix matrix::mult( matrix other ) const
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
226 {
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
227 matrix val;
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
228 val.zero();
211
8d35e631bef3 Added dialog for rotation points
Santeri Piippo <crimsondusk64@gmail.com>
parents: 191
diff changeset
229
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
230 for( short i = 0; i < 3; ++i )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
231 for( short j = 0; j < 3; ++j )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
232 for( short k = 0; k < 3; ++k )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
233 val[( i * 3 ) + j] += m_vals[( i * 3 ) + k] * other[( k * 3 ) + j];
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
234
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
235 return val;
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
236 }
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
237
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
238 // =============================================================================
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
239 matrix& matrix::operator= ( matrix other )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
240 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
241 memcpy( &m_vals[0], &other.m_vals[0], sizeof( double ) * 9 );
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
242 return *this;
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
243 }
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
244
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
245 // =============================================================================
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
246 double matrix::determinant() const
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
247 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
248 return ( val( 0 ) * val( 4 ) * val( 8 )) +
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
249 ( val( 1 ) * val( 5 ) * val( 6 )) +
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
250 ( val( 2 ) * val( 3 ) * val( 7 )) -
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
251 ( val( 2 ) * val( 4 ) * val( 6 )) -
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
252 ( val( 1 ) * val( 3 ) * val( 8 )) -
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
253 ( val( 0 ) * val( 5 ) * val( 7 ));
191
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
254 }
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
255
9bb6a17305ad Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 183
diff changeset
256 // =============================================================================
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
257 StringFormatArg::StringFormatArg( const str& v )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
258 {
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
259 m_val = v;
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
260 }
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
261
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
262 StringFormatArg::StringFormatArg( const char& v )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
263 {
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
264 m_val = v;
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
265 }
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
266
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
267 StringFormatArg::StringFormatArg( const uchar& v )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
268 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
269 m_val = v;
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
270 }
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
271
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
272 StringFormatArg::StringFormatArg( const qchar& v )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
273 {
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
274 m_val = v;
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
275 }
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
276
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
277 StringFormatArg::StringFormatArg( const float& v )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
278 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
279 m_val = ftoa( v );
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
280 }
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
281
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
282 StringFormatArg::StringFormatArg( const double& v )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
283 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
284 m_val = ftoa( v );
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
285 }
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
286
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
287 StringFormatArg::StringFormatArg( const vertex& v )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
288 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
289 m_val = v.stringRep( false );
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
290 }
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
291
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
292 StringFormatArg::StringFormatArg( const matrix& v )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
293 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
294 m_val = v.stringRep();
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
295 }
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
296
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
297 StringFormatArg::StringFormatArg( const char* v )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
298 {
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
299 m_val = v;
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
300 }
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
301
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
302 StringFormatArg::StringFormatArg( const strconfig& v )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
303 {
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
304 m_val = v.value;
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
305 }
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
306
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
307 StringFormatArg::StringFormatArg( const intconfig& v )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
308 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
309 m_val.number( v.value );
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
310 }
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
311
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
312 StringFormatArg::StringFormatArg( const floatconfig& v )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
313 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
314 m_val.number( v.value );
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
315 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
316
322
5e701c3c3d8e Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
317 StringFormatArg::StringFormatArg( const void* v )
5e701c3c3d8e Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
318 {
5e701c3c3d8e Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
319 m_val.sprintf( "%p", v );
5e701c3c3d8e Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
320 }
5e701c3c3d8e Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
321
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
322 // =============================================================================
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
323 File::File()
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
324 {
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
325 // Make a null file
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
326 m_file = null;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
327 m_textstream = null;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
328 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
329
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
330 File::File( str path, OpenType rtype )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
331 {
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
332 m_file = null;
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
333 open( path, rtype );
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
334 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
335
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
336 File::File( FILE* fp, OpenType rtype )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
337 {
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
338 m_file = null;
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
339 open( fp, rtype );
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
340 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
341
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
342 File::~File()
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
343 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
344 if( m_file )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
345 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
346 m_file->close();
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
347 delete m_file;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
348
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
349 if( m_textstream )
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
350 delete m_textstream;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
351 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
352 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
353
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
354 bool File::open( FILE* fp, OpenType rtype )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
355 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
356 return open( "", rtype, fp );
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
357 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
358
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
359 bool File::open( str path, OpenType rtype, FILE* fp )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
360 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
361 close();
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
362
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
363 if( !m_file )
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
364 m_file = new QFile;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
365
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
366 m_file->setFileName( path );
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
367
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
368 bool result;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
369
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
370 QIODevice::OpenMode mode =
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
371 ( rtype == Read ) ? QIODevice::ReadOnly :
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
372 ( rtype == Write ) ? QIODevice::WriteOnly : QIODevice::Append;
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
373
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
374 if( fp )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
375 result = m_file->open( fp, mode );
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
376 else
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
377 result = m_file->open( mode );
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
378
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
379 if( result )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
380 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
381 m_textstream = new QTextStream( m_file );
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
382 return true;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
383 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
384
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
385 delete m_file;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
386 m_file = null;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
387 return false;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
388 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
389
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
390 File::iterator File::begin()
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
391 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
392 return iterator( this );
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
393 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
394
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
395 File::iterator& File::end()
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
396 {
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
397 return m_endIterator;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
398 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
399
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
400 void File::write( str msg )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
401 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
402 m_file->write( msg.toUtf8(), msg.length() );
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
403 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
404
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
405 bool File::readLine( str& line )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
406 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
407 if( !m_textstream || m_textstream->atEnd() )
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
408 return false;
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
409
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
410 line = m_textstream->readLine();
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
411 return true;
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
412 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
413
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
414 bool File::atEnd() const
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
415 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
416 if( !m_textstream )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
417 fatal( "cannot use atEnd on a null file" );
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
418
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
419 return m_textstream->atEnd();
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
420 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
421
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
422 bool File::isNull() const
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
423 {
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
424 return m_file == null;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
425 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
426
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
427 bool File::operator!() const
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
428 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
429 return isNull();
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
430 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
431
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
432 void File::close()
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
433 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
434 if( !m_file )
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
435 return;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
436
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
437 delete m_file;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
438 m_file = null;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
439
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
440 if( m_textstream )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
441 {
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
442 delete m_textstream;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
443 m_textstream = null;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
444 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
445 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
446
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
447 bool File::flush()
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
448 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
449 return m_file->flush();
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
450 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
451
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
452 File::operator bool () const
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
453 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
454 return !isNull();
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
455 }
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
456
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
457 void File::rewind()
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
458 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
459 m_file->seek( 0 );
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
460 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
461
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
462 File::iterator::iterator( File* f ) : m_file( f )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
463 {
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
464 operator++ ();
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
465 }
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
466
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
467 void File::iterator::operator++ ()
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
468 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
469 m_gotdata = m_file->readLine( m_text );
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
470 }
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
471
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
472 str File::iterator::operator* ()
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
473 {
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
474 return m_text;
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
475 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
476
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
477 // The prime contestant for the weirdest operator== 2013 award?
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
478 bool File::iterator::operator== ( File::iterator& other )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
479 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
480 return ( other.m_file == null && !m_gotdata );
287
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
481 }
3fcccd8c3357 Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
482
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
483 bool File::iterator::operator!= ( File::iterator& other )
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
484 {
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
485 return !operator== ( other );
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
486 }

mercurial