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 Sha256 & | sha256 () const |
Returns the checksum of this instance's contents() . More... | |
const std::string & | filename_hint () const |
Returns the notional "filename" for this file`. More... | |
std::string | to_string (int contents_limit=100) const |
Returns a string representation. More... | |
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable | |
MemoryFile (const MemoryFile &)=default | |
MemoryFile & | operator= (const MemoryFile &)=default |
MemoryFile (MemoryFile &&)=default | |
MemoryFile & | operator= (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... | |
|
default |
|
default |
MemoryFile | ( | ) |
Default constructor with no contents, checksum, or filename hint.
In this case, the checksum
will be the checksum of the empty contents.
MemoryFile | ( | std::string | contents, |
std::string | extension, | ||
std::string | filename_hint | ||
) |
Constructs a new file from the given contents
.
contents | The contents of a file. |
extension | The extension typically associated with the file contents. The case is unimportant, but it must either be empty or of the form .foo . |
filename_hint | A 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). |
std::exception | if filename_hint contains newlines. |
std::exception | if extension is not empty and the first character isn't '.'. |
~MemoryFile | ( | ) |
const std::string& contents | ( | ) | const |
Returns the file's contents.
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.
const std::string& filename_hint | ( | ) | const |
Returns the notional "filename" for this file`.
|
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.
std::exception | if the file at path cannot be read. |
|
default |
|
default |
const Sha256& sha256 | ( | ) | const |
Returns the checksum of this
instance's contents()
.
std::string to_string | ( | int | contents_limit = 100 | ) | const |
Returns a string representation.
Note: the file contents will be limited to contents_limit
number of characters. To include the full contents, pass any number less than or equal to zero.