Transition from QtCore to stdc++ / STL / boost
This looks like a pretty major change, but in reality, 80% of it is just renames of types and corresponding methods. The config parsing code has been completely replaced with a boost::program_options based version. This means that the config file format slightly changed (checkout the updated README). I still expect there to be bugs / unforseen events. Those should be fixed in follow up commits. Also, finally reverted back to using pkg-config to locate and link libruby. Yay for less hacks!
This commit is contained in:
parent
01529c5741
commit
2adf8ab265
40 changed files with 722 additions and 456 deletions
src
37
src/util.h
37
src/util.h
|
@ -22,6 +22,9 @@
|
|||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
static inline int
|
||||
wrapRange(int value, int min, int max)
|
||||
{
|
||||
|
@ -56,6 +59,40 @@ findNextPow2(int start)
|
|||
return i;
|
||||
}
|
||||
|
||||
/* Reads the contents of the file at 'path' and
|
||||
* appends them to 'out'. Returns false on failure */
|
||||
inline bool readFile(const char *path,
|
||||
std::string &out)
|
||||
{
|
||||
FILE *f = fopen(path, "r");
|
||||
|
||||
if (!f)
|
||||
return false;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
long size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
size_t back = out.size();
|
||||
|
||||
out.resize(back+size);
|
||||
size_t read = fread(&out[back], 1, size, f);
|
||||
fclose(f);
|
||||
|
||||
if (read != (size_t) size)
|
||||
out.resize(back+read);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void strReplace(std::string &str,
|
||||
char before, char after)
|
||||
{
|
||||
for (size_t i = 0; i < str.size(); ++i)
|
||||
if (str[i] == before)
|
||||
str[i] = after;
|
||||
}
|
||||
|
||||
#define ARRAY_SIZE(obj) (sizeof(obj) / sizeof((obj)[0]))
|
||||
|
||||
#define elementsN(obj) const int obj##N = ARRAY_SIZE(obj)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue