solvespace/src/platform/platform.h
whitequark c89a2e4f62 Use a thread-safe temporary arena on every platform.
This commit continues the work started in commits 521473ee and
e84fd464 that parallelizes certain geometric operations. This commit
cleans up the temporary arena implementations and makes them
thread-safe.

Also, in commit 521473ee, a call to FreeAllTemporary() was added
during initialization to create the heap on Windows. This is now
not necessary as the heap is created transparently on the first call
to AllocTemporary().
2020-05-22 18:06:22 +00:00

80 lines
2.3 KiB
C++

//-----------------------------------------------------------------------------
// Platform-dependent functionality.
//
// Copyright 2017 whitequark
//-----------------------------------------------------------------------------
#ifndef SOLVESPACE_PLATFORM_H
#define SOLVESPACE_PLATFORM_H
namespace Platform {
// 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
// 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; }
};
// File manipulation functions.
bool FileExists(const Platform::Path &filename);
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);
// Startup and command-line argument handling.
std::vector<std::string> InitCli(int argc, char **argv);
// Debug print function.
void DebugPrint(const char *fmt, ...);
// Temporary arena functions.
void *AllocTemporary(size_t size);
void FreeAllTemporary();
}
#endif