Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
GEO::FileSystem::MemoryNode Class Reference

Implementation of a file system stored in memory. More...

#include <geogram/basic/file_system.h>

Inheritance diagram for GEO::FileSystem::MemoryNode:
GEO::FileSystem::Node GEO::Counted

Public Member Functions

 MemoryNode (const std::string &path="/")
 MemoryNode constructor. More...
 
bool copy_file (const std::string &from, const std::string &to) override
 Copies a file. More...
 
std::string load_file_as_string (const std::string &path) override
 Load file contents in a string. More...
 
virtual bool is_file (const std::string &path) override
 Checks if a path is a regular file. More...
 
virtual bool is_directory (const std::string &path) override
 Checks if a path is a directory. More...
 
virtual bool create_directory (const std::string &path) override
 Creates a directory. More...
 
virtual bool delete_directory (const std::string &path) override
 Deletes a directory. More...
 
virtual bool delete_file (const std::string &path) override
 Deletes a file. More...
 
bool get_directory_entries (const std::string &path, std::vector< std::string > &result) override
 Lists directory contents. More...
 
bool rename_file (const std::string &old_name, const std::string &new_name) override
 Renames or moves a file. More...
 
const char * get_file_contents (const std::string &path)
 Gets the contents of a file. More...
 
bool create_file (const std::string &path, const char *content)
 Creates a file. More...
 
- Public Member Functions inherited from GEO::FileSystem::Node
 Node ()
 Node constructor.
 
 ~Node () override
 Node destructor.
 
virtual std::string get_current_working_directory ()
 Gets the current working directory. More...
 
virtual bool set_current_working_directory (const std::string &path)
 Sets the working directory. More...
 
virtual Numeric::uint64 get_time_stamp (const std::string &path)
 Gets a file last modification time. More...
 
virtual bool set_executable_flag (const std::string &filename)
 Marks a filename as executable. More...
 
virtual bool touch (const std::string &filename)
 Modifies the last modification time of a file. More...
 
virtual std::string normalized_path (const std::string &path)
 Normalizes a path. More...
 
virtual std::string home_directory ()
 Gets the current user's home directory. More...
 
virtual std::string documents_directory ()
 Gets the current user's home directory. More...
 
virtual std::string extension (const std::string &path)
 Gets a path extension. More...
 
virtual std::string base_name (const std::string &path, bool remove_extension=true)
 Gets a path base name. More...
 
virtual std::string dir_name (const std::string &path)
 Gets a path directory. More...
 
virtual void get_directory_entries (const std::string &path, std::vector< std::string > &result, bool recursive)
 Lists directory contents. More...
 
virtual void get_files (const std::string &path, std::vector< std::string > &result, bool recursive=false)
 Lists files in a directory. More...
 
virtual void get_subdirectories (const std::string &path, std::vector< std::string > &result, bool recursive=false)
 Lists sub-directories in a directory. More...
 
virtual void flip_slashes (std::string &path)
 Converts a path to Unix format. More...
 
- Public Member Functions inherited from GEO::Counted
void ref () const
 Increments the reference count. More...
 
void unref () const
 Decrements the reference count. More...
 
bool is_shared () const
 Check if the object is shared. More...
 
int nb_refs () const
 Gets the number of references that point to this object. More...
 

Static Protected Member Functions

static void split_path (const std::string &path, std::string &leadingsubdir, std::string &rest)
 Splits a path. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from GEO::Counted
static void ref (const Counted *counted)
 Increments the reference count. More...
 
static void unref (const Counted *counted)
 Decrements the reference count. More...
 
- Protected Member Functions inherited from GEO::Counted
 Counted ()
 Creates a reference counted object. More...
 
virtual ~Counted ()
 Destroys a reference counted object. More...
 

Detailed Description

Implementation of a file system stored in memory.

Definition at line 374 of file file_system.h.

Constructor & Destructor Documentation

◆ MemoryNode()

GEO::FileSystem::MemoryNode::MemoryNode ( const std::string &  path = "/")
inline

MemoryNode constructor.

Parameters
[in]pathfull path to this node.

Definition at line 381 of file file_system.h.

Member Function Documentation

◆ copy_file()

bool GEO::FileSystem::MemoryNode::copy_file ( const std::string &  from,
const std::string &  to 
)
overridevirtual

