🌍 Languages: English | Русский
Библиотека VFS предоставляет абстрактный слой для работы с виртуальной файловой системой.
Она реализует единый интерфейс для создания, удаления, чтения и навигации по файлам и директориям, поддерживая две реализации: Linux-подобную и Windows-подобную.
- Создание и удаление файлов и директорий
- Чтение и запись содержимого файлов
- Проверка существования файлов и директорий
- Навигация по дереву файловой системы через итераторы
- Доступ к атрибутам файлов (время создания, обновления, доступа, скрытые, read-only и т. д.)
- Кроссплатформенные реализации:
linux_imlиwindows_iml
-
IFileSystem— основной интерфейс файловой системы
Методы:createFile,deleteFile,createDirectory,deleteDirectory,readFile,writeFile,fileExists,directoryExists,createIterator. -
IFile— интерфейс файла
Методы:getName,getSize,getContent,setContent,getAttributes. -
IDirectory— интерфейс директории
Методы: работа с файлами (addFile,removeFile,getFile,fileExists) и поддиректориями (addSubdirectory,removeSubdirectory,getSubdirectory,subdirectoryExists). -
IDirectoryIterator— итератор по дереву
Методы:goToSubdirectory,goToParentDirectory,getCurrentPath,getCurrentDirectory. -
FileAttributes— атрибуты файла
Содержат даты (created,updated,lastAccess) и флаги (hidden,readOnly).
linux_iml::File— файл Linux-реализации.linux_iml::Directory— директория Linux-реализации.linux_iml::FileTree— дерево файлов.linux_iml::Iterator— итератор по директориям.LinuxFileSystem— реализация интерфейсаIFileSystemдля Linux.
windows_iml::File— файл Windows-реализации.windows_iml::Directory— директория Windows-реализации.windows_iml::FileTree— дерево файлов.windows_iml::Iterator— итератор по директориям.WindowsFileSystem— реализация интерфейсаIFileSystemдля Windows.
#include "vfs/vfs.hpp"
int main() {
vfs::LinuxFileSystem fs;
fs.createDirectory("/project");
fs.createFile("/project/main.cpp", "int main() { return 0; }");
if (fs.fileExists("/project/main.cpp")) {
std::string content = fs.readFile("/project/main.cpp");
fs.writeFile("/project/main.cpp", content + "\n// updated");
}
return 0;
}#include "vfs/vfs.hpp"
int main() {
vfs::WindowsFileSystem fs('C');
fs.createDirectory("C:\\project");
fs.createFile("C:\\project\\main.cpp", "int main() { return 0; }");
if (fs.fileExists("C:\\project\\main.cpp")) {
std::string content = fs.readFile("C:\\project\\main.cpp");
fs.writeFile("C:\\project\\main.cpp", content + "\n// updated");
}
return 0;
}В проекте используется GoogleTest (и при необходимости GoogleMock) для модульного тестирования.
Тесты покрывают основные компоненты библиотеки:
File— проверка работы с именами, содержимым, атрибутами.Directory— работа с файлами и поддиректориями.FileTreeиIterator— навигация по дереву.FileSystem(Linux и Windows) — комплексные сценарии создания, чтения и удаления файлов и директорий.
Запуск тестов:
cd build
cmake ..
make
ctestЕсли тесты не нужны, их сборку можно отключить:
cmake -DBUILD_MODULE_TESTS=OFF ..Сборка выполняется через CMake:
mkdir build && cd build
cmake ..
makeБиблиотека может быть собрана как статическая (.a / .lib) или динамическая (.so / .dll). Выбор управляется переменной BUILD_SHARED_LIBS:
- Статическая (по умолчанию):
cmake -DBUILD_SHARED_LIBS=OFF ..- Динамическая:
cmake -DBUILD_SHARED_LIBS=ON ..Встраивание через add_subdirectory Вы можете подключить библиотеку напрямую в свой проект:
add_subdirectory(vfs)
target_link_libraries(my_project PRIVATE vfs)The VFS library provides an abstraction layer for working with a virtual file system.
It implements a unified interface for creating, deleting, reading, and navigating files and directories, supporting two implementations: Linux-like and Windows-like.
- Create and delete files and directories
- Read and write file contents
- Check existence of files and directories
- Navigate through file system tree via iterators
- Access file attributes (creation time, update time, access time, hidden, read-only, etc.)
- Cross-platform implementations:
linux_imlandwindows_iml
-
IFileSystem— main file system interface
Methods:createFile,deleteFile,createDirectory,deleteDirectory,readFile,writeFile,fileExists,directoryExists,createIterator. -
IFile— file interface
Methods:getName,getSize,getContent,setContent,getAttributes. -
IDirectory— directory interface
Methods: working with files (addFile,removeFile,getFile,fileExists) and subdirectories (addSubdirectory,removeSubdirectory,getSubdirectory,subdirectoryExists). -
IDirectoryIterator— tree iterator
Methods:goToSubdirectory,goToParentDirectory,getCurrentPath,getCurrentDirectory. -
FileAttributes— file attributes
Contains dates (created,updated,lastAccess) and flags (hidden,readOnly).
linux_iml::File— Linux implementation file.linux_iml::Directory— Linux implementation directory.linux_iml::FileTree— file tree.linux_iml::Iterator— directory iterator.LinuxFileSystem— implementation ofIFileSysteminterface for Linux.
windows_iml::File— Windows implementation file.windows_iml::Directory— Windows implementation directory.windows_iml::FileTree— file tree.windows_iml::Iterator— directory iterator.WindowsFileSystem— implementation ofIFileSysteminterface for Windows.
#include "vfs/vfs.hpp"
int main() {
vfs::LinuxFileSystem fs;
fs.createDirectory("/project");
fs.createFile("/project/main.cpp", "int main() { return 0; }");
if (fs.fileExists("/project/main.cpp")) {
std::string content = fs.readFile("/project/main.cpp");
fs.writeFile("/project/main.cpp", content + "\n// updated");
}
return 0;
}#include "vfs/vfs.hpp"
int main() {
vfs::WindowsFileSystem fs('C');
fs.createDirectory("C:\\project");
fs.createFile("C:\\project\\main.cpp", "int main() { return 0; }");
if (fs.fileExists("C:\\project\\main.cpp")) {
std::string content = fs.readFile("C:\\project\\main.cpp");
fs.writeFile("C:\\project\\main.cpp", content + "\n// updated");
}
return 0;
}The project uses GoogleTest (and GoogleMock if needed) for unit testing. Tests cover the main components of the library:
File— testing work with names, content, attributes.Directory— working with files and subdirectories.FileTreeиIterator— tree navigation.FileSystem(Linux and Windows) — complex scenarios of creating, reading and deleting files and directories.
Running tests:
cd build
cmake ..
make
ctestIf tests are not needed, their build can be disabled:
cmake -DBUILD_MODULE_TESTS=OFF ..Building is done via CMake:
mkdir build && cd build
cmake ..
makeThe library can be built as static (.a / .lib) or dynamic (.so / .dll). The choice is controlled by the BUILD_SHARED_LIBS variable:
- Static (default):
cmake -DBUILD_SHARED_LIBS=OFF ..- Dynamic:
cmake -DBUILD_SHARED_LIBS=ON ..Embedding via add_subdirectory You can connect the library directly to your project:
add_subdirectory(vfs)
target_link_libraries(my_project PRIVATE vfs)