source/System/File.cpp: move path stuff to Path.cpp
This commit is contained in:
parent
66f3bb30d9
commit
1a218532c0
8 changed files with 50 additions and 30 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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<unsigned char> read(const std::string& path);
|
||||
} }
|
||||
|
||||
|
|
|
|||
19
include/Spectre/System/Path.h
Normal file
19
include/Spectre/System/Path.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
#ifndef SYSTEM_PATH_H
|
||||
#define SYSTEM_PATH_H
|
||||
|
||||
#include <string>
|
||||
|
||||
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 */
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
#include <Spectre/System/File.h>
|
||||
#include <Spectre/System/Path.h>
|
||||
#include <Spectre/System/Log.h>
|
||||
#include <Spectre/Graphics/Image.h>
|
||||
#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<unsigned char> encoded_data;
|
||||
|
||||
if (ext == "png") {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
#include <fstream>
|
||||
#include <Spectre/System/File.h>
|
||||
#include <Spectre/System/Path.h>
|
||||
#include <Spectre/Graphics/Shader.h>
|
||||
#include <Graphics/GL/gl.h>
|
||||
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include <Spectre/Math/Color.h>
|
||||
#include <Spectre/Graphics/ShaderProgram.h>
|
||||
#include <Spectre/System/File.h>
|
||||
#include <Spectre/System/Path.h>
|
||||
#include <Graphics/GL/gl.h>
|
||||
|
||||
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") {
|
||||
|
|
|
|||
|
|
@ -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<unsigned char> read(const std::string& path) {
|
||||
|
||||
std::vector<unsigned char> buf;
|
||||
|
|
|
|||
24
source/System/Path.cpp
Normal file
24
source/System/Path.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
#include <Spectre/System/Path.h>
|
||||
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue