From 1a218532c039639c96d19dc1da609fe5a900a78e Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Fri, 10 Jan 2020 00:45:11 +0100 Subject: [PATCH] source/System/File.cpp: move path stuff to Path.cpp --- engine.build.lua | 1 + include/Spectre/System/File.h | 6 ------ include/Spectre/System/Path.h | 19 +++++++++++++++++++ source/Graphics/ImageLoader.cpp | 4 ++-- source/Graphics/Shader.cpp | 4 ++-- source/Graphics/ShaderProgram.cpp | 4 ++-- source/System/File.cpp | 18 ------------------ source/System/Path.cpp | 24 ++++++++++++++++++++++++ 8 files changed, 50 insertions(+), 30 deletions(-) create mode 100644 include/Spectre/System/Path.h create mode 100644 source/System/Path.cpp diff --git a/engine.build.lua b/engine.build.lua index b3e3f7c..d2ddd58 100644 --- a/engine.build.lua +++ b/engine.build.lua @@ -24,6 +24,7 @@ settings.cc.includes:Add("vendor/stb/include") local system_module = Module("source/System", { "File.cpp", + "Path.cpp", "MessageHandler.cpp", "MessageQueue.cpp", "SystemEvent.cpp", diff --git a/include/Spectre/System/File.h b/include/Spectre/System/File.h index d3bad58..210f12d 100644 --- a/include/Spectre/System/File.h +++ b/include/Spectre/System/File.h @@ -7,12 +7,6 @@ namespace sp { namespace file { - std::string getBasename(const std::string& path); - - std::string getExtension(const std::string& path); - - std::string getPathname(const std::string& path); - std::vector read(const std::string& path); } } diff --git a/include/Spectre/System/Path.h b/include/Spectre/System/Path.h new file mode 100644 index 0000000..a6fa1bd --- /dev/null +++ b/include/Spectre/System/Path.h @@ -0,0 +1,19 @@ + +#ifndef SYSTEM_PATH_H +#define SYSTEM_PATH_H + +#include + +namespace sp { + +class Path +{ +public : + static std::string getBasename(const std::string& path); + + static std::string getExtension(const std::string& path); +}; + +} // namespace sp + +#endif /* SYSTEM_PATH_H */ diff --git a/source/Graphics/ImageLoader.cpp b/source/Graphics/ImageLoader.cpp index b3af11f..6827c57 100644 --- a/source/Graphics/ImageLoader.cpp +++ b/source/Graphics/ImageLoader.cpp @@ -1,5 +1,5 @@ -#include +#include #include #include #include "ImageLoader.h" @@ -61,7 +61,7 @@ bool ImageLoader::loadFromMemory(const void *data, unsigned size, Image& img) // TODO: Support more formats. bool ImageLoader::saveToFile(const Image& img, const char *filename) { - std::string ext = file::getExtension(filename); + std::string ext = Path::getExtension(filename); std::vector encoded_data; if (ext == "png") { diff --git a/source/Graphics/Shader.cpp b/source/Graphics/Shader.cpp index 6fdee60..47f1016 100644 --- a/source/Graphics/Shader.cpp +++ b/source/Graphics/Shader.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include @@ -37,7 +37,7 @@ bool Shader::loadFromFile(const std::string& file) // If this shader does not have a name, pick the filename. if (m_name.length() < 1) { - m_name = file::getBasename(file); + m_name = Path::getBasename(file); } // Load file into memory. diff --git a/source/Graphics/ShaderProgram.cpp b/source/Graphics/ShaderProgram.cpp index c8baf0b..0a0da3f 100644 --- a/source/Graphics/ShaderProgram.cpp +++ b/source/Graphics/ShaderProgram.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include #include namespace sp { @@ -38,7 +38,7 @@ void ShaderProgram::addShader(const Shader& shader) bool ShaderProgram::loadFromFile(const std::string& filename) { - std::string extension = file::getExtension(filename); + std::string extension = Path::getExtension(filename); // Meta file. load real shaders. if (extension == "shader.glsl") { diff --git a/source/System/File.cpp b/source/System/File.cpp index 9d6f31d..f2d82d7 100644 --- a/source/System/File.cpp +++ b/source/System/File.cpp @@ -5,24 +5,6 @@ namespace sp { namespace file { - std::string getBasename(const std::string& path) { - - size_t p = path.find_last_of('/'); - - if (p == std::string::npos) - return path; - return path.substr(p + 1); - } - - std::string getExtension(const std::string& path) { - - std::string base_name = getBasename(path); - size_t p = base_name.find_first_of('.'); - if (p == std::string::npos) - return ""; - return base_name.substr(p + 1); - } - std::vector read(const std::string& path) { std::vector buf; diff --git a/source/System/Path.cpp b/source/System/Path.cpp new file mode 100644 index 0000000..6e53da2 --- /dev/null +++ b/source/System/Path.cpp @@ -0,0 +1,24 @@ + +#include + +namespace sp { + +std::string Path::getBasename(const std::string& path) +{ + size_t p = path.find_last_of('/'); + + if (p == std::string::npos) + return path; + return path.substr(p + 1); +} + +std::string Path::getExtension(const std::string& path) +{ + std::string base_name = getBasename(path); + size_t p = base_name.find_first_of('.'); + if (p == std::string::npos) + return ""; + return base_name.substr(p + 1); +} + +} // namespace sp