2010-04-21 14:48:36 +00:00
|
|
|
#ifndef UTILS_H
|
|
|
|
#define UTILS_H
|
|
|
|
|
2019-03-07 11:12:09 -05:00
|
|
|
#include <irrlicht/irrlicht.h>
|
2010-04-21 14:48:36 +00:00
|
|
|
|
2019-05-16 12:33:53 -04:00
|
|
|
#include <ctime>
|
|
|
|
#include <string>
|
2020-03-10 14:12:16 -04:00
|
|
|
#include <vector>
|
2019-05-16 12:33:53 -04:00
|
|
|
|
2021-02-18 09:31:03 -05:00
|
|
|
const char path_separator_s =
|
|
|
|
#ifdef _WIN32
|
|
|
|
'\\';
|
|
|
|
#else
|
|
|
|
'/';
|
|
|
|
#endif
|
|
|
|
const wchar_t path_separator_ws =
|
|
|
|
#ifdef _WIN32
|
|
|
|
L'\\';
|
|
|
|
#else
|
|
|
|
L'/';
|
|
|
|
#endif
|
|
|
|
|
2019-04-11 04:31:04 -04:00
|
|
|
class Utility {
|
2010-04-23 07:28:59 +00:00
|
|
|
public:
|
2021-02-17 18:55:39 -05:00
|
|
|
static const std::string WHITESPACE;
|
2019-04-11 04:31:04 -04:00
|
|
|
static void dumpVectorToConsole(const irr::core::vector3df& vector);
|
2020-03-10 14:12:16 -04:00
|
|
|
static int getTextureCount(const irr::video::SMaterial& material);
|
|
|
|
static int getTextureCount(irr::scene::IAnimatedMeshSceneNode* node);
|
2019-04-11 04:31:04 -04:00
|
|
|
static void dumpMeshInfoToConsole(irr::scene::IAnimatedMeshSceneNode* node);
|
|
|
|
static std::wstring parentOfPath(const std::wstring& path);
|
|
|
|
static std::wstring basename(const std::wstring& path);
|
2019-07-03 15:15:44 -04:00
|
|
|
static std::wstring leftOf(const std::wstring& path, const std::wstring& delimiter, bool allIfNotFound);
|
|
|
|
static std::wstring leftOfLast(const std::wstring& path, const std::wstring& delimiter, bool allIfNotFound);
|
|
|
|
static std::wstring rightOf(const std::wstring& path, const std::wstring& delimiter, bool allIfNotFound);
|
|
|
|
static std::wstring rightOfLast(const std::wstring& path, const std::wstring& delimiter, bool allIfNotFound);
|
2019-07-03 17:13:37 -04:00
|
|
|
static bool startsWith(const std::wstring& haystack, const std::wstring& needle);
|
2021-02-17 18:55:39 -05:00
|
|
|
static bool endsWith(const std::wstring& haystack, const std::wstring& needle);
|
|
|
|
static bool startsWith(const std::string& haystack, const std::string& needle);
|
|
|
|
static bool endsWith(const std::string& haystack, const std::string& needle);
|
2020-03-10 14:12:16 -04:00
|
|
|
static std::wstring replaceAll(const std::wstring& subject, const std::wstring& from, const std::wstring& to);
|
|
|
|
static std::string replaceAll(const std::string& subject, const std::string& from, const std::string& to);
|
|
|
|
static std::wstring getPrefix(const std::wstring& haystack, const std::vector<std::wstring>& needles, bool CI);
|
|
|
|
static std::wstring getSuffix(const std::wstring& haystack, const std::vector<std::wstring>& needles, bool CI);
|
|
|
|
static bool startsWithAny(const std::wstring& haystack, const std::vector<std::wstring>& needles, bool CI);
|
|
|
|
static bool endsWithAny(const std::wstring& haystack, const std::vector<std::wstring>& needles, bool CI);
|
2019-04-11 04:31:04 -04:00
|
|
|
static std::wstring withoutExtension(const std::wstring& path);
|
|
|
|
static std::wstring extensionOf(const std::wstring& path);
|
|
|
|
static std::wstring delimiter(const std::wstring& path);
|
|
|
|
static bool isFile(const std::string& name);
|
|
|
|
static bool isFile(const std::wstring& name);
|
2019-06-13 08:57:32 -04:00
|
|
|
static std::string toString(int val);
|
2019-04-03 10:35:27 -04:00
|
|
|
static std::string toString(irr::f32 val);
|
2019-04-11 04:31:04 -04:00
|
|
|
static std::string toString(const std::wstring& name);
|
|
|
|
static std::string toLower(const std::string& s);
|
|
|
|
static std::wstring toLower(const std::wstring& s);
|
2019-04-03 10:35:27 -04:00
|
|
|
static std::wstring toWstring(irr::f32 val);
|
|
|
|
static std::wstring toWstring(int val);
|
2019-04-11 04:31:04 -04:00
|
|
|
static std::wstring toWstring(const std::string& str);
|
2019-05-16 12:33:53 -04:00
|
|
|
static std::string dateTimePathString(const time_t& rawtime);
|
|
|
|
static std::string dateTimeNowPathString();
|
2019-04-03 10:35:27 -04:00
|
|
|
static irr::f32 toF32(std::wstring val);
|
2019-04-19 15:29:30 -04:00
|
|
|
static irr::f32 distance(const irr::core::vector3df& start, const irr::core::vector3df& end);
|
2019-03-10 09:55:31 -04:00
|
|
|
// compiler doesn't like template function when class is not a template--instantiate immediately
|
|
|
|
// see http://processors.wiki.ti.com/index.php/C%2B%2B_Template_Instantiation_Issues
|
|
|
|
template <typename T>
|
2019-04-11 04:31:04 -04:00
|
|
|
static bool equalsApprox(T f1, T f2)
|
|
|
|
{
|
|
|
|
return abs(f2 - f1) < .00000001; // TODO: kEpsilon? (see also <https://en.wikipedia.org/wiki/Machine_epsilon#How_to_determine_machine_epsilon>)
|
2019-03-10 09:55:31 -04:00
|
|
|
}
|
2021-02-17 18:55:39 -05:00
|
|
|
|
|
|
|
static std::string ltrim(const std::string &s);
|
|
|
|
static std::string rtrim(const std::string &s);
|
|
|
|
static std::string trim(const std::string &s);
|
2010-04-23 07:28:59 +00:00
|
|
|
};
|
2010-04-21 14:48:36 +00:00
|
|
|
|
2020-03-10 14:12:16 -04:00
|
|
|
class TestUtility {
|
|
|
|
public:
|
|
|
|
TestUtility();
|
|
|
|
void assertEqual(const std::wstring& subject, const std::wstring& expectedResult);
|
|
|
|
void assertEqual(const std::string subject, const std::string expectedResult);
|
|
|
|
void testReplaceAll(const std::wstring& subject, const std::wstring& from, const std::wstring& to, const std::wstring& expectedResult);
|
|
|
|
void testReplaceAll(const std::string& subject, const std::string& from, const std::string& to, const std::string& expectedResult);
|
2021-02-18 09:31:03 -05:00
|
|
|
void testTrim(const std::string& subject, const std::string &expectedResult);
|
|
|
|
void testRTrim(const std::string& subject, const std::string &expectedResult);
|
|
|
|
void testLTrim(const std::string& subject, const std::string &expectedResult);
|
2020-03-10 14:12:16 -04:00
|
|
|
};
|
|
|
|
|
2010-04-21 14:48:36 +00:00
|
|
|
#endif // UTILS_H
|