Tag Parser 12.3.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
Loading...
Searching...
No Matches
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 ()
 Constructs a new BasicFileInfo for the specified file.
 
 BasicFileInfo (std::string &&path)
 Constructs a new BasicFileInfo for the specified file.
 
 BasicFileInfo (std::string_view path)
 Constructs a new BasicFileInfo for the specified file.
 
 BasicFileInfo (const BasicFileInfo &)=delete
 
BasicFileInfooperator= (const BasicFileInfo &)=delete
 
virtual ~BasicFileInfo ()
 Destroys the BasicFileInfo.
 
void open (bool readOnly=false)
 Opens a std::fstream for the current file.
 
void reopen (bool readOnly=false)
 Opens a std::fstream for the current file.
 
bool isOpen () const
 Indicates whether a std::fstream is open for the current file.
 
bool isReadOnly () const
 Indicates whether the last open()/reopen() call was read-only.
 
void close ()
 A possibly opened std::fstream will be closed.
 
void invalidate ()
 Invalidates the file info manually.
 
CppUtilities::NativeFileStream & stream ()
 Returns the std::fstream for the current instance.
 
const CppUtilities::NativeFileStream & stream () const
 Returns the std::fstream for the current instance.
 
const std::string & path () const
 Returns the path of the current file.
 
void setPath (std::string_view path)
 Sets the current file.
 
void setPath (std::string &&path)
 Sets the current file.
 
std::string fileName (bool cutExtension=false) const
 Returns the file name of the current file.
 
std::string extension () const
 Returns the extension of the current file.
 
std::string pathWithoutExtension () const
 Returns the path of the current file without the extension/suffix.
 
std::string containingDirectory () const
 Returns the path of the directory containing the current file.
 
std::uint64_t size () const
 Returns size of the current file in bytes.
 
void reportSizeChanged (std::uint64_t newSize)
 Call this function to report that the size changed.
 
void reportPathChanged (std::string_view newPath)
 Call this function to report that the path changed.
 
void reportPathChanged (std::string &&newPath)
 Call this function to report that the path changed.
 

Static Public Member Functions

static std::string fileName (std::string_view path, bool cutExtension=false)
 Returns the file name of the given file.
 
static std::string extension (std::string_view path)
 Returns the extension of the given file.
 
static std::string pathWithoutExtension (std::string_view fullPath)
 Returns a copy of the given path without the extension/suffix.
 
static std::string containingDirectory (std::string_view path)
 Returns the path of the directory containing the given file.
 
static std::string_view pathForOpen (std::string_view url)
 Returns removes the "file:/" prefix from url to be able to pass it to functions like open(), stat() and truncate().
 

Protected Member Functions

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

Detailed Description

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

Definition at line 14 of file basicfileinfo.h.

Constructor & Destructor Documentation

◆ BasicFileInfo() [1/4]

TagParser::BasicFileInfo::BasicFileInfo ( )
explicit

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/4]

TagParser::BasicFileInfo::BasicFileInfo ( std::string && path)
explicit

Constructs a new BasicFileInfo for the specified file.

Parameters
pathSpecifies the absolute or relative path of the file.

Definition at line 35 of file basicfileinfo.cpp.

◆ BasicFileInfo() [3/4]

TagParser::BasicFileInfo::BasicFileInfo ( std::string_view path)
explicit

Constructs a new BasicFileInfo for the specified file.

Parameters
pathSpecifies the absolute or relative path of the file.

Definition at line 48 of file basicfileinfo.cpp.

◆ BasicFileInfo() [4/4]

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 61 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 97 of file basicfileinfo.cpp.

◆ containingDirectory() [1/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 247 of file basicfileinfo.cpp.

◆ containingDirectory() [2/2]

std::string TagParser::BasicFileInfo::containingDirectory ( std::string_view path)
static

Returns the path of the directory containing the given file.

Definition at line 220 of file basicfileinfo.cpp.

◆ extension() [1/2]

std::string TagParser::BasicFileInfo::extension ( ) const

Returns the extension of the current file.

Definition at line 195 of file basicfileinfo.cpp.

◆ extension() [2/2]

std::string TagParser::BasicFileInfo::extension ( std::string_view path)
static

Returns the extension of the given file.

Parameters
pathSpecifies the path of the file.

Definition at line 182 of file basicfileinfo.cpp.

◆ fileName() [1/2]

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

Returns the file name of the current file.

Parameters
cutExtensionIndicates whether the extension should be cut.

Definition at line 172 of file basicfileinfo.cpp.

◆ fileName() [2/2]

std::string TagParser::BasicFileInfo::fileName ( std::string_view 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 cut.

Definition at line 149 of file basicfileinfo.cpp.

◆ invalidate()

void TagParser::BasicFileInfo::invalidate ( )

Invalidates the file info manually.

Definition at line 108 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 259 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 69 of file basicfileinfo.h.

◆ isReadOnly()

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

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

Definition at line 77 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 71 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 103 of file basicfileinfo.h.

◆ pathForOpen()

std::string_view TagParser::BasicFileInfo::pathForOpen ( std::string_view url)
inlinestatic

Returns removes the "file:/" prefix from url to be able to pass it to functions like open(), stat() and truncate().

Remarks
If url is already a plain path it won't changed.
Returns
Returns a pointer the URL data itself. No copy is made.

Definition at line 153 of file basicfileinfo.h.

◆ pathWithoutExtension() [1/2]

std::string TagParser::BasicFileInfo::pathWithoutExtension ( ) const

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

Definition at line 212 of file basicfileinfo.cpp.

◆ pathWithoutExtension() [2/2]

std::string TagParser::BasicFileInfo::pathWithoutExtension ( std::string_view fullPath)
static

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

Definition at line 203 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 84 of file basicfileinfo.cpp.

◆ reportPathChanged() [1/2]

void TagParser::BasicFileInfo::reportPathChanged ( 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 142 of file basicfileinfo.h.

◆ reportPathChanged() [2/2]

void TagParser::BasicFileInfo::reportPathChanged ( std::string_view 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 133 of file basicfileinfo.h.

◆ reportSizeChanged()

void TagParser::BasicFileInfo::reportSizeChanged ( std::uint64_t newSize)
inline

Call this function to report that the size changed.

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

Definition at line 124 of file basicfileinfo.h.

◆ setPath() [1/2]

void TagParser::BasicFileInfo::setPath ( 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 135 of file basicfileinfo.cpp.

◆ setPath() [2/2]

void TagParser::BasicFileInfo::setPath ( std::string_view 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 120 of file basicfileinfo.cpp.

◆ size()

std::uint64_t 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 115 of file basicfileinfo.h.

◆ stream() [1/2]

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

Returns the std::fstream for the current instance.

Definition at line 85 of file basicfileinfo.h.

◆ stream() [2/2]

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

Returns the std::fstream for the current instance.

Definition at line 93 of file basicfileinfo.h.


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