utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
system_io.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include <filesystem>
26#include <iostream>
27#include <map>
28#include <memory>
29#include <sstream>
30#include <string>
31#include <utility>
32#include <vector>
33
34#include "utility/system_io/file.hpp"
35
41namespace utility
42{
49 {
50 public:
54 virtual ~SystemIO() = default;
55
66 virtual bool loadDirectory(const std::string &directory) = 0;
67
74 bool loadDirectory(const std::filesystem::path &directory)
75 {
76 return loadDirectory(directory.string());
77 }
78
89 virtual std::shared_ptr<utility::File> add(const std::string &path) = 0;
90
96 std::shared_ptr<utility::File> add(const std::filesystem::path &path)
97 {
98 return add(path.string());
99 }
100
114 virtual void remove(const std::string &path, bool save = true) = 0;
115
121 void remove(const std::filesystem::path &path, bool save = true)
122 {
123 remove(path.string(), save);
124 }
125
138 virtual bool save(const std::string &path,
139 const std::string &newPath = "") = 0;
140
147 bool save(const std::filesystem::path &path,
148 const std::filesystem::path &newPath)
149 {
150 return save(path.string(), newPath.string());
151 }
152
158 bool save(const std::filesystem::path &path)
159 {
160 return save(path.string());
161 }
162
170 bool exists(const std::string &path) const;
171
177 bool exists(const std::filesystem::path &path) const
178 {
179 return exists(path.string());
180 }
181
190 std::shared_ptr<utility::File> open(const std::string &path) const;
191
197 std::shared_ptr<utility::File>
198 open(const std::filesystem::path &path) const
199 {
200 return open(path.string());
201 }
202
203 protected:
210 std::map<std::string, std::shared_ptr<utility::File>> _assets;
211 };
212} // namespace utility
The SystemIO class is an abstract base class for managing file assets.
Definition system_io.hpp:49
virtual bool loadDirectory(const std::string &directory)=0
Loads assets from a directory.
bool save(const std::filesystem::path &path, const std::filesystem::path &newPath)
Saves an asset to the disk.
std::shared_ptr< utility::File > open(const std::filesystem::path &path) const
Opens an asset from the manager.
std::map< std::string, std::shared_ptr< utility::File > > _assets
Map of loaded assets.
bool exists(const std::string &path) const
Checks if an asset exists in the manager.
Definition system_io.cpp:33
virtual void remove(const std::string &path, bool save=true)=0
Removes an asset from the manager.
virtual bool save(const std::string &path, const std::string &newPath="")=0
Saves an asset to the disk.
bool save(const std::filesystem::path &path)
Saves an asset to its original path.
bool exists(const std::filesystem::path &path) const
Checks if an asset exists in the manager.
void remove(const std::filesystem::path &path, bool save=true)
Removes an asset from the manager.
std::shared_ptr< utility::File > open(const std::string &path) const
Opens an asset from the manager.
Definition system_io.cpp:39
std::shared_ptr< utility::File > add(const std::filesystem::path &path)
Adds an asset to the manager.
Definition system_io.hpp:96
virtual std::shared_ptr< utility::File > add(const std::string &path)=0
Adds an asset to the manager.
bool loadDirectory(const std::filesystem::path &directory)
Loads assets from a directory.
Definition system_io.hpp:74
virtual ~SystemIO()=default
Default destructor for SystemIO.
The utility namespace contains classes and functions for the utility project.
Definition cache.hpp:34