Files
LearnOpenGL/includes/learnopengl/filesystem.h
Marin Nilsson a8a8d11f22 Support for out-of-source builds.
Uses environment variable to tell the program where to find resource
files.
Sharder sources are still search for in the current workind directory.
2015-07-30 21:48:41 +02:00

50 lines
1.0 KiB
C++

#ifndef FILESYSTEM_H
#define FILESYSTEM_H
#include <string>
class FileSystem
{
private:
typedef std::string (*Builder) (const std::string& path);
public:
static std::string getPath(const std::string& path)
{
static std::string(*pathBuilder)(std::string const &) = getPathBuilder();
return (*pathBuilder)(path);
}
private:
static std::string const & getRoot()
{
static char const * givenRoot {getenv("LOGL_ROOT_PATH")};
static std::string root {givenRoot != nullptr ? givenRoot : ""};
return root;
}
//static std::string(*foo (std::string const &)) getPathBuilder()
static Builder getPathBuilder()
{
if (getRoot() != "")
return &FileSystem::getPathRelativeRoot;
else
return &FileSystem::getPathRelativeBinary;
}
static std::string getPathRelativeRoot(const std::string& path)
{
return getRoot() + std::string("/") + path;
}
static std::string getPathRelativeBinary(const std::string& path)
{
return "../../../" + path;
}
};
// FILESYSTEM_H
#endif