Open arapelle opened 1 year ago
#include "main.hpp"
#include <strn/string64.hpp>
#include <strn/io.hpp>
#include <regex>
#include <filesystem>
#include <iostream>
#include <bit>
rsce::resource_manager rscm;
Image_sptr image_sptr = rscm.get_shared<Image>(">IMG:/dir/subdir/icon.png");
// Image_sptr image_sptr = rscm.get_shared<Image>("#IMG:/dir/subdir/icon.png");
Image_sptr image_sptr = rscm.get_shared<Image>("*IMG:/dir/subdir/icon.png");
Image_sptr image_sptr = rscm.get_shared<Image>("IMG:/dir/subdir/icon.png"); // <=> Image_sptr image_sptr = rscm.get_shared<Image>("?IMG:/dir/subdir/icon.png");
virtual root: [a-Z][a-Z_-.]{1-7}
class resource_manager
{
public:
using path_char_type = std::filesystem::path::value_type;
using path_view = std::basic_string_view<path_char_type>;
constexpr static path_char_type file_marker = path_char_type('>');
constexpr static path_char_type rscpack_marker = path_char_type('#');
constexpr static path_char_type rsclib_marker = path_char_type('*');
constexpr static path_char_type unknown_source_marker = path_char_type('?');
template <class T>
std::shared_ptr<T> load(std::filesystem::path& rsc_path)
{
const path_char_type& ch = rsc_path.native().front();
switch (ch)
{
case file_marker:
{
path_view rsc_path_view(&rsc_path.native()[1], rsc_path.native().size() - 1);
return load_resource_from_file<T>(rsc_path_view);
}
case rscpack_marker:
{
path_view rsc_path_view(&rsc_path.native()[1], rsc_path.native().size() - 1);
return load_resource_from_rscpack<T>(rsc_path_view);
}
// case rsclib_marker:
// {
// path_view rsc_path_view(&rsc_path.native()[1], rsc_path.native().size() - 1);
// return load_resource_from_rsclib<T>(rsc_path_view);
// }
case unknown_source_marker:
{
path_view rsc_path_view(&rsc_path.native()[1], rsc_path.native().size() - 1);
return load_resource_from_unkwown_source<T>(rsc_path_view);
}
default:
{
if ((ch >= path_char_type('a') && ch <= path_char_type('z'))
|| (ch >= path_char_type('A') && ch <= path_char_type('Z')))
{
break;
}
throw std::runtime_error("Wrong format.");
}
}
}
template <class T>
std::shared_ptr<T> load_resource_from_file(path_view rsc_path)
{
strn::string64 vroot;
if (virtual_system_.extract_vroot_rpath(vroot, rsc_path))
{
}
else
{
}
}
private:
vlfs::virtual_filesystem virtual_system_;
};
int main(int argc, char** argv)
{
std::cout << "EXIT SUCCESS" << std::endl;
return EXIT_SUCCESS;
}