Support for debug_string method for testing

This commit is contained in:
2021-07-21 00:50:06 -04:00
parent 4ba0471bde
commit c2a69b5b23
6 changed files with 197 additions and 150 deletions

View File

@@ -5,6 +5,7 @@
#include "util.hpp"
#include <sys/types.h>
#include <sys/stat.h>
#include <cmath>
#ifndef WIN32
#include <unistd.h>
#define stat _stat
@@ -12,6 +13,21 @@
namespace util {
stringvec split(const std::string &s, char sep) {
stringvec result;
int start = 0;
for (int i = 0; i < int(s.size()); i++) {
if (s[i] == sep) {
result.push_back(s.substr(start, i-start));
start = i+1;
}
}
if (start < int(s.size())) {
result.push_back(s.substr(start));
}
return result;
}
std::string tolower(std::string input) {
for (int i = 0; i < int(input.size()); i++) {
input[i] = std::tolower(input[i]);
@@ -42,6 +58,16 @@ int64_t strtoint(const std::string &value, int64_t errval) {
}
}
double strtodouble(const std::string &value) {
char *endptr;
double result = strtod(value.c_str(), &endptr);
if (endptr == value.c_str() + value.size()) {
return result;
} else {
return std::nan("");
}
}
std::string ltrim(std::string s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(),
std::not1(std::ptr_fun<int, int>(std::isspace))));
@@ -97,31 +123,10 @@ double distance_squared(double x1, double y1, double x2, double y2) {
return dx*dx + dy*dy;
}
// These hash functions are part of Bob Jenkins' Lookup3.
#define hash_rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
#define hash_mix(a,b,c) { \
a -= c; a ^= hash_rot(c, 4); c += b; \
b -= a; b ^= hash_rot(a, 6); a += c; \
c -= b; c ^= hash_rot(b, 8); b += a; \
a -= c; a ^= hash_rot(c,16); c += b; \
b -= a; b ^= hash_rot(a,19); a += c; \
c -= b; c ^= hash_rot(b, 4); b += a; \
}
#define hash_final(a,b,c) { \
c ^= b; c -= hash_rot(b,14); \
a ^= c; a -= hash_rot(c,11); \
b ^= a; b -= hash_rot(a,25); \
c ^= b; c -= hash_rot(b,16); \
a ^= c; a -= hash_rot(c,4); \
b ^= a; b -= hash_rot(a,14); \
c ^= b; c -= hash_rot(b,24); \
}
std::ostream & operator << (std::ostream &out, const XYZ &xyz) {
out << "(" << xyz.x << "," << xyz.y << "," << xyz.z << ")";
return out;
std::string XYZ::debug_string() const {
std::ostringstream oss;
oss << "(" << x << "," << y << "," << z << ")";
return oss.str();
}
} // namespace util