src/types.h

changeset 606
3dd6f343ec06
parent 604
01bdac75994a
child 609
a8dc74a809c6
equal deleted inserted replaced
605:2983f7c7e7c9 606:3dd6f343ec06
27 27
28 class LDObject; 28 class LDObject;
29 class QFile; 29 class QFile;
30 class QTextStream; 30 class QTextStream;
31 31
32 using str = QString;
33 using int8 = qint8; 32 using int8 = qint8;
34 using int16 = qint16; 33 using int16 = qint16;
35 using int32 = qint32; 34 using int32 = qint32;
36 using int64 = qint64; 35 using int64 = qint64;
37 using uint8 = quint8; 36 using uint8 = quint8;
68 Matrix (double vals[]); 67 Matrix (double vals[]);
69 68
70 double getDeterminant() const; 69 double getDeterminant() const;
71 Matrix mult (Matrix other) const; 70 Matrix mult (Matrix other) const;
72 void puts() const; 71 void puts() const;
73 str stringRep() const; 72 QString stringRep() const;
74 void zero(); 73 void zero();
75 Matrix& operator= (Matrix other); 74 Matrix& operator= (Matrix other);
76 75
77 inline double& val (int idx) 76 inline double& val (int idx)
78 { 77 {
120 Vertex (double x, double y, double z); 119 Vertex (double x, double y, double z);
121 120
122 double distanceTo (const Vertex& other) const; 121 double distanceTo (const Vertex& other) const;
123 Vertex midpoint (const Vertex& other); 122 Vertex midpoint (const Vertex& other);
124 void move (const Vertex& other); 123 void move (const Vertex& other);
125 str stringRep (bool mangled) const; 124 QString stringRep (bool mangled) const;
126 void transform (Matrix matr, Vertex pos); 125 void transform (Matrix matr, Vertex pos);
127 126
128 Vertex& operator+= (const Vertex& other); 127 Vertex& operator+= (const Vertex& other);
129 Vertex operator+ (const Vertex& other) const; 128 Vertex operator+ (const Vertex& other) const;
130 Vertex operator/ (const double d) const; 129 Vertex operator/ (const double d) const;
191 // Used as the argument type to the formatting functions, hence its name. 190 // Used as the argument type to the formatting functions, hence its name.
192 // ============================================================================= 191 // =============================================================================
193 class StringFormatArg 192 class StringFormatArg
194 { 193 {
195 public: 194 public:
196 StringFormatArg (const str& v); 195 StringFormatArg (const QString& v);
197 StringFormatArg (const char& v); 196 StringFormatArg (const char& v);
198 StringFormatArg (const uchar& v); 197 StringFormatArg (const uchar& v);
199 StringFormatArg (const QChar& v); 198 StringFormatArg (const QChar& v);
200 199
201 #define NUMERIC_FORMAT_ARG(T,C) \ 200 #define NUMERIC_FORMAT_ARG(T,C) \
238 m_val += " "; 237 m_val += " ";
239 238
240 m_val += "}"; 239 m_val += "}";
241 } 240 }
242 241
243 str value() const 242 QString value() const
244 { 243 {
245 return m_val; 244 return m_val;
246 } 245 }
247 private: 246 private:
248 str m_val; 247 QString m_val;
249 }; 248 };
250 249
251 // ============================================================================= 250 // =============================================================================
252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
253 // ============================================================================= 252 // =============================================================================
263 { 262 {
264 public: 263 public:
265 iterator() : m_file (null) {} // end iterator has m_file == null 264 iterator() : m_file (null) {} // end iterator has m_file == null
266 iterator (File* f); 265 iterator (File* f);
267 void operator++(); 266 void operator++();
268 str operator*(); 267 QString operator*();
269 bool operator== (iterator& other); 268 bool operator== (iterator& other);
270 bool operator!= (iterator& other); 269 bool operator!= (iterator& other);
271 270
272 private: 271 private:
273 File* m_file; 272 File* m_file;
274 str m_text; 273 QString m_text;
275 bool m_gotdata = false; 274 bool m_gotdata = false;
276 }; 275 };
277 276
278 public: 277 public:
279 enum OpenType 278 enum OpenType
282 Write, 281 Write,
283 Append 282 Append
284 }; 283 };
285 284
286 File(); 285 File();
287 File (str path, File::OpenType rtype); 286 File (QString path, File::OpenType rtype);
288 File (FILE* fp, File::OpenType rtype); 287 File (FILE* fp, File::OpenType rtype);
289 ~File(); 288 ~File();
290 289
291 bool atEnd() const; 290 bool atEnd() const;
292 iterator begin(); 291 iterator begin();
293 void close(); 292 void close();
294 iterator& end(); 293 iterator& end();
295 bool flush(); 294 bool flush();
296 bool isNull() const; 295 bool isNull() const;
297 bool readLine (str& line); 296 bool readLine (QString& line);
298 void rewind(); 297 void rewind();
299 bool open (FILE* fp, OpenType rtype); 298 bool open (FILE* fp, OpenType rtype);
300 bool open (str path, OpenType rtype, FILE* fp = null); 299 bool open (QString path, OpenType rtype, FILE* fp = null);
301 void write (str msg); 300 void write (QString msg);
302 301
303 bool operator!() const; 302 bool operator!() const;
304 operator bool() const; 303 operator bool() const;
305 304
306 inline str getPath() const { return m_path; } 305 inline QString getPath() const { return m_path; }
307 306
308 private: 307 private:
309 QFile* m_file; 308 QFile* m_file;
310 QTextStream* m_textstream; 309 QTextStream* m_textstream;
311 iterator m_endIterator; 310 iterator m_endIterator;
312 str m_path; 311 QString m_path;
313 }; 312 };
314 313
315 // ============================================================================= 314 // =============================================================================
316 // LDBoundingBox 315 // LDBoundingBox
317 // 316 //
336 LDBoundingBox& operator<< (LDObject* obj); 335 LDBoundingBox& operator<< (LDObject* obj);
337 LDBoundingBox& operator<< (const Vertex& v); 336 LDBoundingBox& operator<< (const Vertex& v);
338 }; 337 };
339 338
340 // Formatter function 339 // Formatter function
341 str DoFormat (QList<StringFormatArg> args); 340 QString DoFormat (QList<StringFormatArg> args);
342 341
343 // printf replacement 342 // printf replacement
344 void doPrint (File& f, initlist<StringFormatArg> args); 343 void doPrint (File& f, initlist<StringFormatArg> args);
345 void doPrint (FILE* f, initlist<StringFormatArg> args); // heh 344 void doPrint (FILE* f, initlist<StringFormatArg> args); // heh
346 345
352 # ifndef IN_IDE_PARSER 351 # ifndef IN_IDE_PARSER
353 #define fmt(...) DoFormat ({__VA_ARGS__}) 352 #define fmt(...) DoFormat ({__VA_ARGS__})
354 # define fprint(F, ...) doPrint (F, {__VA_ARGS__}) 353 # define fprint(F, ...) doPrint (F, {__VA_ARGS__})
355 # define log(...) DoLog({ __VA_ARGS__ }) 354 # define log(...) DoLog({ __VA_ARGS__ })
356 #else 355 #else
357 str fmt (const char* fmtstr, ...); 356 QString fmt (const char* fmtstr, ...);
358 void fprint (File& f, const char* fmtstr, ...); 357 void fprint (File& f, const char* fmtstr, ...);
359 void log (const char* fmtstr, ...); 358 void log (const char* fmtstr, ...);
360 #endif 359 #endif
361 360
362 extern File g_file_stdout; 361 extern File g_file_stdout;

mercurial