Version: SMASH-3.1
smash::FileDeleter Struct Reference

#include <file.h>

FileDeleter is the deleter class for std::unique_ptr of std::FILE.

std::unique_ptr takes a second template argument which determines what happens when the resource it holds needs to be freed. The default implementation calls delete. For std::FILE the resource needs to be freed with a call to std::fclose instead. Therefore FilePtr requires a custom deleter class to correctly free the resource.

Definition at line 34 of file file.h.

Public Member Functions

constexpr FileDeleter ()=default
 The class has no members, so this is a noop. More...
 
void operator() (std::FILE *f) const
 Frees the std::FILE resource if it is non-zero. More...
 

Constructor & Destructor Documentation

◆ FileDeleter()

constexpr smash::FileDeleter::FileDeleter ( )
constexprdefault

The class has no members, so this is a noop.

Member Function Documentation

◆ operator()()

void smash::FileDeleter::operator() ( std::FILE *  f) const
inline

Frees the std::FILE resource if it is non-zero.

Parameters
[in]fFile resource.
Exceptions
runtime_errorif the file could not get closed.

Definition at line 43 of file file.h.

43  {
44  if (f == nullptr) {
45  return;
46  }
47  if (0 != std::fclose(f)) {
48  throw std::runtime_error(std::strerror(errno));
49  }
50  }

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