Mercurial > hg > forks > gldragon
annotate dmutil.h @ 80:98e077d9d361
List the keyboard controls in --help.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 07 Mar 2020 14:37:59 +0200 |
parents | 9ee0edff3940 |
children |
rev | line source |
---|---|
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 // |
22
03b86b9c2f29
Add copyright blurbs and licenses.
Matti Hamalainen <ccr@tnsp.org>
parents:
21
diff
changeset
|
2 // GLDragon - OpenGL PLY model viewer / simple benchmark |
03b86b9c2f29
Add copyright blurbs and licenses.
Matti Hamalainen <ccr@tnsp.org>
parents:
21
diff
changeset
|
3 // -- Miscellaneous utility functions |
03b86b9c2f29
Add copyright blurbs and licenses.
Matti Hamalainen <ccr@tnsp.org>
parents:
21
diff
changeset
|
4 // Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org> |
76 | 5 // (C) Copyright 2019-2020 Tecnic Software productions (TNSP) |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 // |
22
03b86b9c2f29
Add copyright blurbs and licenses.
Matti Hamalainen <ccr@tnsp.org>
parents:
21
diff
changeset
|
7 // See file "COPYING" for license information. |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 // |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 #ifndef DMUTIL_H |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 #define DMUTIL_H 1 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 #include <string> |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 #include <vector> |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 #include <cstdio> |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 #include <iostream> |
47
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
16 #include <cstdarg> |
70
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
17 #include <fstream> |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 |
47
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
20 #define DMUTIL_WHITESPACE "\t\n\v\f\r " |
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
21 |
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
22 |
70
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
23 /* Functions |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
24 */ |
47
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
25 void dmMsg_V(const char *fmt, va_list ap); |
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
26 void dmMsg(const char *fmt, ...); |
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
27 void dmError_V(const char *fmt, va_list ap); |
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
28 void dmError(const char *fmt, ...); |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
31 std::string dmStrLTrim(const std::string& str, const std::string& delim = DMUTIL_WHITESPACE); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
32 std::string dmStrRTrim(const std::string& str, const std::string& delim = DMUTIL_WHITESPACE); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
33 std::string dmStrTrim(const std::string& str, const std::string& delim = DMUTIL_WHITESPACE); |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
35 std::vector<std::string> dmStrSplit(const std::string& str, const std::string& delim = DMUTIL_WHITESPACE); |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 std::string dmStrJoin(const std::vector<std::string> &list, const std::string &delim); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
38 std::string dmGetPath(const std::string &path); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
39 |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 bool dmReadText(const std::string &filename, std::string &buf, const int maxSize); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 bool dmFileExists(const std::string &filename, std::ios_base::openmode mode = std::ios_base::in); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 |
70
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
44 /* Structures and classes |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
45 */ |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
46 struct DMTextFileInfo |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
47 { |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
48 int nline, state; |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
49 std::string filename; |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
50 std::string line; |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
51 std::ifstream file; |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
52 std::string *key; |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
53 |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
54 virtual bool syntaxError(const std::string &msg) |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
55 { |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
56 dmError("Syntax error on line #%d: %s\n", |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
57 nline, msg.c_str()); |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
58 return false; |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
59 } |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
60 |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
61 virtual bool textError(const std::string &msg) |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
62 { |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
63 dmError("%s on line #%d: %s\n", |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
64 msg.c_str(), nline, line.c_str()); |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
65 return false; |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
66 } |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
67 |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
68 virtual bool readLine(void) |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
69 { |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
70 if (!std::getline(file, line)) |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
71 return false; |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
72 |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
73 nline++; |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
74 line = dmStrTrim(line); |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
75 return true; |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
76 } |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
77 }; |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
78 |
03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
79 |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 #endif |