Orcus
Public Member Functions | List of all members
orcus::file_content Class Reference

#include <stream.hpp>

Public Member Functions

 file_content (const file_content &)=delete
 
file_contentoperator= (const file_content &)=delete
 
 file_content (file_content &&other)
 
 file_content (std::string_view filepath)
 
const char * data () const
 
size_t size () const
 
bool empty () const
 
void swap (file_content &other)
 
void load (std::string_view filepath)
 
void convert_to_utf8 ()
 
std::string_view str () const
 

Detailed Description

Represents the content of a file.

The file content is memory-mapped initially, but may later become in-memory if the non-utf-8 content gets converted to utf-8.

Member Function Documentation

◆ convert_to_utf8()

void orcus::file_content::convert_to_utf8 ( )

Convert a non-utf-8 stream to a utf-8 one if the source stream contains a byte order mark. If not, it does nothing. When the conversion happens, the converted content will be stored in-memory.

◆ data()

const char* orcus::file_content::data ( ) const

Obtain the memory address to the first character in the content buffer.

Returns
pointer to the first character in the buffer.

◆ empty()

bool orcus::file_content::empty ( ) const

Query whether or not the content is empty.

Returns
true if the content is empty, otherwise false.

◆ load()

void orcus::file_content::load ( std::string_view  filepath)

Load from a new file. This will invalidate the pointer returned from the data() method prior to the call.

Parameters
filepathpath of the file to load from.

◆ size()

size_t orcus::file_content::size ( ) const

Return the size of the content i.e. the number of characters in the content buffer.

Returns
size of the content.

◆ swap()

void orcus::file_content::swap ( file_content other)

Swap content with another instance.

Parameters
otheranother instance to swap content with.