Tag Parser  7.1.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
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/types.h>
7 #include <c++utilities/io/nativefilestream.h>
8 
9 #include <string>
10 
11 namespace TagParser {
12 
14 public:
15  // constructor, destructor
16  BasicFileInfo(const std::string &path = std::string());
17  BasicFileInfo(const BasicFileInfo &) = delete;
18  BasicFileInfo &operator=(const BasicFileInfo &) = delete;
19  virtual ~BasicFileInfo();
20 
21  // methods to control associated file stream
22  void open(bool readOnly = false);
23  void reopen(bool readonly = false);
24  bool isOpen() const;
25  bool isReadOnly() const;
26  void close();
27  void invalidate();
28  IoUtilities::NativeFileStream &stream();
29  const IoUtilities::NativeFileStream &stream() const;
30 
31  // methods to get, set path (components)
32  const std::string &path() const;
33  void setPath(const std::string &path);
34  static std::string fileName(const std::string &path, bool cutExtension = false);
35  std::string fileName(bool cutExtension = false) const;
36  static std::string extension(const std::string &path);
37  std::string extension() const;
38  static std::string pathWithoutExtension(const std::string &fullPath);
39  std::string pathWithoutExtension() const;
40  static std::string containingDirectory(const std::string &path);
41  std::string containingDirectory() const;
42 
43  // methods to get, set the file size
44  uint64 size() const;
45  void reportSizeChanged(uint64 newSize);
46  void reportPathChanged(const std::string &newPath);
47 
48 protected:
49  virtual void invalidated();
50 
51 private:
52  std::string m_path;
53  IoUtilities::NativeFileStream m_file;
54  uint64 m_size;
55  bool m_readOnly;
56 };
57 
63 inline bool BasicFileInfo::isOpen() const
64 {
65  return m_file.is_open();
66 }
67 
71 inline bool BasicFileInfo::isReadOnly() const
72 {
73  return m_readOnly;
74 }
75 
79 inline IoUtilities::NativeFileStream &BasicFileInfo::stream()
80 {
81  return m_file;
82 }
83 
87 inline const IoUtilities::NativeFileStream &BasicFileInfo::stream() const
88 {
89  return m_file;
90 }
91 
97 inline const std::string &BasicFileInfo::path() const
98 {
99  return m_path;
100 }
101 
109 inline uint64 BasicFileInfo::size() const
110 {
111  return m_size;
112 }
113 
118 inline void BasicFileInfo::reportSizeChanged(uint64 newSize)
119 {
120  m_size = newSize;
121 }
122 
127 inline void BasicFileInfo::reportPathChanged(const std::string &newPath)
128 {
129  m_path = newPath;
130 }
131 
132 } // namespace TagParser
133 
134 #endif // TAG_PARSER_BASICFILEINFO_H
const std::string & path() const
Returns the path of the current file.
Definition: basicfileinfo.h:97
bool isReadOnly() const
Indicates whether the last open()/reopen() call was read-only.
Definition: basicfileinfo.h:71
void reportPathChanged(const std::string &newPath)
Call this function to report that the path changed.
void reportSizeChanged(uint64 newSize)
Call this function to report that the size changed.
uint64 size() const
Returns size of the current file in bytes.
IoUtilities::NativeFileStream & stream()
Returns the std::fstream for the current instance.
Definition: basicfileinfo.h:79
bool isOpen() const
Indicates whether a std::fstream is open for the current file.
Definition: basicfileinfo.h:63
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:9
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
The BasicFileInfo class provides basic file information such as file name, extension, directory and size for a specified file.
Definition: basicfileinfo.h:13