forked from ShadowNinja/minetest-mapper-cpp
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read backend from world.mt, closes #6
- Loading branch information
Showing
7 changed files
with
80 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,7 @@ set(mapper_SRCS | |
TileGenerator.cpp | ||
ZlibDecompressor.cpp | ||
mapper.cpp | ||
util.cpp | ||
db-sqlite3.cpp | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "util.h" | ||
|
||
inline std::string trim(const std::string &s) | ||
{ | ||
size_t front = 0; | ||
while(s[front] == ' ' || | ||
s[front] == '\t' || | ||
s[front] == '\r' || | ||
s[front] == '\n' | ||
) | ||
++front; | ||
|
||
size_t back = s.size(); | ||
while(back > front && | ||
(s[back-1] == ' ' || | ||
s[back-1] == '\t' || | ||
s[back-1] == '\r' || | ||
s[back-1] == '\n' | ||
) | ||
) | ||
--back; | ||
|
||
return s.substr(front, back - front); | ||
} | ||
|
||
#define EOFCHECK() \ | ||
if(is.eof()) \ | ||
throw std::runtime_error("setting not found"); | ||
|
||
std::string get_setting(std::string name, std::istream &is) | ||
{ | ||
char c; | ||
char s[256]; | ||
std::string nm, value; | ||
|
||
next: | ||
while((c = is.get()) == ' ' || c == '\t' || c == '\r' || c == '\n') | ||
; | ||
EOFCHECK(); | ||
if(c == '#') // Ignore comments | ||
is.ignore(0xffff, '\n'); | ||
EOFCHECK(); | ||
s[0] = c; // The current char belongs to the name too | ||
is.get(&s[1], 255, '='); | ||
is.ignore(1); // Jump over the = | ||
EOFCHECK(); | ||
nm = trim(std::string(s)); | ||
is.get(s, 256, '\n'); | ||
value = trim(std::string(s)); | ||
if(name == nm) | ||
return value; | ||
else | ||
goto next; | ||
} | ||
|
||
#undef EOFCHECK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef _UTIL_H | ||
#define _UTIL_H | ||
|
||
#include <string> | ||
#include <stdexcept> | ||
#include <fstream> | ||
|
||
std::string get_setting(std::string name, std::istream &is); | ||
|
||
#endif // _UTIL_H |
2069118
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't let you override the backend, which was very useful when I was improving the SQLite3 and LevelDB backends as I was switching between them and comparing them a lot.
2069118
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, 2cc1ffc