Tag Parser  8.0.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
TagParser::BasicFileInfo Class Reference

The BasicFileInfo class provides basic file information such as file name, extension, directory and size for a specified file. More...

#include <basicfileinfo.h>

Inheritance diagram for TagParser::BasicFileInfo:
[legend]

Public Member Functions

 BasicFileInfo (const std::string &path=std::string())
 Constructs a new BasicFileInfo for the specified file. More...
 
 BasicFileInfo (const BasicFileInfo &)=delete
 
BasicFileInfooperator= (const BasicFileInfo &)=delete
 
virtual ~BasicFileInfo ()
 Destroys the BasicFileInfo. More...
 
void open (bool readOnly=false)
 Opens a std::fstream for the current file. More...
 
void reopen (bool readonly=false)
 Opens a std::fstream for the current file. More...
 
bool isOpen () const
 Indicates whether a std::fstream is open for the current file. More...
 
bool isReadOnly () const
 Indicates whether the last open()/reopen() call was read-only. More...
 
void close ()
 A possibly opened std::fstream will be closed. More...
 
void invalidate ()
 Invalidates the file info manually. More...
 
IoUtilities::NativeFileStream & stream ()
 Returns the std::fstream for the current instance. More...
 
const IoUtilities::NativeFileStream & stream () const
 Returns the std::fstream for the current instance. More...
 
const std::string & path () const
 Returns the path of the current file. More...
 
void setPath (const std::string &path)
 Sets the current file. More...
 
std::string fileName (bool cutExtension=false) const
 Returns the file name of the current file. More...
 
std::string extension () const
 Returns the extension of the current file. More...
 
std::string pathWithoutExtension () const
 Returns the path of the current file without the extension/suffix. More...
 
std::string containingDirectory () const
 Returns the path of the directory containing the current file. More...
 
uint64 size () const
 Returns size of the current file in bytes. More...
 
void reportSizeChanged (uint64 newSize)
 Call this function to report that the size changed. More...
 
void reportPathChanged (const std::string &newPath)
 Call this function to report that the path changed. More...
 

Static Public Member Functions

static std::string fileName (const std::string &path, bool cutExtension=false)
 Returns the file name of the given file. More...
 
static std::string extension (const std::string &path)
 Returns the extension of the given file. More...
 
static std::string pathWithoutExtension (const std::string &fullPath)
 Returns a copy of the given path without the extension/suffix. More...
 
static std::string containingDirectory (const std::string &path)
 Returns the path of the directory containing the given file. More...
 

Protected Member Functions

virtual void invalidated ()
 This function is called when the BasicFileInfo gets invalidated. More...
 

Detailed Description

The BasicFileInfo class provides basic file information such as file name, extension, directory and size for a specified file.

Definition at line 13 of file basicfileinfo.h.

Constructor & Destructor Documentation

◆ BasicFileInfo() [1/2]

TagParser::BasicFileInfo::BasicFileInfo ( const std::string &  path = std::string())

Constructs a new BasicFileInfo for the specified file.

Parameters
pathSpecifies the absolute or relative path of the file.

Definition at line 23 of file basicfileinfo.cpp.

◆ BasicFileInfo() [2/2]

TagParser::BasicFileInfo::BasicFileInfo ( const BasicFileInfo )
delete

◆ ~BasicFileInfo()

TagParser::BasicFileInfo::~BasicFileInfo ( )
virtual

Destroys the BasicFileInfo.

A possibly opened std::fstream will be closed.

Definition at line 36 of file basicfileinfo.cpp.

Member Function Documentation

◆ close()

void TagParser::BasicFileInfo::close ( )

A possibly opened std::fstream will be closed.

All flags of the stream will be cleared.

Definition at line 72 of file basicfileinfo.cpp.

◆ containingDirectory() [1/2]

string TagParser::BasicFileInfo::containingDirectory ( const std::string &  path)
static

Returns the path of the directory containing the given file.

Definition at line 180 of file basicfileinfo.cpp.

◆ containingDirectory() [2/2]

string TagParser::BasicFileInfo::containingDirectory ( ) const

Returns the path of the directory containing the current file.

The returned path is relative if the path of the file (specified using the setPath() method) is relative.

Definition at line 207 of file basicfileinfo.cpp.

◆ extension() [1/2]

string TagParser::BasicFileInfo::extension ( const std::string &  path)
static

Returns the extension of the given file.

Parameters
pathSpecifies the path of the file.

Definition at line 142 of file basicfileinfo.cpp.

◆ extension() [2/2]

string TagParser::BasicFileInfo::extension ( ) const

Returns the extension of the current file.

Definition at line 155 of file basicfileinfo.cpp.

◆ fileName() [1/2]

string TagParser::BasicFileInfo::fileName ( const std::string &  path,
bool  cutExtension = false 
)
static

