3 #include <c++utilities/conversion/stringconversion.h> 23 BasicFileInfo::BasicFileInfo(
const std::string &path)
28 m_file.exceptions(ios_base::failbit | ios_base::badbit);
62 m_file.open(startsWith(m_path,
"file:/") ? m_path.data() + 6 : m_path.data(),
63 (m_readOnly = readOnly) ? ios_base::in | ios_base::binary : ios_base::in | ios_base::out | ios_base::binary);
64 m_file.seekg(0, ios_base::end);
65 m_size =
static_cast<uint64
>(m_file.tellg());
66 m_file.seekg(0, ios_base::beg);
111 size_t lastSlash =
path.rfind(
'/');
112 size_t lastBackSlash =
path.rfind(
'\\');
113 size_t lastPoint = cutExtension ?
path.rfind(
'.') : string::npos;
114 size_t lastSeparator;
115 if (lastSlash == string::npos && lastBackSlash == string::npos) {
116 return (lastPoint == string::npos) ?
path :
path.substr(0, lastPoint);
117 }
else if (lastSlash == string::npos) {
118 lastSeparator = lastBackSlash;
119 }
else if (lastBackSlash == string::npos) {
120 lastSeparator = lastSlash;
122 lastSeparator = lastSlash > lastBackSlash ? lastSlash : lastBackSlash;
124 return (lastPoint != string::npos) ?
path.substr(lastSeparator + 1, lastPoint - lastSeparator - 1) :
path.substr(lastSeparator + 1);
134 return fileName(m_path, cutExtension);
144 size_t lastPoint =
path.rfind(
'.');
145 if (lastPoint == string::npos) {
148 return path.substr(lastPoint);
165 size_t lastPoint = fullPath.rfind(
'.');
166 return lastPoint != string::npos ? fullPath.substr(0, lastPoint) : fullPath;
182 size_t lastSlash =
path.rfind(
'/');
183 size_t lastBackSlash =
path.rfind(
'\\');
184 size_t lastSeparator;
185 if (lastSlash == string::npos && lastBackSlash == string::npos) {
187 }
else if (lastSlash == string::npos) {
188 lastSeparator = lastBackSlash;
189 }
else if (lastBackSlash == string::npos) {
190 lastSeparator = lastSlash;
192 lastSeparator = lastSlash > lastBackSlash ? lastSlash : lastBackSlash;
194 if (lastSeparator > 0) {
195 return path.substr(0, lastSeparator);
void setPath(const std::string &path)
Sets the current file.
void open(bool readOnly=false)
Opens a std::fstream for the current file.
std::string extension() const
Returns the extension of the current file.
const std::string & path() const
Returns the path of the current file.
virtual void invalidated()
This function is called when the BasicFileInfo gets invalidated.
void invalidate()
Invalidates the file info manually.
std::string containingDirectory() const
Returns the path of the directory containing the current file.
static std::string fileName(const std::string &path, bool cutExtension=false)
Returns the file name of the given file.
virtual ~BasicFileInfo()
Destroys the BasicFileInfo.
void reopen(bool readonly=false)
Opens a std::fstream for the current file.
void close()
A possibly opened std::fstream will be closed.
std::string pathWithoutExtension() const
Returns the path of the current file without the extension/suffix.
bool isOpen() const
Indicates whether a std::fstream is open for the current file.
Contains all classes and functions of the TagInfo library.