src/types.h

changeset 609
a8dc74a809c6
parent 606
3dd6f343ec06
child 610
f8244301110d
equal deleted inserted replaced
608:487db37f0bb3 609:a8dc74a809c6
246 private: 246 private:
247 QString m_val; 247 QString m_val;
248 }; 248 };
249 249
250 // ============================================================================= 250 // =============================================================================
251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
252 // =============================================================================
253 // File
254 //
255 // A file interface with simple interface and support for range-for-loops.
256 // =============================================================================
257 class File
258 {
259 private:
260 // Iterator class to enable range-for-loop support. Rough hack.. don't use directly!
261 class iterator
262 {
263 public:
264 iterator() : m_file (null) {} // end iterator has m_file == null
265 iterator (File* f);
266 void operator++();
267 QString operator*();
268 bool operator== (iterator& other);
269 bool operator!= (iterator& other);
270
271 private:
272 File* m_file;
273 QString m_text;
274 bool m_gotdata = false;
275 };
276
277 public:
278 enum OpenType
279 {
280 Read,
281 Write,
282 Append
283 };
284
285 File();
286 File (QString path, File::OpenType rtype);
287 File (FILE* fp, File::OpenType rtype);
288 ~File();
289
290 bool atEnd() const;
291 iterator begin();
292 void close();
293 iterator& end();
294 bool flush();
295 bool isNull() const;
296 bool readLine (QString& line);
297 void rewind();
298 bool open (FILE* fp, OpenType rtype);
299 bool open (QString path, OpenType rtype, FILE* fp = null);
300 void write (QString msg);
301
302 bool operator!() const;
303 operator bool() const;
304
305 inline QString getPath() const { return m_path; }
306
307 private:
308 QFile* m_file;
309 QTextStream* m_textstream;
310 iterator m_endIterator;
311 QString m_path;
312 };
313
314 // =============================================================================
315 // LDBoundingBox 251 // LDBoundingBox
316 // 252 //
317 // The bounding box is the box that encompasses a given set of objects. 253 // The bounding box is the box that encompasses a given set of objects.
318 // v0 is the minimum vertex, v1 is the maximum vertex. 254 // v0 is the minimum vertex, v1 is the maximum vertex.
319 // ============================================================================= 255 // =============================================================================
338 274
339 // Formatter function 275 // Formatter function
340 QString DoFormat (QList<StringFormatArg> args); 276 QString DoFormat (QList<StringFormatArg> args);
341 277
342 // printf replacement 278 // printf replacement
343 void doPrint (File& f, initlist<StringFormatArg> args); 279 void doPrint (QFile& f, QList<StringFormatArg> args);
344 void doPrint (FILE* f, initlist<StringFormatArg> args); // heh 280 void doPrint (FILE* fp, QList<StringFormatArg> args);
345 281
346 // log() - universal access to the message log. Defined here so that I don't have 282 // log() - universal access to the message log. Defined here so that I don't have
347 // to include messagelog.h here and recompile everything every time that file changes. 283 // to include messagelog.h here and recompile everything every time that file changes.
348 void DoLog (std::initializer_list<StringFormatArg> args); 284 void DoLog (std::initializer_list<StringFormatArg> args);
349 285
352 #define fmt(...) DoFormat ({__VA_ARGS__}) 288 #define fmt(...) DoFormat ({__VA_ARGS__})
353 # define fprint(F, ...) doPrint (F, {__VA_ARGS__}) 289 # define fprint(F, ...) doPrint (F, {__VA_ARGS__})
354 # define log(...) DoLog({ __VA_ARGS__ }) 290 # define log(...) DoLog({ __VA_ARGS__ })
355 #else 291 #else
356 QString fmt (const char* fmtstr, ...); 292 QString fmt (const char* fmtstr, ...);
357 void fprint (File& f, const char* fmtstr, ...); 293 void fprint (QFile& f, const char* fmtstr, ...);
294 void fprint (FILE* fp, const char* fmtstr, ...);
358 void log (const char* fmtstr, ...); 295 void log (const char* fmtstr, ...);
359 #endif 296 #endif
360 297
361 extern File g_file_stdout;
362 extern File g_file_stderr;
363 extern const Vertex g_origin; // Vertex at (0, 0, 0) 298 extern const Vertex g_origin; // Vertex at (0, 0, 0)
364 extern const Matrix g_identity; // Identity matrix 299 extern const Matrix g_identity; // Identity matrix
365 300
366 static const double pi = 3.14159265358979323846; 301 static const double pi = 3.14159265358979323846;
367 302

mercurial