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