bettola/common/src/vfs.h

36 lines
760 B
C++

#pragma once
#include <string>
#include <map>
struct vfs_node;
/* Store children for quick lookup by name. */
typedef std::map<std::string, vfs_node*> vfs_child_map;
enum vfs_node_type {
FILE_NODE,
DIR_NODE,
EXEC_NODE
};
struct vfs_node {
long long id;
long long parent_id; /* Used durin DB loading only. */
std::string name;
vfs_node_type type;
/* Files. */
std::string content;
/* Directories. */
vfs_child_map children;
vfs_node* parent;
};
vfs_node* new_node(std::string name, vfs_node_type type, vfs_node* parent);
vfs_node* find_node_by_id(vfs_node* root, long long id);
std::string get_full_path(vfs_node* node);
vfs_node* find_node_by_path(vfs_node* root, const std::string& path);
void delete_vfs_tree(vfs_node* node);