Copies a file.

Parameters
[in]fromname of the file to be copied
[out]toname of the copy
Return values
trueif the copy was successful
falseotherwise

Reimplemented from GEO::FileSystem::Node.

◆ create_directory()

virtual bool GEO::FileSystem::MemoryNode::create_directory ( const std::string &  path)
overridevirtual

Creates a directory.

This recursively creates a new directory given by its absolute path path, creating any missing intermediate directories on the fly.

Parameters
[in]pathabsolute path to the directory to be created.
Return values
trueif the directory was successfully created.
falseotherwise.

Reimplemented from GEO::FileSystem::Node.

◆ create_file()

bool GEO::FileSystem::MemoryNode::create_file ( const std::string &  path,
const char *  content 
)

Creates a file.

Parameters
[in]paththe path to the file
[in]contenta const pointer to the contents of the file

◆ delete_directory()

virtual bool GEO::FileSystem::MemoryNode::delete_directory ( const std::string &  path)
overridevirtual

Deletes a directory.

This deletes the directory specified by path path. The path must specify an empty directory.

Parameters
[in]paththe path of the directory to be removed.
Return values
trueif the directory was successfully deleted.
falseotherwise.

Reimplemented from GEO::FileSystem::Node.

◆ delete_file()

virtual bool GEO::FileSystem::MemoryNode::delete_file ( const std::string &  path)
overridevirtual

Deletes a file.

Parameters
[in]paththe path of the file to be deleted.
Return values
trueif the file path was successfully deleted
falseotherwise

Reimplemented from GEO::FileSystem::Node.

◆ get_directory_entries()

bool GEO::FileSystem::MemoryNode::get_directory_entries ( const std::string &  path,
std::vector< std::string > &  result 
)
overridevirtual

Lists directory contents.

Lists all the files and sub-directories in the directory specified by path, and stores the list in result. Special entries "." and ".." are not stored in result.

Parameters
[in]paththe path to the directory to list.
[in]resultoutput vector of files and sub-directories.
Return values
trueif path specifies a readable directory.
falseotherwise.

Reimplemented from GEO::FileSystem::Node.

◆ get_file_contents()

const char* GEO::FileSystem::MemoryNode::get_file_contents ( const std::string &  path)

Gets the contents of a file.

Parameters
[in]paththe path to the file.
Returns
a const pointer to the contents of the file.

◆ is_directory()

virtual bool GEO::FileSystem::MemoryNode::is_directory ( const std::string &  path)
overridevirtual

Checks if a path is a directory.

Parameters
[in]pathsystem path to verify.
Return values
trueif path is a directory.
falseotherwise.

Reimplemented from GEO::FileSystem::Node.

◆ is_file()

virtual bool GEO::FileSystem::MemoryNode::is_file ( const std::string &  path)
overridevirtual

Checks if a path is a regular file.

Parameters
[in]pathsystem path to verify.
Return values
trueif path is a regular file.
falseotherwise.

Reimplemented from GEO::FileSystem::Node.

◆ load_file_as_string()

std::string GEO::FileSystem::MemoryNode::load_file_as_string ( const std::string &  path)
overridevirtual

Load file contents in a string.

Parameters
[in]paththe path to the file
Returns
a string with the contents of the file.

Reimplemented from GEO::FileSystem::Node.

◆ rename_file()

bool GEO::FileSystem::MemoryNode::rename_file ( const std::string &  old_name,
const std::string &  new_name 
)
overridevirtual

Renames or moves a file.

This renames the existing file or directory specified by path old_name to the new path new_name. The new name must not be the name of an existing file or directory. If old_name and new_name are not in the same directory, old_name is moved to the new_name.

Parameters
[in]old_namepath of the file or directory to be renamed.
[in]new_namenew path of the file or directory.
Return values
trueif the file was renamed successfully.
falseotherwise.

Reimplemented from GEO::FileSystem::Node.

◆ split_path()

static void GEO::FileSystem::MemoryNode::split_path ( const std::string &  path,
std::string &  leadingsubdir,
std::string &  rest 
)
staticprotected

Splits a path.

Parameters
[in]paththe path
[out]leadingsubdirthe leading subdirectory or the empty string
[out]restthe rest of the path

The documentation for this class was generated from the following file: