tagparser/basicfileinfo.h

110 lines
2.6 KiB
C
Raw Normal View History

2015-04-22 19:22:01 +02:00
#ifndef BASICFILEINFO_H
#define BASICFILEINFO_H
#include <c++utilities/application/global.h>
#include <c++utilities/conversion/types.h>
#include <string>
#include <fstream>
namespace Media {
class LIB_EXPORT BasicFileInfo
{
public:
2016-03-12 18:36:10 +01:00
BasicFileInfo(const std::string &path = std::string());
2015-04-22 19:22:01 +02:00
BasicFileInfo(const BasicFileInfo &) = delete;
BasicFileInfo &operator=(const BasicFileInfo &) = delete;
virtual ~BasicFileInfo();
2016-03-12 18:36:10 +01:00
void open(bool readOnly = false);
2015-04-22 19:22:01 +02:00
void reopen(bool readonly = false);
2016-03-12 18:36:10 +01:00
bool isOpen() const;
bool isReadOnly() const;
2015-04-22 19:22:01 +02:00
void close();
const std::string &path() const;
void setPath(const std::string &path);
static std::string fileName(const std::string &path, bool cutExtension = false);
std::string fileName(bool cutExtension = false) const;
static std::string extension(const std::string &path);
std::string extension() const;
static std::string pathWithoutExtension(const std::string &fullPath);
std::string pathWithoutExtension() const;
static std::string containingDirectory(const std::string &path);
std::string containingDirectory() const;
std::fstream &stream();
const std::fstream &stream() const;
uint64 size() const;
void reportSizeChanged(uint64 newSize);
protected:
virtual void invalidated();
private:
std::string m_path;
std::fstream m_file;
uint64 m_size;
2016-03-12 18:36:10 +01:00
bool m_readOnly;
2015-04-22 19:22:01 +02:00
};
/*!
* \brief Indicates whether a std::fstream is open for the current file.
*
* \sa stream()
*/
2016-03-12 18:36:10 +01:00
inline bool BasicFileInfo::isOpen() const
2015-04-22 19:22:01 +02:00
{
return m_file.is_open();
}
2016-03-12 18:36:10 +01:00
/*!
* \brief Indicates whether the last open()/reopen() call was read-only.
*/
inline bool BasicFileInfo::isReadOnly() const
{
return m_readOnly;
}
2015-04-22 19:22:01 +02:00
/*!
* \brief Returns the std::fstream for the current instance.
*/
inline std::fstream &BasicFileInfo::stream()
{
return m_file;
}
/*!
* \brief Returns the std::fstream for the current instance.
*/
inline const std::fstream &BasicFileInfo::stream() const
{
return m_file;
}
/*!
* \brief Returns the path of the current file.
*
* \sa setPath()
*/
inline const std::string &BasicFileInfo::path() const
{
return m_path;
}
/*!
* \brief 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.
*/
inline uint64 BasicFileInfo::size() const
{
return m_size;
}
}
#endif // BASICFILEINFO_H