matio-cpp  v0.2.5
A C++ wrapper of the matio library, with memory ownership handling, to read and write .mat files.
matioCpp::File Class Reference

#include <matioCpp/File.h>

Data Structures

class  Impl
 

Public Member Functions

 File ()
 Default Constructor. More...
 
 File (const std::string &name, matioCpp::FileMode mode=matioCpp::FileMode::ReadAndWrite)
 Constructor opening the specified file. More...
 
 File (const File &other)=delete
 Deleted copy constructor, to avoid confusion on whether the content has been copied or not. More...
 
 File (File &&other)
 Move constructor. More...
 
 ~File ()
 Destructor. More...
 
void operator= (const File &other)=delete
 Deleted copy assignment, to avoid confusion on whether the content has been copied or not. More...
 
void operator= (File &&other)
 Move assignement. More...
 
void close ()
 Close the file. More...
 
bool open (const std::string &name, matioCpp::FileMode mode=matioCpp::FileMode::ReadAndWrite)
 Open the specified file. More...
 
std::string name () const
 The file name. More...
 
std::string header () const
 The file header. More...
 
matioCpp::FileVersion version () const
 The MAT file version. More...
 
matioCpp::FileMode mode () const
 The mode with which the file has been opened. More...
 
std::vector< std::stringvariableNames () const
 Get the list of variables in the file. More...
 
matioCpp::Variable read (const std::string &name) const
 Read a variable given the name. More...
 
bool write (const Variable &variable, matioCpp::Compression compression=matioCpp::Compression::None)
 Write a Variable to a file. More...
 
template<class iterator >
bool write (iterator begin, iterator end, matioCpp::Compression compression=matioCpp::Compression::None)
 Write a Variable to a file in a batch. More...
 
bool isOpen () const
 Check if the file is open. More...
 

Static Public Member Functions

static File Create (const std::string &name, matioCpp::FileVersion version=matioCpp::FileVersion::Default, const std::string &header="")
 Create a new file (static) More...
 
static bool Delete (const std::string &name)
 Delete the specified file. More...
 
static bool Exists (const std::string &name)
 Check if file exists and can be opened. More...
 

Detailed Description

Definition at line 15 of file File.h.

Constructor & Destructor Documentation

◆ File() [1/4]

matioCpp::File::File ( )

Default Constructor.

Definition at line 93 of file File.cpp.

◆ File() [2/4]

matioCpp::File::File ( const std::string name,
matioCpp::FileMode  mode = matioCpp::FileMode::ReadAndWrite 
)

Constructor opening the specified file.

Parameters
nameThe name of the file to open.
modeThe mode with which to open the file. By default, both reading and writing are allowed.
Note
If the mode is ReadAndWrite, a file with the same name is created if not found

Definition at line 99 of file File.cpp.

References mode(), name(), and open().

◆ File() [3/4]

matioCpp::File::File ( const File other)
delete

Deleted copy constructor, to avoid confusion on whether the content has been copied or not.

◆ File() [4/4]

matioCpp::File::File ( matioCpp::File &&  other)

Move constructor.

Parameters
otherThe other File from which the internal status has been taken.

Definition at line 105 of file File.cpp.

◆ ~File()

matioCpp::File::~File ( )

Destructor.

Definition at line 110 of file File.cpp.

Member Function Documentation

◆ close()

void matioCpp::File::close ( )

Close the file.

Definition at line 120 of file File.cpp.

◆ Create()

matioCpp::File matioCpp::File::Create ( const std::string name,
matioCpp::FileVersion  version = matioCpp::FileVersion::Default,
const std::string header = "" 
)
static

Create a new file (static)

This is the static version of open, with the addition that it is possible to have additional settings.

Parameters
nameThe name of the file to be openend.
versionThe MAT file version.
headerThis is an optional string that is added inside the MAT file. You can view the text in a MAT-file header using the cat command on the file on UNIX.
Returns
a newly created File object. The method isOpen() returnf false if something went wrong.

Definition at line 132 of file File.cpp.

References std::string::c_str(), std::endl(), std::string::find_last_of(), isOpen(), matioCpp::MAT4, matioCpp::MAT5, matioCpp::MAT7_3, matioCpp::ReadAndWrite, std::string::size(), std::string::substr(), std::to_string(), and matioCpp::Undefined.

