comparison dmutil.h @ 70:03aa729a9e90

Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 16 Dec 2019 07:51:05 +0200
parents 9909014498f0
children 9ee0edff3940
comparison
equal deleted inserted replaced
69:267b3fd2c98c 70:03aa729a9e90
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 #include <cstdio> 14 #include <cstdio>
15 #include <iostream> 15 #include <iostream>
16 #include <cstdarg> 16 #include <cstdarg>
17 #include <fstream>
17 18
18 19
19 #define DMUTIL_WHITESPACE "\t\n\v\f\r " 20 #define DMUTIL_WHITESPACE "\t\n\v\f\r "
20 21
21 22
23 /* Functions
24 */
22 void dmMsg_V(const char *fmt, va_list ap); 25 void dmMsg_V(const char *fmt, va_list ap);
23 void dmMsg(const char *fmt, ...); 26 void dmMsg(const char *fmt, ...);
24 void dmError_V(const char *fmt, va_list ap); 27 void dmError_V(const char *fmt, va_list ap);
25 void dmError(const char *fmt, ...); 28 void dmError(const char *fmt, ...);
26 29
36 39
37 bool dmReadText(const std::string &filename, std::string &buf, const int maxSize); 40 bool dmReadText(const std::string &filename, std::string &buf, const int maxSize);
38 bool dmFileExists(const std::string &filename, std::ios_base::openmode mode = std::ios_base::in); 41 bool dmFileExists(const std::string &filename, std::ios_base::openmode mode = std::ios_base::in);
39 42
40 43
44 /* Structures and classes
45 */
46 struct DMTextFileInfo
47 {
48 int nline, state;
49 std::string filename;
50 std::string line;
51 std::ifstream file;
52 std::string *key;
53
54 virtual bool syntaxError(const std::string &msg)
55 {
56 dmError("Syntax error on line #%d: %s\n",
57 nline, msg.c_str());
58 return false;
59 }
60
61 virtual bool textError(const std::string &msg)
62 {
63 dmError("%s on line #%d: %s\n",
64 msg.c_str(), nline, line.c_str());
65 return false;
66 }
67
68 virtual bool readLine(void)
69 {
70 if (!std::getline(file, line))
71 return false;
72
73 nline++;
74 line = dmStrTrim(line);
75 return true;
76 }
77 };
78
79
41 #endif 80 #endif