Mercurial > hg > forks > gldragon
diff 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 |
line wrap: on
line diff
--- a/dmutil.h Mon Dec 16 06:51:40 2019 +0200 +++ b/dmutil.h Mon Dec 16 07:51:05 2019 +0200 @@ -14,11 +14,14 @@ #include <cstdio> #include <iostream> #include <cstdarg> +#include <fstream> #define DMUTIL_WHITESPACE "\t\n\v\f\r " +/* Functions + */ void dmMsg_V(const char *fmt, va_list ap); void dmMsg(const char *fmt, ...); void dmError_V(const char *fmt, va_list ap); @@ -38,4 +41,40 @@ bool dmFileExists(const std::string &filename, std::ios_base::openmode mode = std::ios_base::in); +/* Structures and classes + */ +struct DMTextFileInfo +{ + int nline, state; + std::string filename; + std::string line; + std::ifstream file; + std::string *key; + + virtual bool syntaxError(const std::string &msg) + { + dmError("Syntax error on line #%d: %s\n", + nline, msg.c_str()); + return false; + } + + virtual bool textError(const std::string &msg) + { + dmError("%s on line #%d: %s\n", + msg.c_str(), nline, line.c_str()); + return false; + } + + virtual bool readLine(void) + { + if (!std::getline(file, line)) + return false; + + nline++; + line = dmStrTrim(line); + return true; + } +}; + + #endif