Returns the file name of the given file.

Parameters
pathSpecifies the path of the file.
cutExtensionIndicates whether the extension/suffix should be cutted.

Definition at line 109 of file basicfileinfo.cpp.

◆ fileName() [2/2]

string TagParser::BasicFileInfo::fileName ( bool  cutExtension = false) const

Returns the file name of the current file.

Parameters
cutExtensionIndicates whether the extension should be cutted.

Definition at line 132 of file basicfileinfo.cpp.

◆ invalidate()

void TagParser::BasicFileInfo::invalidate ( )

Invalidates the file info manually.

Definition at line 83 of file basicfileinfo.cpp.

◆ invalidated()

void TagParser::BasicFileInfo::invalidated ( )
protectedvirtual

This function is called when the BasicFileInfo gets invalidated.

This is the case when the current file changes or is reopened.

When subclassing and overwriting this virtual method invoke the base implementation by calling BasicFileInfo::invalidated() before the reimplemented code.

Reimplemented in TagParser::MediaFileInfo.

Definition at line 219 of file basicfileinfo.cpp.

◆ isOpen()

bool TagParser::BasicFileInfo::isOpen ( ) const
inline

Indicates whether a std::fstream is open for the current file.

See also
stream()

Definition at line 63 of file basicfileinfo.h.

◆ isReadOnly()

bool TagParser::BasicFileInfo::isReadOnly ( ) const
inline

Indicates whether the last open()/reopen() call was read-only.

Definition at line 71 of file basicfileinfo.h.

◆ open()

void TagParser::BasicFileInfo::open ( bool  readOnly = false)

Opens a std::fstream for the current file.

Does nothing a stream is already open.

Parameters
readOnlyIndicates whether the stream should be opend as read-only.
Exceptions
Throwsstd::ios_base::failure when an IO error occurs.

Definition at line 46 of file basicfileinfo.cpp.

◆ operator=()

BasicFileInfo& TagParser::BasicFileInfo::operator= ( const BasicFileInfo )
delete

◆ path()

const std::string & TagParser::BasicFileInfo::path ( ) const
inline

Returns the path of the current file.

See also
setPath()

Definition at line 97 of file basicfileinfo.h.

◆ pathWithoutExtension() [1/2]

string TagParser::BasicFileInfo::pathWithoutExtension ( const std::string &  fullPath)
static

Returns a copy of the given path without the extension/suffix.

Definition at line 163 of file basicfileinfo.cpp.

◆ pathWithoutExtension() [2/2]

string TagParser::BasicFileInfo::pathWithoutExtension ( ) const

Returns the path of the current file without the extension/suffix.

Definition at line 172 of file basicfileinfo.cpp.

◆ reopen()

void TagParser::BasicFileInfo::reopen ( bool  readOnly = false)

Opens a std::fstream for the current file.

Closes a possibly already opened stream and clears all flags before.

Parameters
readOnlyIndicates whether the stream should be opend as read-only.
Exceptions
Throwsstd::ios_base::failure when an IO error occurs.

Definition at line 59 of file basicfileinfo.cpp.

◆ reportPathChanged()

void TagParser::BasicFileInfo::reportPathChanged ( const std::string &  newPath)
inline

Call this function to report that the path changed.

Remarks
Should be called after associating another file to the stream() manually.

Definition at line 127 of file basicfileinfo.h.

◆ reportSizeChanged()

void TagParser::BasicFileInfo::reportSizeChanged ( uint64  newSize)
inline

Call this function to report that the size changed.

Remarks
Should be called after writing/truncating the stream().

Definition at line 118 of file basicfileinfo.h.

◆ setPath()

void TagParser::BasicFileInfo::setPath ( const std::string &  path)

Sets the current file.

A possibly opened std::fstream will be closed and invalidated() will be called.

Parameters
pathSpecifies the absolute or relative path of the file to be set.

Definition at line 95 of file basicfileinfo.cpp.

◆ size()

uint64 TagParser::BasicFileInfo::size ( ) const
inline

Returns size of the current file in bytes.

Remarks
The file needs to be opened. Otherwise zero or the size of the previously opened file is returned. The size is not automatically updated when the file is modified. You might update the size using the reportSizeChanged() method.

Definition at line 109 of file basicfileinfo.h.

◆ stream() [1/2]

IoUtilities::NativeFileStream & TagParser::BasicFileInfo::stream ( )
inline

Returns the std::fstream for the current instance.

Definition at line 79 of file basicfileinfo.h.

◆ stream() [2/2]

const IoUtilities::NativeFileStream & TagParser::BasicFileInfo::stream ( ) const
inline

Returns the std::fstream for the current instance.

Definition at line 87 of file basicfileinfo.h.


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