irccd  3.0.3
Public Member Functions | List of all members
irccd::js::file Class Reference

Object for Javascript to perform I/O. More...

#include <file_api.hpp>

Public Member Functions

 file (std::string path, const std::string &mode)
 
 file (std::FILE *fp, std::function< void(std::FILE *)> destructor) noexcept
 
virtual ~file () noexcept
 
const std::string & get_path () const noexcept
 
std::FILE * get_handle () noexcept
 
void close () noexcept
 

Detailed Description

Object for Javascript to perform I/O.

This class can be constructed to Javascript.

It is used in:

Constructor & Destructor Documentation

◆ file() [1/2]

irccd::js::file::file ( std::string  path,
const std::string &  mode 
)
inline

Construct a file specified by path

Parameters
paththe path
modethe mode string (for std::fopen)
Exceptions
std::runtime_erroron failures

◆ file() [2/2]

irccd::js::file::file ( std::FILE *  fp,
std::function< void(std::FILE *)>  destructor 
)
inlinenoexcept

Construct a file from a already created FILE pointer (e.g. popen).

The class takes ownership of fp and will close it.

Precondition
destructor must not be null
Parameters
fpthe file pointer
destructorthe function to close fp (e.g. std::fclose)

◆ ~file()

virtual irccd::js::file::~file ( )
inlinevirtualnoexcept

Closes the file.

Member Function Documentation

◆ close()

void irccd::js::file::close ( )
inlinenoexcept

Force close, can be safely called multiple times.

◆ get_handle()

std::FILE* irccd::js::file::get_handle ( )
inlinenoexcept

Get the handle.

Returns
the handle or nullptr if the stream was closed

◆ get_path()

const std::string& irccd::js::file::get_path ( ) const
inlinenoexcept

Get the path.

Returns
the path
Warning
empty when constructed from the FILE constructor

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