tagparser/basicfileinfo.h

101 lines
2.4 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:
BasicFileInfo();
BasicFileInfo(const std::string &path);
BasicFileInfo(const BasicFileInfo &) = delete;
BasicFileInfo &operator=(const BasicFileInfo &) = delete;
virtual ~BasicFileInfo();
void open(bool readonly = false);
void reopen(bool readonly = false);
bool isOpen();
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;
};
/*!
* \brief Indicates whether a std::fstream is open for the current file.
*
* \sa stream()
*/
inline bool BasicFileInfo::isOpen()
{
return m_file.is_open();
}
/*!
* \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