ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
detray::io::file_handle Class Referencefinal

Wrapper around a file stream. More...

#include <detray/io/utils/file_handle.hpp>

Public Member Functions

 file_handle ()=delete
 All writers must define a file name.
 file_handle (const std::string &file_name, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out)
 Open the file at the supplied path.
 file_handle (const std::string &name, const std::string &extension, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out)
 File gets created with a name and extension.
 ~file_handle ()
 Destructor closes the file.
std::fstream & operator* ()

Detailed Description

Wrapper around a file stream.

Performs some checks and offers some convenience functionality:

  • In out mode w.o. file replacement: Checks if file exists and automatically finds a new filename in case it does.
  • In in mode: Checks for empty file names and whether the file exists
  • Enforces a limit on the number of files that can be written/opened
  • Checks whether a file was opened correctly
  • Closes the stream when the handle goes out of scope and checks whether anything went wrong during the IO operations
Note
Not thread safe.
Can throw exceptions during construction.

Constructor & Destructor Documentation

◆ file_handle() [1/2]

detray::io::file_handle::file_handle ( const std::string & file_name,
std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out )
explicit

Open the file at the supplied path.

Parameters
file_namecomplete file path
modestream open mode

◆ file_handle() [2/2]

detray::io::file_handle::file_handle ( const std::string & name,
const std::string & extension,
std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out )

File gets created with a name and extension.

Parameters
namefile path without its extension
extensionfile extension, including its leading dot
modestream open mode

Member Function Documentation

◆ operator*()

std::fstream & detray::io::file_handle::operator* ( )
Returns
the output stream