Ninja
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
VirtualFileSystem Struct Reference

An implementation of DiskInterface that uses an in-memory representation of disk state. More...

#include <test.h>

Inheritance diagram for VirtualFileSystem:
Inheritance graph
[legend]

Classes

struct  Entry
 An entry for a single in-memory file. More...
 

Public Types

typedef std::map< std::string, EntryFileMap
 
enum  Status { Okay, NotFound, OtherError }
 Result of ReadFile. More...
 

Public Member Functions

void Create (const std::string &path, const std::string &contents)
 "Create" a file with contents. More...
 
virtual bool MakeDir (const std::string &path)
 Create a directory, returning false on failure. More...
 
bool MakeDirs (const std::string &path)
 Create all the parent directories for path; like mkdir -p basename path. More...
 
virtual Status ReadFile (const std::string &path, std::string *contents, std::string *err)
 Read and store in given string. More...
 
virtual int RemoveFile (const std::string &path)
 Remove the file named path. More...
 
virtual TimeStamp Stat (const std::string &path, std::string *err) const
 stat() a file, returning the mtime, or 0 if missing and -1 on other errors. More...
 
int Tick ()
 Tick "time" forwards; subsequent file operations will be newer than previous ones. More...
 
 VirtualFileSystem ()
 
virtual bool WriteFile (const std::string &path, const std::string &contents)
 Create a file, with the specified name and contents Returns true on success, false on failure. More...
 

Public Attributes

std::vector< std::string > directories_made_
 
FileMap files_
 
std::set< std::string > files_created_
 
std::vector< std::string > files_read_
 
std::set< std::string > files_removed_
 
int now_
 A simple fake timestamp for file operations. More...
 

Detailed Description

An implementation of DiskInterface that uses an in-memory representation of disk state.

It also logs file accesses and directory creations so it can be used by tests to verify disk access patterns.

Definition at line 134 of file test.h.

Member Typedef Documentation

◆ FileMap

typedef std::map<std::string, Entry> VirtualFileSystem::FileMap

Definition at line 163 of file test.h.

Member Enumeration Documentation

◆ Status

enum FileReader::Status
inherited

Result of ReadFile.

Enumerator
Okay 
NotFound 
OtherError 

Definition at line 29 of file disk_interface.h.

Constructor & Destructor Documentation

◆ VirtualFileSystem()

VirtualFileSystem::VirtualFileSystem ( )
inline

Definition at line 135 of file test.h.

Member Function Documentation

◆ Create()

void VirtualFileSystem::Create ( const std::string &  path,
const std::string &  contents 
)

"Create" a file with contents.

Definition at line 145 of file test.cc.

◆ MakeDir()

bool VirtualFileSystem::MakeDir ( const std::string &  path)
virtual

Create a directory, returning false on failure.

Implements DiskInterface.

Definition at line 166 of file test.cc.

◆ MakeDirs()

bool DiskInterface::MakeDirs ( const std::string &  path)
inherited

Create all the parent directories for path; like mkdir -p basename path.

Definition at line 138 of file disk_interface.cc.

References Error().

Referenced by Builder::StartEdge().

◆ ReadFile()

FileReader::Status VirtualFileSystem::ReadFile ( const std::string &  path,
std::string *  contents,
std::string *  err 
)
virtual

Read and store in given string.

On success, return Okay. On error, return another Status and fill |err|.

Implements FileReader.

Definition at line 171 of file test.cc.

◆ RemoveFile()

int VirtualFileSystem::RemoveFile ( const std::string &  path)
virtual

Remove the file named path.

It behaves like 'rm -f path' so no errors are reported if it does not exists.

Returns
0 if the file has been removed, 1 if the file does not exist, and -1 if an error occurs.

Implements DiskInterface.

Definition at line 184 of file test.cc.

◆ Stat()

TimeStamp VirtualFileSystem::Stat ( const std::string &  path,
std::string *  err 
) const
virtual

stat() a file, returning the mtime, or 0 if missing and -1 on other errors.

Implements DiskInterface.

Definition at line 152 of file test.cc.

◆ Tick()

int VirtualFileSystem::Tick ( )
inline

Tick "time" forwards; subsequent file operations will be newer than previous ones.

Definition at line 142 of file test.h.

References now_.

◆ WriteFile()

bool VirtualFileSystem::WriteFile ( const std::string &  path,
const std::string &  contents 
)
virtual

Create a file, with the specified name and contents Returns true on success, false on failure.

Implements DiskInterface.

Definition at line 161 of file test.cc.

Member Data Documentation

◆ directories_made_

std::vector<std::string> VirtualFileSystem::directories_made_

Definition at line 161 of file test.h.

◆ files_

FileMap VirtualFileSystem::files_

Definition at line 164 of file test.h.

◆ files_created_

std::set<std::string> VirtualFileSystem::files_created_

Definition at line 166 of file test.h.

◆ files_read_

std::vector<std::string> VirtualFileSystem::files_read_

Definition at line 162 of file test.h.

◆ files_removed_

std::set<std::string> VirtualFileSystem::files_removed_

Definition at line 165 of file test.h.

◆ now_

int VirtualFileSystem::now_

A simple fake timestamp for file operations.

Definition at line 169 of file test.h.

Referenced by Tick().


The documentation for this struct was generated from the following files: