Tag Parser 12.1.0
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
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;
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
69inline bool BasicFileInfo::isOpen() const
70{
71 return m_file.is_open();
72}
73
77inline bool BasicFileInfo::isReadOnly() const
78{
79 return m_readOnly;
80}
81
85inline CppUtilities::NativeFileStream &BasicFileInfo::stream()
86{
87 return m_file;
88}
89
93inline const CppUtilities::NativeFileStream &BasicFileInfo::stream() const
94{
95 return m_file;
96}
97
103inline const std::string &BasicFileInfo::path() const
104{
105 return m_path;
106}
107
115inline std::uint64_t BasicFileInfo::size() const
116{
117 return m_size;
118}
119
124inline void BasicFileInfo::reportSizeChanged(std::uint64_t newSize)
125{
126 m_size = newSize;
127}
128
133inline void BasicFileInfo::reportPathChanged(std::string_view newPath)
134{
135 m_path = newPath;
136}
137
142inline void BasicFileInfo::reportPathChanged(std::string &&newPath)
143{
144 m_path = std::move(newPath);
145}
146
153inline 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
The BasicFileInfo class provides basic file information such as file name, extension,...
void reportPathChanged(std::string_view newPath)
Call this function to report that the path changed.
const std::string & path() const
Returns the path of the current file.
bool isReadOnly() const
Indicates whether the last open()/reopen() call was read-only.
std::uint64_t size() const
Returns size of the current file in bytes.
CppUtilities::NativeFileStream & stream()
Returns the std::fstream for the current instance.
BasicFileInfo(const BasicFileInfo &)=delete
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(),...
void reportSizeChanged(std::uint64_t newSize)
Call this function to report that the size changed.
BasicFileInfo & operator=(const BasicFileInfo &)=delete
bool isOpen() const
Indicates whether a std::fstream is open for the current file.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:13
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10