migrate from std::filesystem::path to io::path (WIP)

This commit is contained in:
MihailRis
2025-01-30 22:23:13 +03:00
parent 1e22882284
commit e0314803c0
72 changed files with 1189 additions and 791 deletions
+4 -7
View File
@@ -6,12 +6,9 @@
#include <utility>
#include "io/engine_paths.hpp"
#include "io/io.hpp"
#include "typedefs.hpp"
#include "util/stringutil.hpp"
namespace fs = std::filesystem;
void GLSLExtension::setVersion(std::string version) {
this->version = std::move(version);
}
@@ -21,7 +18,7 @@ void GLSLExtension::setPaths(const ResPaths* paths) {
}
void GLSLExtension::loadHeader(const std::string& name) {
fs::path file = paths->find("shaders/lib/" + name + ".glsl");
io::path file = paths->find("shaders/lib/" + name + ".glsl");
std::string source = io::read_string(file);
addHeader(name, "");
addHeader(name, process(file, source, true));
@@ -66,7 +63,7 @@ void GLSLExtension::undefine(const std::string& name) {
}
inline std::runtime_error parsing_error(
const fs::path& file, uint linenum, const std::string& message
const io::path& file, uint linenum, const std::string& message
) {
return std::runtime_error(
"file " + file.string() + ": " + message + " at line " +
@@ -75,7 +72,7 @@ inline std::runtime_error parsing_error(
}
inline void parsing_warning(
const fs::path& file, uint linenum, const std::string& message
const io::path& file, uint linenum, const std::string& message
) {
std::cerr << "file " + file.string() + ": warning: " + message +
" at line " + std::to_string(linenum)
@@ -87,7 +84,7 @@ inline void source_line(std::stringstream& ss, uint linenum) {
}
std::string GLSLExtension::process(
const fs::path& file, const std::string& source, bool header
const io::path& file, const std::string& source, bool header
) {
std::stringstream ss;
size_t pos = 0;
+3 -2
View File
@@ -1,10 +1,11 @@
#pragma once
#include <filesystem>
#include <string>
#include <unordered_map>
#include <vector>
#include "io/io.hpp"
class ResPaths;
class GLSLExtension {
@@ -29,7 +30,7 @@ public:
bool hasDefine(const std::string& name) const;
std::string process(
const std::filesystem::path& file,
const io::path& file,
const std::string& source,
bool header = false
);
+9 -16
View File
@@ -1,6 +1,5 @@
#include "imageio.hpp"
#include <filesystem>
#include <functional>
#include <unordered_map>
@@ -8,8 +7,6 @@
#include "io/io.hpp"
#include "png.hpp"
namespace fs = std::filesystem;
using image_reader =
std::function<std::unique_ptr<ImageData>(const ubyte*, size_t)>;
using image_writer = std::function<void(const std::string&, const ImageData*)>;
@@ -30,33 +27,29 @@ bool imageio::is_write_supported(const std::string& extension) {
return writers.find(extension) != writers.end();
}
inline std::string extensionOf(const std::string& filename) {
return fs::u8path(filename).extension().u8string();
}
std::unique_ptr<ImageData> imageio::read(const fs::path& filename) {
auto found = readers.find(extensionOf(filename.u8string()));
std::unique_ptr<ImageData> imageio::read(const io::path& file) {
auto found = readers.find(file.extension());
if (found == readers.end()) {
throw std::runtime_error(
"file format is not supported (read): " + filename.u8string()
"file format is not supported (read): " + file.string()
);
}
auto bytes = io::read_bytes_buffer(filename);
auto bytes = io::read_bytes_buffer(file);
try {
return std::unique_ptr<ImageData>(found->second(bytes.data(), bytes.size()));
} catch (const std::runtime_error& err) {
throw std::runtime_error(
"could not to load image " + filename.u8string() + ": " + err.what()
"could not to load image " + file.string() + ": " + err.what()
);
}
}
void imageio::write(const std::string& filename, const ImageData* image) {
auto found = writers.find(extensionOf(filename));
void imageio::write(const io::path& file, const ImageData* image) {
auto found = writers.find(file.extension());
if (found == writers.end()) {
throw std::runtime_error(
"file format is not supported (write): " + filename
"file format is not supported (write): " + file.string()
);
}
return found->second(filename, image);
return found->second(io::resolve(file).u8string(), image);
}
+4 -3
View File
@@ -2,7 +2,8 @@
#include <memory>
#include <string>
#include <filesystem>
#include "io/fwd.hpp"
class ImageData;
@@ -12,6 +13,6 @@ namespace imageio {
bool is_read_supported(const std::string& extension);
bool is_write_supported(const std::string& extension);
std::unique_ptr<ImageData> read(const std::filesystem::path& file);
void write(const std::string& filename, const ImageData* image);
std::unique_ptr<ImageData> read(const io::path& file);
void write(const io::path& file, const ImageData* image);
}
+5 -4
View File
@@ -5,6 +5,7 @@
#include <string>
#include "io/io.hpp"
#include "audio/audio.hpp"
#include "debug/Logger.hpp"
#include "typedefs.hpp"
@@ -43,11 +44,11 @@ static inline std::string vorbis_error_message(int code) {
}
std::unique_ptr<audio::PCM> ogg::load_pcm(
const fs::path& file, bool headerOnly
const io::path& file, bool headerOnly
) {
OggVorbis_File vf;
int code;
if ((code = ov_fopen(file.u8string().c_str(), &vf))) {
if ((code = ov_fopen(io::resolve(file).u8string().c_str(), &vf))) {
throw std::runtime_error("vorbis: " + vorbis_error_message(code));
}
std::vector<char> data;
@@ -166,10 +167,10 @@ public:
}
};
std::unique_ptr<PCMStream> ogg::create_stream(const fs::path& file) {
std::unique_ptr<PCMStream> ogg::create_stream(const io::path& file) {
OggVorbis_File vf;
int code;
if ((code = ov_fopen(file.u8string().c_str(), &vf))) {
if ((code = ov_fopen(io::resolve(file).u8string().c_str(), &vf))) {
throw std::runtime_error("vorbis: " + vorbis_error_message(code));
}
return std::make_unique<OggStream>(vf);
+5 -3
View File
@@ -1,6 +1,8 @@
#pragma once
#include <filesystem>
#include <memory>
#include "io/fwd.hpp"
namespace audio {
struct PCM;
@@ -9,9 +11,9 @@ namespace audio {
namespace ogg {
std::unique_ptr<audio::PCM> load_pcm(
const std::filesystem::path& file, bool headerOnly
const io::path& file, bool headerOnly
);
std::unique_ptr<audio::PCMStream> create_stream(
const std::filesystem::path& file
const io::path& file
);
}
+1 -1
View File
@@ -212,7 +212,7 @@ std::unique_ptr<Texture> png::load_texture(const ubyte* bytes, size_t size) {
}
std::unique_ptr<Texture> png::load_texture(const std::string& filename) {
auto bytes = io::read_bytes_buffer(fs::u8path(filename));
auto bytes = io::read_bytes_buffer(filename);
try {
return load_texture(bytes.data(), bytes.size());
} catch (const std::runtime_error& err) {
+5 -4
View File
@@ -6,6 +6,7 @@
#include <string>
#include <vector>
#include "io/io.hpp"
#include "audio/audio.hpp"
#include "debug/Logger.hpp"
@@ -118,11 +119,11 @@ public:
}
};
std::unique_ptr<audio::PCMStream> wav::create_stream(const fs::path& file) {
std::ifstream in(file, std::ios::binary);
std::unique_ptr<audio::PCMStream> wav::create_stream(const io::path& file) {
std::ifstream in(io::resolve(file), std::ios::binary);
if (!in.is_open()) {
throw std::runtime_error(
"could not to open file '" + file.u8string() + "'"
"could not to open file '" + file.string() + "'"
);
}
@@ -234,7 +235,7 @@ std::unique_ptr<audio::PCMStream> wav::create_stream(const fs::path& file) {
}
std::unique_ptr<audio::PCM> wav::load_pcm(
const fs::path& file, bool headerOnly
const io::path& file, bool headerOnly
) {
auto stream = wav::create_stream(file);
+5 -3
View File
@@ -1,6 +1,8 @@
#pragma once
#include <filesystem>
#include <memory>
#include "io/fwd.hpp"
namespace audio {
struct PCM;
@@ -9,9 +11,9 @@ namespace audio {
namespace wav {
std::unique_ptr<audio::PCM> load_pcm(
const std::filesystem::path& file, bool headerOnly
const io::path& file, bool headerOnly
);
std::unique_ptr<audio::PCMStream> create_stream(
const std::filesystem::path& file
const io::path& file
);
}