diff --git a/basicfileinfo.cpp b/basicfileinfo.cpp index 2d9beaa..02221a8 100644 --- a/basicfileinfo.cpp +++ b/basicfileinfo.cpp @@ -15,15 +15,6 @@ using namespace std; namespace Media { -/*! - * \brief Constructs a new BasicFileInfo. - */ -BasicFileInfo::BasicFileInfo() : - m_size(0) -{ - m_file.exceptions(fstream::failbit | fstream::badbit); -} - /*! * \brief Constructs a new BasicFileInfo for the specified file. * @@ -31,7 +22,8 @@ BasicFileInfo::BasicFileInfo() : */ BasicFileInfo::BasicFileInfo(const std::string &path) : m_path(path), - m_size(0) + m_size(0), + m_readOnly(false) { m_file.exceptions(fstream::failbit | fstream::badbit); } @@ -48,26 +40,26 @@ BasicFileInfo::~BasicFileInfo() /*! * \brief Opens a std::fstream for the current file. Does nothing a stream is already open. - * \param readonly Indicates whether the stream should be opend as read-only. + * \param readOnly Indicates whether the stream should be opend as read-only. * \throws Throws std::ios_base::failure when an IO error occurs. */ -void BasicFileInfo::open(bool readonly) +void BasicFileInfo::open(bool readOnly) { if(!isOpen()) { - reopen(readonly); + reopen(readOnly); } } /*! * \brief Opens a std::fstream for the current file. Closes a possibly already opened stream and * clears all flags before. - * \param readonly Indicates whether the stream should be opend as read-only. + * \param readOnly Indicates whether the stream should be opend as read-only. * \throws Throws std::ios_base::failure when an IO error occurs. */ -void BasicFileInfo::reopen(bool readonly) +void BasicFileInfo::reopen(bool readOnly) { close(); - m_file.open(m_path, readonly ? ios_base::in | ios_base::binary : ios_base::in | ios_base::out | ios_base::binary); + m_file.open(m_path, (m_readOnly = readOnly) ? ios_base::in | ios_base::binary : ios_base::in | ios_base::out | ios_base::binary); m_file.seekg(0, ios_base::end); m_size = m_file.tellg(); m_file.seekg(0, ios_base::beg); diff --git a/basicfileinfo.h b/basicfileinfo.h index 1a0fce4..631f0cb 100644 --- a/basicfileinfo.h +++ b/basicfileinfo.h @@ -12,15 +12,15 @@ namespace Media { class LIB_EXPORT BasicFileInfo { public: - BasicFileInfo(); - BasicFileInfo(const std::string &path); + BasicFileInfo(const std::string &path = std::string()); BasicFileInfo(const BasicFileInfo &) = delete; BasicFileInfo &operator=(const BasicFileInfo &) = delete; virtual ~BasicFileInfo(); - void open(bool readonly = false); + void open(bool readOnly = false); void reopen(bool readonly = false); - bool isOpen(); + bool isOpen() const; + bool isReadOnly() const; void close(); const std::string &path() const; @@ -45,6 +45,7 @@ private: std::string m_path; std::fstream m_file; uint64 m_size; + bool m_readOnly; }; /*! @@ -52,11 +53,19 @@ private: * * \sa stream() */ -inline bool BasicFileInfo::isOpen() +inline bool BasicFileInfo::isOpen() const { return m_file.is_open(); } +/*! + * \brief Indicates whether the last open()/reopen() call was read-only. + */ +inline bool BasicFileInfo::isReadOnly() const +{ + return m_readOnly; +} + /*! * \brief Returns the std::fstream for the current instance. */ diff --git a/matroska/matroskacontainer.cpp b/matroska/matroskacontainer.cpp index 6bbff02..399d3f4 100644 --- a/matroska/matroskacontainer.cpp +++ b/matroska/matroskacontainer.cpp @@ -171,7 +171,7 @@ void MatroskaContainer::validateIndex() if(clusterElement->id() != MatroskaIds::Cluster) { addNotification(NotificationType::Critical, "\"CueClusterPosition\" element at " + numberToString(subElement->startOffset()) + " does not point to \"Cluster\"-element (points to " + numberToString(clusterElement->startOffset()) + ").", context); } - } catch(Failure &) { + } catch(const Failure &) { addNotifications(context, *clusterElement); } break; @@ -211,7 +211,7 @@ void MatroskaContainer::validateIndex() default: addNotification(NotificationType::Critical, "\"CueRelativePosition\" element does not point to \"Block\"-, \"BlockGroup\", or \"SimpleBlock\"-element (points to " + numberToString(referenceElement.startOffset()) + ").", context); } - } catch(Failure &) { + } catch(const Failure &) { addNotifications(context, referenceElement); } } @@ -493,7 +493,7 @@ void MatroskaContainer::internalParseHeader() default: ; } - } catch(Failure &) { + } catch(const Failure &) { addNotification(NotificationType::Critical, "Can not parse element at " + numberToString(offset) + " (denoted using \"SeekHead\" element).", context); } } @@ -586,7 +586,7 @@ void MatroskaContainer::internalParseTags() m_tags.back()->parse(*subElement); } catch(NoDataFoundException &) { m_tags.pop_back(); - } catch(Failure &) { + } catch(const Failure &) { addNotification(NotificationType::Critical, "Unable to parse tag " + ConversionUtilities::numberToString(m_tags.size()) + ".", context); } break; @@ -597,7 +597,7 @@ void MatroskaContainer::internalParseTags() addNotification(NotificationType::Warning, "\"Tags\"-element contains unknown child. It will be ignored.", context); } } - } catch(Failure &) { + } catch(const Failure &) { addNotification(NotificationType::Critical, "Element structure seems to be invalid.", context); throw; } @@ -620,7 +620,7 @@ void MatroskaContainer::internalParseTracks() m_tracks.back()->parseHeader(); } catch(NoDataFoundException &) { m_tracks.pop_back(); - } catch(Failure &) { + } catch(const Failure &) { addNotification(NotificationType::Critical, "Unable to parse track " + ConversionUtilities::numberToString(m_tracks.size()) + ".", context); } break; @@ -631,7 +631,7 @@ void MatroskaContainer::internalParseTracks() addNotification(NotificationType::Warning, "\"Tracks\"-element contains unknown child element \"" + subElement->idToString() + "\". It will be ignored.", context); } } - } catch(Failure &) { + } catch(const Failure &) { addNotification(NotificationType::Critical, "Element structure seems to be invalid.", context); throw; } @@ -654,7 +654,7 @@ void MatroskaContainer::internalParseChapters() m_editionEntries.back()->parseNested(); } catch(NoDataFoundException &) { m_editionEntries.pop_back(); - } catch(Failure &) { + } catch(const Failure &) { addNotification(NotificationType::Critical, "Unable to parse edition entry " + ConversionUtilities::numberToString(m_editionEntries.size()) + ".", context); } break; @@ -665,7 +665,7 @@ void MatroskaContainer::internalParseChapters() addNotification(NotificationType::Warning, "\"Chapters\"-element contains unknown child element \"" + subElement->idToString() + "\". It will be ignored.", context); } } - } catch(Failure &) { + } catch(const Failure &) { addNotification(NotificationType::Critical, "Element structure seems to be invalid.", context); throw; } @@ -688,7 +688,7 @@ void MatroskaContainer::internalParseAttachments() m_attachments.back()->parse(subElement); } catch(NoDataFoundException &) { m_attachments.pop_back(); - } catch(Failure &) { + } catch(const Failure &) { addNotification(NotificationType::Critical, "Unable to parse attached file " + ConversionUtilities::numberToString(m_attachments.size()) + ".", context); } break; @@ -699,7 +699,7 @@ void MatroskaContainer::internalParseAttachments() addNotification(NotificationType::Warning, "\"Attachments\"-element contains unknown child element \"" + subElement->idToString() + "\". It will be ignored.", context); } } - } catch(Failure &) { + } catch(const Failure &) { addNotification(NotificationType::Critical, "Element structure seems to be invalid.", context); throw; } @@ -901,7 +901,7 @@ void MatroskaContainer::internalMakeFile() } } - } catch(Failure &) { + } catch(const Failure &) { addNotification(NotificationType::Critical, "Unable to parse content in top-level element at " + numberToString(level0Element->startOffset()) + " of original file.", context); throw; } @@ -948,7 +948,7 @@ calculateSegmentData: if((segment.cuesElement = level0Element->childById(MatroskaIds::Cues))) { try { segment.cuesUpdater.parse(segment.cuesElement); - } catch(Failure &) { + } catch(const Failure &) { addNotifications(segment.cuesUpdater); throw; } @@ -1316,10 +1316,10 @@ nonRewriteCalculations: } } - } catch(Failure &) { + } catch(const Failure &) { addNotification(NotificationType::Critical, "Parsing the original file failed.", context); throw; - } catch(ios_base::failure &) { + } catch(const ios_base::failure &) { addNotification(NotificationType::Critical, "An IO error occured when parsing the original file.", context); throw; } @@ -1495,7 +1495,7 @@ nonRewriteCalculations: try { segment.cuesUpdater.make(outputStream); addNotifications(segment.cuesUpdater); - } catch(Failure &) { + } catch(const Failure &) { addNotifications(segment.cuesUpdater); throw; } @@ -1593,7 +1593,7 @@ nonRewriteCalculations: try { segment.cuesUpdater.make(outputStream); addNotifications(segment.cuesUpdater); - } catch(Failure &) { + } catch(const Failure &) { addNotifications(segment.cuesUpdater); throw; } @@ -1668,7 +1668,7 @@ nonRewriteCalculations: reset(); try { parseHeader(); - } catch(Failure &) { + } catch(const Failure &) { addNotification(NotificationType::Critical, "Unable to reparse the header of the new file.", context); throw; } diff --git a/matroska/matroskacues.cpp b/matroska/matroskacues.cpp index 4a2c77a..1aa9f7d 100644 --- a/matroska/matroskacues.cpp +++ b/matroska/matroskacues.cpp @@ -264,7 +264,7 @@ void MatroskaCuePositionUpdater::make(ostream &stream) case MatroskaIds::CueRelativePosition: try { EbmlElement::makeSimpleElement(stream, cueTrackPositionsChild->id(), m_relativeOffsets.at(cueTrackPositionsChild).currentValue()); - } catch(out_of_range &) { + } catch(const out_of_range &) { // we were not able parse the relative offset because the absolute offset is missing // continue anyways } @@ -316,7 +316,7 @@ void MatroskaCuePositionUpdater::make(ostream &stream) addNotification(NotificationType::Warning, "\"Cues\"-element contains a element which is not a \"CuePoint\"-element. It will be ignored.", context); } } - } catch(out_of_range &) { + } catch(const out_of_range &) { addNotification(NotificationType::Critical, "Unable to write the file index because the index of the original file could not be parsed correctly.", context); throw InvalidDataException(); } diff --git a/matroska/matroskaseekinfo.cpp b/matroska/matroskaseekinfo.cpp index c898ea5..116a06c 100644 --- a/matroska/matroskaseekinfo.cpp +++ b/matroska/matroskaseekinfo.cpp @@ -38,10 +38,6 @@ void MatroskaSeekInfo::shift(uint64 start, int64 amount) void MatroskaSeekInfo::parse(EbmlElement *seekHeadElement) { static const string context("parsing \"SeekHead\"-element"); - //if(!seekHeadElement->parent()) { - // addNotification(NotificationType::Warning, "\"SeekHead\"-element without parent specified.", context); - // throw InvalidDataException(); - //} m_seekHeadElement = seekHeadElement; m_info.clear(); EbmlElement *seekElement = seekHeadElement->firstChild(); diff --git a/matroska/matroskatag.cpp b/matroska/matroskatag.cpp index dff9b4d..a063dc6 100644 --- a/matroska/matroskatag.cpp +++ b/matroska/matroskatag.cpp @@ -72,7 +72,7 @@ KnownField MatroskaTag::knownField(const std::string &id) const }); try { return map.at(id); - } catch(out_of_range &) { + } catch(const out_of_range &) { return KnownField::Invalid; } } @@ -100,7 +100,7 @@ void MatroskaTag::parse(EbmlElement &tagElement) field.invalidateNotifications(); field.reparse(*child, true); fields().insert(pair(field.id(), field)); - } catch(Failure &) { + } catch(const Failure &) { } addNotifications(context, field); break;