2017-03-09 22:44:32 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
2017-03-11 22:43:21 +08:00
|
|
|
// Platform-dependent functionality.
|
2017-03-09 22:44:32 +08:00
|
|
|
//
|
|
|
|
// Copyright 2017 whitequark
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifndef SOLVESPACE_PLATFORM_H
|
|
|
|
#define SOLVESPACE_PLATFORM_H
|
|
|
|
|
|
|
|
namespace Platform {
|
|
|
|
|
2017-03-11 22:43:21 +08:00
|
|
|
// UTF-8 ⟷ UTF-16 conversion, for Windows.
|
|
|
|
#if defined(WIN32)
|
|
|
|
std::string Narrow(const wchar_t *s);
|
|
|
|
std::wstring Widen(const char *s);
|
|
|
|
std::string Narrow(const std::wstring &s);
|
|
|
|
std::wstring Widen(const std::string &s);
|
|
|
|
#endif
|
|
|
|
|
2020-11-23 19:52:17 +08:00
|
|
|
#if defined(_WIN32)
|
|
|
|
const std::string embeddedFont = "res://fonts/BitstreamVeraSans-Roman-builtin.ttf";
|
|
|
|
#else // Linux and macOS
|
|
|
|
const std::string embeddedFont = "BitstreamVeraSans-Roman-builtin.ttf";
|
|
|
|
#endif
|
|
|
|
|
2017-03-09 22:44:32 +08:00
|
|
|
// A filesystem path, respecting the conventions of the current platform.
|
|
|
|
// Transformation functions return an empty path on error.
|
|
|
|
class Path {
|
|
|
|
public:
|
|
|
|
std::string raw;
|
|
|
|
|
|
|
|
static Path From(std::string raw);
|
|
|
|
static Path CurrentDirectory();
|
|
|
|
|
|
|
|
void Clear() { raw.clear(); }
|
|
|
|
|
|
|
|
bool Equals(const Path &other) const;
|
|
|
|
bool IsEmpty() const { return raw.empty(); }
|
|
|
|
bool IsAbsolute() const;
|
|
|
|
bool HasExtension(std::string ext) const;
|
|
|
|
|
|
|
|
std::string FileName() const;
|
|
|
|
std::string FileStem() const;
|
|
|
|
std::string Extension() const;
|
|
|
|
|
|
|
|
Path WithExtension(std::string ext) const;
|
|
|
|
Path Parent() const;
|
|
|
|
Path Join(const std::string &component) const;
|
|
|
|
Path Join(const Path &other) const;
|
|
|
|
Path Expand(bool fromCurrentDirectory = false) const;
|
|
|
|
Path RelativeTo(const Path &base) const;
|
|
|
|
|
|
|
|
// Converting to and from a platform-independent representation
|
|
|
|
// (conventionally, the Unix one).
|
|
|
|
static Path FromPortable(const std::string &repr);
|
|
|
|
std::string ToPortable() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PathLess {
|
|
|
|
bool operator()(const Path &a, const Path &b) const { return a.raw < b.raw; }
|
|
|
|
};
|
|
|
|
|
2017-03-11 22:43:21 +08:00
|
|
|
// File manipulation functions.
|
2019-05-24 23:57:43 +08:00
|
|
|
bool FileExists(const Platform::Path &filename);
|
2017-03-11 22:43:21 +08:00
|
|
|
FILE *OpenFile(const Platform::Path &filename, const char *mode);
|
|
|
|
bool ReadFile(const Platform::Path &filename, std::string *data);
|
|
|
|
bool WriteFile(const Platform::Path &filename, const std::string &data);
|
|
|
|
void RemoveFile(const Platform::Path &filename);
|
|
|
|
|
|
|
|
// Resource loading function.
|
|
|
|
const void *LoadResource(const std::string &name, size_t *size);
|
|
|
|
|
2020-05-10 15:21:16 +08:00
|
|
|
// Startup and command-line argument handling.
|
|
|
|
std::vector<std::string> InitCli(int argc, char **argv);
|
|
|
|
|
2020-05-10 16:28:01 +08:00
|
|
|
// Debug print function.
|
|
|
|
void DebugPrint(const char *fmt, ...);
|
|
|
|
|
2020-05-22 21:45:37 +08:00
|
|
|
// Temporary arena functions.
|
|
|
|
void *AllocTemporary(size_t size);
|
|
|
|
void FreeAllTemporary();
|
|
|
|
|
2017-03-09 22:44:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|