vitrio 0.1.4
High-throughput image I/O for Cryo-Electron Microscopy (CryoEM)
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
vitrio::image_file_probe Class Reference

Inmutable brief representation of a file. More...

#include <vitrio/image_file_probe.hpp>

Public Member Functions

 image_file_probe (std::string path)
 Construct a probe by reading the leading bytes of a file.
 
 image_file_probe (const image_file_probe &other)
 
 image_file_probe (image_file_probe &&other) noexcept
 
image_file_probe & operator= (const image_file_probe &other)
 
image_file_probe & operator= (image_file_probe &&other) noexcept
 
const std::string & get_path () const noexcept
 Get the path of the probed file.
 
const std::string & get_extension () const noexcept
 Get the extension of the probed file.
 
span< const byte > get_leading_bytes () const noexcept
 Get the leading bytes of the probed file.
 
bool exists () const noexcept
 Check whether the probed file exists and could be read.
 

Static Public Attributes

static constexpr std::size_t max_leading_bytes = 4096
 Most bytes a probe reads off the front of a file.
 

Detailed Description

Inmutable brief representation of a file.

It reads the leading bytes once, when it is constructed, and never changes afterwards, so one probe can be shown to any number of formats and shared between threads.

A file that does not exist yields a probe with no leading bytes rather than an error, so a probe can name a file yet to be created, and what fits it then rests on the extension alone.

Constructor & Destructor Documentation

◆ image_file_probe()

vitrio::image_file_probe::image_file_probe ( std::string  path)
explicit

Construct a probe by reading the leading bytes of a file.

Reads at most max_leading_bytes bytes, fewer when the file is shorter and none when it does not exist or can not be read.

Parameters
pathPath to the file to probe.

Member Function Documentation

◆ exists()

bool vitrio::image_file_probe::exists ( ) const
noexcept

Check whether the probed file exists and could be read.

Returns
true The file exists and its leading bytes were read.
false The file does not exist or could not be read, in which case get_leading_bytes is empty.

◆ get_extension()

const std::string & vitrio::image_file_probe::get_extension ( ) const
noexcept

Get the extension of the probed file.

Folded to lower case and including the leading dot. Empty when the file name has no extension.

Returns
const std::string& The extension.

◆ get_leading_bytes()

span< const byte > vitrio::image_file_probe::get_leading_bytes ( ) const
noexcept

Get the leading bytes of the probed file.

At most max_leading_bytes bytes, and fewer when the file is shorter. They are the front of the file and nothing more: what counts as its header is up to each format.

Returns
span<const byte> The bytes. Empty when the file does not exist, is empty, or could not be read.

◆ get_path()

const std::string & vitrio::image_file_probe::get_path ( ) const
noexcept

Get the path of the probed file.

Returns
const std::string& The path, as it was given.

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