◆ Delete()

bool matioCpp::File::Delete ( const std::string name)
static

Delete the specified file.

Parameters
nameName of the file to delete.
Returns
True if successful, false otherwise (for example, in Windows the file will not be deleted if open).

Definition at line 224 of file File.cpp.

References std::string::c_str(), and std::remove().

◆ Exists()

bool matioCpp::File::Exists ( const std::string name)
static

Check if file exists and can be opened.

Parameters
nameThe name of the file to check
Returns
True if the specified file exists, false otherwise

Definition at line 229 of file File.cpp.

References isOpen(), and matioCpp::ReadOnly.

◆ header()

std::string matioCpp::File::header ( ) const

The file header.

This is an optional string that is added inside the MAT file. You can view the text in a MAT-file header using the cat command on the file on UNIX.

Warning
This is available only if the matio version is >= 1.5.15
Returns
The file header

Definition at line 245 of file File.cpp.

References std::endl().

◆ isOpen()

bool matioCpp::File::isOpen ( ) const

Check if the file is open.

Returns
True if open.

Definition at line 402 of file File.cpp.

Referenced by Create(), and Exists().

◆ mode()

matioCpp::FileMode matioCpp::File::mode ( ) const

The mode with which the file has been opened.

Returns
The file mode. If the file is not open, it returns ReadOnly.

Definition at line 283 of file File.cpp.

Referenced by File(), and matioCpp::File::Impl::reset().

◆ name()

std::string matioCpp::File::name ( ) const

The file name.

Returns
The file name

Definition at line 235 of file File.cpp.

Referenced by File().

◆ open()

bool matioCpp::File::open ( const std::string name,
matioCpp::FileMode  mode = matioCpp::FileMode::ReadAndWrite 
)

Open the specified file.

Parameters
nameThe name of the file to open.
modeThe mode with which to open the file. By default, both reading and writing are allowed.
Returns
false in case of failure (the file does not exist, the file exist but cannot be written, ..)

Definition at line 125 of file File.cpp.

References std::string::c_str(), and matioCpp::ReadOnly.

Referenced by File().

◆ operator=() [1/2]

void matioCpp::File::operator= ( const File other)
delete

Deleted copy assignment, to avoid confusion on whether the content has been copied or not.

◆ operator=() [2/2]

void matioCpp::File::operator= ( matioCpp::File &&  other)

Move assignement.

Parameters
otherThe other File from which the internal status has been taken.

Definition at line 115 of file File.cpp.

References std::move().

◆ read()

matioCpp::Variable matioCpp::File::read ( const std::string name) const

Read a variable given the name.

Parameters
nameThe name of the variable to be read
Returns
The desired Variable. The method isValid() would return false if something went wrong.
Note
Modifying the output variable will not change the file.

Definition at line 306 of file File.cpp.

References std::string::c_str(), std::endl(), matioCpp::Variable::isValid(), and matioCpp::MAT7_3.

◆ variableNames()

std::vector< std::string > matioCpp::File::variableNames ( ) const

Get the list of variables in the file.

Returns
The list of variables in the file.

Definition at line 288 of file File.cpp.

References std::vector< T >::resize().

◆ version()

matioCpp::FileVersion matioCpp::File::version ( ) const

The MAT file version.

Returns
The MAT file version

Definition at line 260 of file File.cpp.

References matioCpp::MAT4, matioCpp::MAT5, matioCpp::MAT7_3, and matioCpp::Undefined.

◆ write() [1/2]

bool matioCpp::File::write ( const Variable variable,
matioCpp::Compression  compression = matioCpp::Compression::None 
)

◆ write() [2/2]

template<class iterator >
bool matioCpp::File::write ( iterator  begin,
iterator  end,
matioCpp::Compression  compression = matioCpp::Compression::None 
)

Write a Variable to a file in a batch.

Parameters
beginIterator to the first element to be written
endIterator to the first element that is not written
compressionThe compression type to be used for writing the variable.
Returns
True if successful.

Definition at line 24 of file File.tpp.


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