Drake
Drake C++ Documentation
MemoryFile Class Referencefinal

Detailed Description

A virtual file, stored in memory.

#include <drake/common/memory_file.h>

Public Member Functions

 MemoryFile ()
 Default constructor with no contents, checksum, or filename hint. More...
 
 MemoryFile (std::string contents, std::string extension, std::string filename_hint)
 Constructs a new file from the given contents. More...
 
 ~MemoryFile ()
 
const std::string & contents () const
 Returns the file's contents. More...
 
const std::string & extension () const
 Returns the extension (as passed to the constructor). More...
 
const Sha256sha256 () const
 Returns the checksum of this instance's contents(). More...
 
const std::string & filename_hint () const
 Returns the notional "filename" for this file`. More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 MemoryFile (const MemoryFile &)=default
 
MemoryFileoperator= (const MemoryFile &)=default
 
 MemoryFile (MemoryFile &&)=default
 
MemoryFileoperator= (MemoryFile &&)=default
 

Static Public Member Functions

static MemoryFile Make (const std::filesystem::path &path)
 Creates an instance of MemoryFile from the file located at the given path. More...
 

Constructor & Destructor Documentation

◆ MemoryFile() [1/4]

MemoryFile ( const MemoryFile )
default

◆ MemoryFile() [2/4]

MemoryFile ( MemoryFile &&  )
default

◆ MemoryFile() [3/4]

Default constructor with no contents, checksum, or filename hint.

In this case, the checksum will be the checksum of the empty contents.

◆ MemoryFile() [4/4]

MemoryFile ( std::string  contents,
std::string  extension,
std::string  filename_hint 
)

Constructs a new file from the given contents.

Parameters
contentsThe contents of a file.
extensionThe extension typically associated with the file contents. The case is unimportant, but it must either be empty or of the form .foo.
filename_hintA label for the file. The label is used for warning and error messages. Otherwise, the label has no other functional purpose. It need not be a valid file name, but must consist of a single line (no newlines).
Warning
An empty extension may be problematic. Many consumers of MemoryFile key on the extension to determine if the file is suitable for a purpose. Always provide an accurate, representative extension when possible.
Exceptions
std::exceptionif filename_hint contains newlines.
std::exceptionif extension is not empty and the first character isn't '.'.

◆ ~MemoryFile()

~MemoryFile ( )

Member Function Documentation

◆ contents()

const std::string& contents ( ) const

Returns the file's contents.

◆ extension()

const std::string& extension ( ) const

Returns the extension (as passed to the constructor).

When not empty, it will always be reported with a leading period and all lower case characters.

◆ filename_hint()

const std::string& filename_hint ( ) const

Returns the notional "filename" for this file`.

◆ Make()

static MemoryFile Make ( const std::filesystem::path &  path)
static

Creates an instance of MemoryFile from the file located at the given path.

The filename_hint() will be the stringified path. Making a MemoryFile computes the hash of its contents. If all you want is the contents, use drake::ReadFile() or drake::ReadFileOrThrow() instead.

Exceptions
std::exceptionif the file at path cannot be read.

◆ operator=() [1/2]

MemoryFile& operator= ( MemoryFile &&  )
default

◆ operator=() [2/2]

MemoryFile& operator= ( const MemoryFile )
default

◆ sha256()

const Sha256& sha256 ( ) const

Returns the checksum of this instance's contents().


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