Files
integration/luprex/core/cpp/util.hpp

64 lines
1.7 KiB
C++
Raw Normal View History

2020-11-13 15:18:09 -05:00
#ifndef UTIL_HPP
2020-11-13 18:17:47 -05:00
#define UTIL_HPP
2020-11-13 15:18:09 -05:00
#include <string>
2020-11-27 13:21:07 -05:00
#include <set>
2020-11-13 15:18:09 -05:00
#include <algorithm>
2020-12-05 18:57:53 -05:00
#include <sstream>
2021-02-02 16:29:07 -05:00
#include <ostream>
2021-01-12 14:14:38 -05:00
#include <tuple>
2021-01-16 01:24:33 -05:00
#include <utility>
2020-11-13 15:18:09 -05:00
namespace util {
2021-07-18 17:48:39 -04:00
enum WorldType {
WORLD_TYPE_STANDALONE,
WORLD_TYPE_C_SYNC,
WORLD_TYPE_S_SYNC,
WORLD_TYPE_MASTER,
};
2020-11-13 15:18:09 -05:00
using stringvec = std::vector<std::string>;
2020-11-27 13:21:07 -05:00
using stringset = std::set<std::string>;
2021-07-18 17:48:39 -04:00
using HashValue = std::pair<uint64_t, uint64_t>;
2020-11-13 15:18:09 -05:00
2021-02-07 15:35:31 -05:00
// String to lowercase/uppercase
std::string tolower(std::string input);
std::string toupper(std::string input);
2021-02-10 16:22:24 -05:00
// Return true if the string can be parsed as an integer.
bool validinteger(const std::string &value);
2021-02-02 16:29:07 -05:00
// String to integer. Returns errval if the number is not parseable.
int64_t strtoint(const std::string &value, int64_t errval);
// Trim strings: left end, right end, both ends.
std::string ltrim(std::string s);
std::string rtrim(std::string s);
std::string trim(std::string s);
// Read a file as one big string.
std::string get_file_contents(const std::string &path);
// Read a file as a vector of lines.
stringvec get_file_lines(const std::string &path);
// Get a file's fingerprint - ie, size and modification time.
2020-12-05 18:57:53 -05:00
std::string get_file_fingerprint(const std::string &path);
2020-11-13 15:18:09 -05:00
2021-02-02 16:29:07 -05:00
// Calculate distance between two points
double distance_squared(double x1, double y1, double x2, double y2);
2021-02-02 16:29:07 -05:00
// An XYZ coordinate, general purpose.
2021-01-12 16:21:29 -05:00
struct XYZ {
float x, y, z;
XYZ() { x=0; y=0; z=0; }
XYZ(float ix, float iy, float iz) { x=ix; y=iy; z=iz; }
bool operator ==(const XYZ &o) const { return x==o.x && y == o.y && z==o.z; }
bool operator !=(const XYZ &o) const { return x!=o.x || y != o.y || z!=o.z; }
2021-01-12 16:21:29 -05:00
};
2021-02-02 16:29:07 -05:00
std::ostream & operator << (std::ostream &out, const XYZ &xyz);
2021-07-18 17:48:39 -04:00
2020-11-13 15:18:09 -05:00
} // namespace util
#endif // UTIL_HPP