Tag Parser: basicfileinfo.h Source File

Tag Parser 12.5.3 C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags

Loading...
Searching...
No Matches
basicfileinfo.h
Go to the documentation of this file.
1#ifndef TAG_PARSER_BASICFILEINFO_H
2#define TAG_PARSER_BASICFILEINFO_H
3
4#include "./global.h"
5
6#include <c++utilities/conversion/stringconversion.h>
7#include <c++utilities/io/nativefilestream.h>
8
9#include <cstdint>
10#include <string>
11
12namespace TagParser {
13
14 class TAG_PARSER_EXPORT BasicFileInfo {
15public:
16 // constructor, destructor
17 explicit BasicFileInfo();
18 explicit BasicFileInfo(std::string &&path);
19 explicit BasicFileInfo(std::string_view path);
20 BasicFileInfo(const BasicFileInfo &) = delete;
21 BasicFileInfo &operator=(const BasicFileInfo &) = delete;
22 virtual ~BasicFileInfo();
23
24 // methods to control associated file stream
25 void open(bool readOnly = false);
26 void reopen(bool readOnly = false);
27 bool isOpen() const;
28 bool isReadOnly() const;
29 void close();
30 void invalidate();
31 CppUtilities::NativeFileStream &stream();
32 const CppUtilities::NativeFileStream &stream() const;
33
34 // methods to get, set path (components)
35 const std::string &path() const;
36 void setPath(std::string_view path);
37 void setPath(std::string &&path);
38 static std::string fileName(std::string_view path, bool cutExtension = false);
39 std::string fileName(bool cutExtension = false) const;
40 static std::string extension(std::string_view path);
41 std::string extension() const;
42 static std::string pathWithoutExtension(std::string_view fullPath);
43 std::string pathWithoutExtension() const;
44 static std::string containingDirectory(std::string_view path);
45 std::string containingDirectory() const;
46 static std::string_view pathForOpen(std::string_view url);
47
48 // methods to get, set the file size
49 std::uint64_t size() const;
50 void reportSizeChanged(std::uint64_t newSize);
51 void reportPathChanged(std::string_view newPath);
52 void reportPathChanged(std::string &&newPath);
53
54protected:
55 virtual void invalidated();
56
57private:
58 std::string m_path;
59 CppUtilities::NativeFileStream m_file;
60 std::uint64_t m_size;
61 bool m_readOnly;
62};
63
69 inline bool BasicFileInfo::isOpen() const
70{
71 return m_file.is_open();
72}
73
77 inline bool BasicFileInfo::isReadOnly() const
78{
79 return m_readOnly;
80}
81
85 inline CppUtilities::NativeFileStream &BasicFileInfo::stream()
86{
87 return m_file;
88}
89
93 inline const CppUtilities::NativeFileStream &BasicFileInfo::stream() const
94{
95 return m_file;
96}
97
103 inline const std::string &BasicFileInfo::path() const
104{
105 return m_path;
106}
107
115 inline std::uint64_t BasicFileInfo::size() const
116{
117 return m_size;
118}
119
124 inline void BasicFileInfo::reportSizeChanged(std::uint64_t newSize)
125{
126 m_size = newSize;
127}
128
133 inline void BasicFileInfo::reportPathChanged(std::string_view newPath)
134{
135 m_path = newPath;
136}
137
142 inline void BasicFileInfo::reportPathChanged(std::string &&newPath)
143{
144 m_path = std::move(newPath);
145}
146
153 inline std::string_view BasicFileInfo::pathForOpen(std::string_view url)
154{
155 return CppUtilities::startsWith(url, "file:/") ? url.data() + 6 : url.data();
156}
157
158} // namespace TagParser
159
160#endif // TAG_PARSER_BASICFILEINFO_H
TagParser::BasicFileInfo::BasicFileInfo
BasicFileInfo()
Constructs a new BasicFileInfo for the specified file.
Definition basicfileinfo.cpp:23
TagParser::BasicFileInfo::fileName
static std::string fileName(std::string_view path, bool cutExtension=false)
Returns the file name of the given file.
Definition basicfileinfo.cpp:149
TagParser::BasicFileInfo::extension
static std::string extension(std::string_view path)
Returns the extension of the given file.
Definition basicfileinfo.cpp:182
TagParser::BasicFileInfo::reportPathChanged
void reportPathChanged(std::string_view newPath)
Call this function to report that the path changed.
Definition basicfileinfo.h:133
TagParser::BasicFileInfo::invalidate
void invalidate()
Invalidates the file info manually.
Definition basicfileinfo.cpp:108
TagParser::BasicFileInfo::path
const std::string & path() const
Returns the path of the current file.
Definition basicfileinfo.h:103
TagParser::BasicFileInfo::isReadOnly
bool isReadOnly() const
Indicates whether the last open()/reopen() call was read-only.
Definition basicfileinfo.h:77
TagParser::BasicFileInfo::containingDirectory
static std::string containingDirectory(std::string_view path)
Returns the path of the directory containing the given file.
Definition basicfileinfo.cpp:220
TagParser::BasicFileInfo::reopen
void reopen(bool readOnly=false)
Opens a std::fstream for the current file.
Definition basicfileinfo.cpp:84
TagParser::BasicFileInfo::size
std::uint64_t size() const
Returns size of the current file in bytes.
Definition basicfileinfo.h:115
TagParser::BasicFileInfo::invalidated
virtual void invalidated()
This function is called when the BasicFileInfo gets invalidated.
Definition basicfileinfo.cpp:259
TagParser::BasicFileInfo::stream
CppUtilities::NativeFileStream & stream()
Returns the std::fstream for the current instance.
Definition basicfileinfo.h:85
TagParser::BasicFileInfo::open
void open(bool readOnly=false)
Opens a std::fstream for the current file.
Definition basicfileinfo.cpp:71
TagParser::BasicFileInfo::BasicFileInfo
BasicFileInfo(const BasicFileInfo &)=delete
TagParser::BasicFileInfo::pathWithoutExtension
static std::string pathWithoutExtension(std::string_view fullPath)
Returns a copy of the given path without the extension/suffix.
Definition basicfileinfo.cpp:203
TagParser::BasicFileInfo::close
void close()
A possibly opened std::fstream will be closed.
Definition basicfileinfo.cpp:97
TagParser::BasicFileInfo::pathForOpen
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(),...
Definition basicfileinfo.h:153
TagParser::BasicFileInfo::reportSizeChanged
void reportSizeChanged(std::uint64_t newSize)
Call this function to report that the size changed.
Definition basicfileinfo.h:124
TagParser::BasicFileInfo::operator=
BasicFileInfo & operator=(const BasicFileInfo &)=delete
TagParser::BasicFileInfo::isOpen
bool isOpen() const
Indicates whether a std::fstream is open for the current file.
Definition basicfileinfo.h:69
TagParser::BasicFileInfo::setPath
void setPath(std::string_view path)
Sets the current file.
Definition basicfileinfo.cpp:120
global.h
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
TagParser
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10