LLVM  8.0.1
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
llvm::FileOutputBuffer Class Referenceabstract

FileOutputBuffer - This interface provides simple way to create an in-memory buffer which will be written to a file. More...

#include "llvm/Support/FileOutputBuffer.h"

Collaboration diagram for llvm::FileOutputBuffer:
Collaboration graph
[legend]

Public Types

enum  { F_executable = 1, F_modify = 2 }
 

Public Member Functions

virtual uint8_t * getBufferStart () const =0
 Returns a pointer to the start of the buffer. More...
 
virtual uint8_t * getBufferEnd () const =0
 Returns a pointer to the end of the buffer. More...
 
virtual size_t getBufferSize () const =0
 Returns size of the buffer. More...
 
StringRef getPath () const
 Returns path where file will show up if buffer is committed. More...
 
virtual Error commit ()=0
 Flushes the content of the buffer to its file and deallocates the buffer. More...
 
virtual ~FileOutputBuffer ()
 If this object was previously committed, the destructor just deletes this object. More...
 
virtual void discard ()
 This removes the temporary file (unless it already was committed) but keeps the memory mapping alive. More...
 

Static Public Member Functions

static Expected< std::unique_ptr< FileOutputBuffer > > create (StringRef FilePath, size_t Size, unsigned Flags=0)
 Factory method to create an OutputBuffer object which manages a read/write buffer of the specified size. More...
 

Protected Member Functions

 FileOutputBuffer (StringRef Path)
 

Protected Attributes

std::string FinalPath
 

Detailed Description

FileOutputBuffer - This interface provides simple way to create an in-memory buffer which will be written to a file.

During the lifetime of these objects, the content or existence of the specified file is undefined. That is, creating an OutputBuffer for a file may immediately remove the file. If the FileOutputBuffer is committed, the target file's content will become the buffer content at the time of the commit. If the FileOutputBuffer is not committed, the file will be deleted in the FileOutputBuffer destructor.

Definition at line 31 of file FileOutputBuffer.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
F_executable 

set the 'x' bit on the resulting file

F_modify 

the contents of the new file are initialized from the file that exists at the location (if present).

This allows in-place modification of an existing file.

Definition at line 33 of file FileOutputBuffer.h.

Constructor & Destructor Documentation

◆ ~FileOutputBuffer()

virtual llvm::FileOutputBuffer::~FileOutputBuffer ( )
inlinevirtual

If this object was previously committed, the destructor just deletes this object.

If this object was not committed, the destructor deallocates the buffer and the target file is never written.

Definition at line 77 of file FileOutputBuffer.h.

◆ FileOutputBuffer()

llvm::FileOutputBuffer::FileOutputBuffer ( StringRef  Path)
inlineprotected

Definition at line 84 of file FileOutputBuffer.h.

Member Function Documentation

◆ commit()

virtual Error llvm::FileOutputBuffer::commit ( )
pure virtual

Flushes the content of the buffer to its file and deallocates the buffer.

If commit() is not called before this object's destructor is called, the file is deleted in the destructor. The optional parameter is used if it turns out you want the file size to be smaller than initially requested.

Referenced by getPath().

◆ create()

Expected< std::unique_ptr< FileOutputBuffer > > FileOutputBuffer::create ( StringRef  FilePath,
size_t  Size,
unsigned  Flags = 0 
)
static

Factory method to create an OutputBuffer object which manages a read/write buffer of the specified size.

When committed, the buffer will be written to the file at the specified path.

When F_modify is specified and FilePath refers to an existing on-disk file Size may be set to -1, in which case the entire file is used. Otherwise, the file shrinks or grows as necessary based on the value of Size. It is an error to specify F_modify and Size=-1 if FilePath does not exist.

Definition at line 158 of file FileOutputBuffer.cpp.

References llvm::sys::fs::all_exe, llvm::sys::fs::all_read, llvm::sys::fs::all_write, createInMemoryBuffer(), createOnDiskBuffer(), llvm::sys::fs::directory_file, llvm::errorCodeToError(), llvm::sys::fs::file_not_found, llvm::sys::fs::basic_file_status::getSize(), llvm::invalid_argument, llvm::is_a_directory, Mode, llvm::no_such_file_or_directory, llvm::sys::fs::regular_file, llvm::sys::fs::status(), llvm::sys::fs::status_error, and llvm::sys::fs::basic_file_status::type().

Referenced by llvm::msf::MSFBuilder::commit().

◆ discard()

virtual void llvm::FileOutputBuffer::discard ( )
inlinevirtual

This removes the temporary file (unless it already was committed) but keeps the memory mapping alive.

Definition at line 81 of file FileOutputBuffer.h.

◆ getBufferEnd()

virtual uint8_t* llvm::FileOutputBuffer::getBufferEnd ( ) const
pure virtual

Returns a pointer to the end of the buffer.

◆ getBufferSize()

virtual size_t llvm::FileOutputBuffer::getBufferSize ( ) const
pure virtual

Returns size of the buffer.

◆ getBufferStart()

virtual uint8_t* llvm::FileOutputBuffer::getBufferStart ( ) const
pure virtual

Returns a pointer to the start of the buffer.

◆ getPath()

StringRef llvm::FileOutputBuffer::getPath ( ) const
inline

Returns path where file will show up if buffer is committed.

Definition at line 65 of file FileOutputBuffer.h.

References commit(), and FinalPath.

Member Data Documentation

◆ FinalPath

std::string llvm::FileOutputBuffer::FinalPath
protected

Definition at line 86 of file FileOutputBuffer.h.

Referenced by getPath().


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