nodiscard addition

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2022-03-29 18:47:04 -07:00
parent 389501462a
commit c4eedd6ae4
17 changed files with 145 additions and 141 deletions

View File

@ -201,25 +201,25 @@ class EXIV2API BasicIo {
@return Offset from the start of IO if successful;<BR>
-1 if failure;
*/
virtual long tell() const = 0;
[[nodiscard]] virtual long tell() const = 0;
/*!
@brief Get the current size of the IO source in bytes.
@return Size of the IO source in bytes;<BR>
-1 if failure;
*/
virtual size_t size() const = 0;
[[nodiscard]] virtual size_t size() const = 0;
//! Returns true if the IO source is open, otherwise false.
virtual bool isopen() const = 0;
[[nodiscard]] virtual bool isopen() const = 0;
//! Returns 0 if the IO source is in a valid state, otherwise nonzero.
virtual int error() const = 0;
[[nodiscard]] virtual int error() const = 0;
//! Returns true if the IO position has reached the end, otherwise false.
virtual bool eof() const = 0;
[[nodiscard]] virtual bool eof() const = 0;
/*!
@brief Return the path to the IO resource. Often used to form
comprehensive error messages where only a BasicIo instance is
available.
*/
virtual const std::string &path() const noexcept = 0;
[[nodiscard]] virtual const std::string &path() const noexcept = 0;
/*!
@brief Mark all the bNone blocks to bKnow. This avoids allocating memory
@ -442,22 +442,22 @@ class EXIV2API FileIo : public BasicIo {
@return Offset from the start of the file if successful;<BR>
-1 if failure;
*/
long tell() const override;
[[nodiscard]] long tell() const override;
/*!
@brief Flush any buffered writes and get the current file size
in bytes.
@return Size of the file in bytes;<BR>
-1 if failure;
*/
size_t size() const override;
[[nodiscard]] size_t size() const override;
//! Returns true if the file is open, otherwise false.
bool isopen() const override;
[[nodiscard]] bool isopen() const override;
//! Returns 0 if the file is in a valid state, otherwise nonzero.
int error() const override;
[[nodiscard]] int error() const override;
//! Returns true if the file position has reached the end, otherwise false.
bool eof() const override;
[[nodiscard]] bool eof() const override;
//! Returns the path of the file
const std::string &path() const noexcept override;
[[nodiscard]] const std::string &path() const noexcept override;
/*!
@brief Mark all the bNone blocks to bKnow. This avoids allocating memory
@ -624,21 +624,21 @@ class EXIV2API MemIo : public BasicIo {
@brief Get the current IO position.
@return Offset from the start of the memory block
*/
long tell() const override;
[[nodiscard]] long tell() const override;
/*!
@brief Get the current memory buffer size in bytes.
@return Size of the in memory data in bytes;<BR>
-1 if failure;
*/
size_t size() const override;
[[nodiscard]] size_t size() const override;
//! Always returns true
bool isopen() const override;
[[nodiscard]] bool isopen() const override;
//! Always returns 0
int error() const override;
[[nodiscard]] int error() const override;
//! Returns true if the IO position has reached the end, otherwise false.
bool eof() const override;
[[nodiscard]] bool eof() const override;
//! Returns a dummy path, indicating that memory access is used
const std::string &path() const noexcept override;
[[nodiscard]] const std::string &path() const noexcept override;
/*!
@brief Mark all the bNone blocks to bKnow. This avoids allocating memory
@ -868,21 +868,21 @@ class EXIV2API RemoteIo : public BasicIo {
@brief Get the current IO position.
@return Offset from the start of the memory block
*/
long tell() const override;
[[nodiscard]] long tell() const override;
/*!
@brief Get the current memory buffer size in bytes.
@return Size of the in memory data in bytes;<BR>
-1 if failure;
*/
size_t size() const override;
[[nodiscard]] size_t size() const override;
//! Returns true if the memory area is allocated.
bool isopen() const override;
[[nodiscard]] bool isopen() const override;
//! Always returns 0
int error() const override;
[[nodiscard]] int error() const override;
//! Returns true if the IO position has reached the end, otherwise false.
bool eof() const override;
[[nodiscard]] bool eof() const override;
//! Returns the URL of the file.
const std::string &path() const noexcept override;
[[nodiscard]] const std::string &path() const noexcept override;
/*!
@brief Mark all the bNone blocks to bKnow. This avoids allocating memory

View File

@ -26,7 +26,7 @@ struct Iloc {
uint32_t start_;
uint32_t length_;
std::string toString() const;
[[nodiscard]] std::string toString() const;
}; // class Iloc
// *****************************************************************************
@ -105,9 +105,9 @@ class EXIV2API BmffImage : public Image {
//! @name Accessors
//@{
std::string mimeType() const override /* override */;
uint32_t pixelWidth() const override;
uint32_t pixelHeight() const override;
[[nodiscard]] std::string mimeType() const override /* override */;
[[nodiscard]] uint32_t pixelWidth() const override;
[[nodiscard]] uint32_t pixelHeight() const override;
//@}
const Exiv2::ByteOrder endian_{Exiv2::bigEndian};
@ -123,7 +123,7 @@ class EXIV2API BmffImage : public Image {
@warning This function should only be called by readMetadata()
*/
long boxHandler(std::ostream& out, Exiv2::PrintStructureOption option, const long pbox_end, int depth);
std::string indent(int i) const {
[[nodiscard]] std::string indent(int i) const {
return std::string(2 * i, ' ');
}

View File

@ -70,7 +70,7 @@ class EXIV2API BmpImage : public Image {
//! @name Accessors
//@{
std::string mimeType() const override;
[[nodiscard]] std::string mimeType() const override;
//@}
}; // class BmpImage

View File

@ -66,9 +66,9 @@ class EXIV2API Cr2Image : public Image {
//! @name Accessors
//@{
std::string mimeType() const override;
uint32_t pixelWidth() const override;
uint32_t pixelHeight() const override;
[[nodiscard]] std::string mimeType() const override;
[[nodiscard]] uint32_t pixelWidth() const override;
[[nodiscard]] uint32_t pixelHeight() const override;
//@}
//! @name NOT implemented

View File

@ -68,9 +68,9 @@ class EXIV2API CrwImage : public Image {
//! @name Accessors
//@{
std::string mimeType() const override;
uint32_t pixelWidth() const override;
uint32_t pixelHeight() const override;
[[nodiscard]] std::string mimeType() const override;
[[nodiscard]] uint32_t pixelWidth() const override;
[[nodiscard]] uint32_t pixelHeight() const override;
//@}
//! @name NOT Implemented

View File

@ -272,21 +272,21 @@ class EXIV2API IptcKey : public Key {
//! @name Accessors
//@{
std::string key() const override;
const char* familyName() const override;
[[nodiscard]] std::string key() const override;
[[nodiscard]] const char* familyName() const override;
/*!
@brief Return the name of the group (the second part of the key).
For IPTC keys, the group name is the record name.
*/
std::string groupName() const override;
std::string tagName() const override;
std::string tagLabel() const override;
uint16_t tag() const override;
UniquePtr clone() const;
[[nodiscard]] std::string groupName() const override;
[[nodiscard]] std::string tagName() const override;
[[nodiscard]] std::string tagLabel() const override;
[[nodiscard]] uint16_t tag() const override;
[[nodiscard]] UniquePtr clone() const;
//! Return the name of the record
std::string recordName() const;
[[nodiscard]] std::string recordName() const;
//! Return the record id
uint16_t record() const;
[[nodiscard]] uint16_t record() const;
//@}
protected:
@ -309,7 +309,7 @@ class EXIV2API IptcKey : public Key {
private:
//! Internal virtual copy constructor.
IptcKey* clone_() const override;
[[nodiscard]] IptcKey* clone_() const override;
uint16_t tag_; //!< Tag value
uint16_t record_; //!< Record value

View File

@ -70,7 +70,7 @@ class EXIV2API EpsImage : public Image {
//! @name Accessors
//@{
std::string mimeType() const override;
[[nodiscard]] std::string mimeType() const override;
//@}
//! @name NOT Implemented

View File

@ -262,17 +262,17 @@ class EXIV2API Error : public std::exception {
}
//! Virtual destructor. (Needed because of throw())
virtual ~Error() noexcept;
~Error() noexcept override;
//@}
//! @name Accessors
//@{
ErrorCode code() const noexcept;
[[nodiscard]] ErrorCode code() const noexcept;
/*!
@brief Return the error message as a C-string. The pointer returned by what()
is valid only as long as the BasicError object exists.
*/
const char* what() const noexcept override;
[[nodiscard]] const char* what() const noexcept override;
//@}
private:

View File

@ -135,18 +135,18 @@ class EXIV2API Exifdatum : public Metadatum {
//! @name Accessors
//@{
//! Return the key of the %Exifdatum.
std::string key() const override;
const char* familyName() const override;
std::string groupName() const override;
std::string tagName() const override;
std::string tagLabel() const override;
uint16_t tag() const override;
[[nodiscard]] std::string key() const override;
[[nodiscard]] const char* familyName() const override;
[[nodiscard]] std::string groupName() const override;
[[nodiscard]] std::string tagName() const override;
[[nodiscard]] std::string tagLabel() const override;
[[nodiscard]] uint16_t tag() const override;
//! Return the IFD id as an integer. (Do not use, this is meant for library internal use.)
int ifdId() const;
[[nodiscard]] int ifdId() const;
//! Return the name of the IFD
const char* ifdName() const;
[[nodiscard]] const char* ifdName() const;
//! Return the index (unique id of this key within the original IFD)
int idx() const;
[[nodiscard]] int idx() const;
/*!
@brief Write value to a data buffer and return the number
of bytes written.
@ -161,25 +161,25 @@ class EXIV2API Exifdatum : public Metadatum {
size_t copy(byte* buf, ByteOrder byteOrder) const override;
std::ostream& write(std::ostream& os, const ExifData* pMetadata = nullptr) const override;
//! Return the type id of the value
TypeId typeId() const override;
[[nodiscard]] TypeId typeId() const override;
//! Return the name of the type
const char* typeName() const override;
[[nodiscard]] const char* typeName() const override;
//! Return the size in bytes of one component of this type
size_t typeSize() const override;
[[nodiscard]] size_t typeSize() const override;
//! Return the number of components in the value
size_t count() const override;
[[nodiscard]] size_t count() const override;
//! Return the size of the value in bytes
size_t size() const override;
[[nodiscard]] size_t size() const override;
//! Return the value as a string.
std::string toString() const override;
std::string toString(size_t n) const override;
int64_t toInt64(size_t n = 0) const override;
float toFloat(size_t n = 0) const override;
Rational toRational(size_t n = 0) const override;
Value::UniquePtr getValue() const override;
const Value& value() const override;
[[nodiscard]] std::string toString() const override;
[[nodiscard]] std::string toString(size_t n) const override;
[[nodiscard]] int64_t toInt64(size_t n = 0) const override;
[[nodiscard]] float toFloat(size_t n = 0) const override;
[[nodiscard]] Rational toRational(size_t n = 0) const override;
[[nodiscard]] Value::UniquePtr getValue() const override;
[[nodiscard]] const Value& value() const override;
//! Return the size of the data area.
size_t sizeDataArea() const;
[[nodiscard]] size_t sizeDataArea() const;
/*!
@brief Return a copy of the data area of the value. The caller owns
this copy and %DataBuf ensures that it will be deleted.
@ -192,7 +192,7 @@ class EXIV2API Exifdatum : public Metadatum {
%DataBuf if the value does not have a data area assigned or the
value is not set.
*/
DataBuf dataArea() const;
[[nodiscard]] DataBuf dataArea() const;
//@}
private:
@ -227,7 +227,7 @@ class EXIV2API ExifThumbC {
@brief Return the thumbnail image in a %DataBuf. The caller owns the
data buffer and %DataBuf ensures that it will be deleted.
*/
DataBuf copy() const;
[[nodiscard]] DataBuf copy() const;
/*!
@brief Write the thumbnail image to a file.
@ -238,17 +238,17 @@ class EXIV2API ExifThumbC {
@param path File name of the thumbnail without extension.
@return The number of bytes written.
*/
size_t writeFile(const std::string& path) const;
[[nodiscard]] size_t writeFile(const std::string& path) const;
/*!
@brief Return the MIME type of the thumbnail, either \c "image/tiff"
or \c "image/jpeg".
*/
const char* mimeType() const;
[[nodiscard]] const char* mimeType() const;
/*!
@brief Return the file extension for the format of the thumbnail
(".tif" or ".jpg").
*/
const char* extension() const;
[[nodiscard]] const char* extension() const;
//@}
private:
@ -442,24 +442,24 @@ class EXIV2API ExifData {
//! @name Accessors
//@{
//! Begin of the metadata
const_iterator begin() const {
[[nodiscard]] const_iterator begin() const {
return exifMetadata_.begin();
}
//! End of the metadata
const_iterator end() const {
[[nodiscard]] const_iterator end() const {
return exifMetadata_.end();
}
/*!
@brief Find the first Exifdatum with the given \em key, return a const
iterator to it.
*/
const_iterator findKey(const ExifKey& key) const;
[[nodiscard]] const_iterator findKey(const ExifKey& key) const;
//! Return true if there is no Exif metadata
bool empty() const {
[[nodiscard]] bool empty() const {
return exifMetadata_.empty();
}
//! Get the number of metadata entries
size_t count() const {
[[nodiscard]] size_t count() const {
return exifMetadata_.size();
}
//@}

View File

@ -73,7 +73,7 @@ class EXIV2API GifImage : public Image {
//! @name Accessors
//@{
std::string mimeType() const override;
[[nodiscard]] std::string mimeType() const override;
//@}
}; // class GifImage

View File

@ -206,7 +206,7 @@ class EXIV2API Image {
/*!
@brief return iccProfile
*/
virtual const DataBuf& iccProfile() const {
[[nodiscard]] virtual const DataBuf& iccProfile() const {
return iccProfile_;
}
@ -337,12 +337,12 @@ class EXIV2API Image {
@brief Return the byte order in which the Exif metadata of the image is
encoded. Initially, it is not set (\em invalidByteOrder).
*/
ByteOrder byteOrder() const;
[[nodiscard]] ByteOrder byteOrder() const;
/*! @brief Check if the Image instance is valid. Use after object construction.
@return true if the Image is in a valid state.
*/
bool good() const;
[[nodiscard]] bool good() const;
/*!
@brief Return the MIME type of the image.
@ -353,15 +353,15 @@ class EXIV2API Image {
and thus they all have MIME type "image/tiff", although a more
specific MIME type may exist (e.g., "image/x-nikon-nef").
*/
virtual std::string mimeType() const = 0;
[[nodiscard]] virtual std::string mimeType() const = 0;
/*!
@brief Return the pixel width of the image.
*/
virtual uint32_t pixelWidth() const;
[[nodiscard]] virtual uint32_t pixelWidth() const;
/*!
@brief Return the pixel height of the image.
*/
virtual uint32_t pixelHeight() const;
[[nodiscard]] virtual uint32_t pixelHeight() const;
/*!
@brief Returns an ExifData instance containing currently buffered
Exif data.
@ -373,7 +373,7 @@ class EXIV2API Image {
@return read only ExifData instance containing Exif values
*/
virtual const ExifData& exifData() const;
[[nodiscard]] virtual const ExifData& exifData() const;
/*!
@brief Returns an IptcData instance containing currently buffered
IPTC data.
@ -385,7 +385,7 @@ class EXIV2API Image {
@return modifiable IptcData instance containing IPTC values
*/
virtual const IptcData& iptcData() const;
[[nodiscard]] virtual const IptcData& iptcData() const;
/*!
@brief Returns an XmpData instance containing currently buffered
XMP data.
@ -397,15 +397,15 @@ class EXIV2API Image {
@return modifiable XmpData instance containing XMP values
*/
virtual const XmpData& xmpData() const;
[[nodiscard]] virtual const XmpData& xmpData() const;
/*!
@brief Return a copy of the image comment. May be an empty string.
*/
virtual std::string comment() const;
[[nodiscard]] virtual std::string comment() const;
/*!
@brief Return the raw XMP packet as a string.
*/
virtual const std::string& xmpPacket() const;
[[nodiscard]] virtual const std::string& xmpPacket() const;
/*!
@brief Return a reference to the BasicIo instance being used for Io.
@ -420,23 +420,23 @@ class EXIV2API Image {
Image class will not see those changes until the readMetadata()
method is called.
*/
virtual BasicIo& io() const;
[[nodiscard]] virtual BasicIo& io() const;
/*!
@brief Returns the access mode, i.e., the metadata functions, which
this image supports for the metadata type \em metadataId.
@param metadataId The metadata identifier.
@return Access mode for the requested image type and metadata identifier.
*/
AccessMode checkMode(MetadataId metadataId) const;
[[nodiscard]] AccessMode checkMode(MetadataId metadataId) const;
/*!
@brief Check if image supports a particular type of metadata.
This method is deprecated. Use checkMode() instead.
*/
bool supportsMetadata(MetadataId metadataId) const;
[[nodiscard]] bool supportsMetadata(MetadataId metadataId) const;
//! Return the flag indicating the source when writing XMP metadata.
bool writeXmpFromPacket() const;
[[nodiscard]] bool writeXmpFromPacket() const;
//! Return list of native previews. This is meant to be used only by the PreviewManager.
const NativePreviewList& nativePreviews() const;
[[nodiscard]] const NativePreviewList& nativePreviews() const;
//@}
//! set type support for this image format
@ -446,7 +446,7 @@ class EXIV2API Image {
}
//! set type support for this image format
ImageType imageType() const {
[[nodiscard]] ImageType imageType() const {
return imageType_;
}

View File

@ -94,39 +94,39 @@ class EXIV2API Iptcdatum : public Metadatum {
is not necessarily unique, i.e., an IptcData object may contain
multiple metadata with the same key.
*/
std::string key() const override;
[[nodiscard]] std::string key() const override;
/*!
@brief Return the name of the record (deprecated)
@return record name
*/
std::string recordName() const;
[[nodiscard]] std::string recordName() const;
/*!
@brief Return the record id
@return record id
*/
uint16_t record() const;
const char* familyName() const override;
std::string groupName() const override;
[[nodiscard]] uint16_t record() const;
[[nodiscard]] const char* familyName() const override;
[[nodiscard]] std::string groupName() const override;
/*!
@brief Return the name of the tag (aka dataset)
@return tag name
*/
std::string tagName() const override;
std::string tagLabel() const override;
[[nodiscard]] std::string tagName() const override;
[[nodiscard]] std::string tagLabel() const override;
//! Return the tag (aka dataset) number
uint16_t tag() const override;
TypeId typeId() const override;
const char* typeName() const override;
size_t typeSize() const override;
size_t count() const override;
size_t size() const override;
std::string toString() const override;
std::string toString(size_t n) const override;
int64_t toInt64(size_t n = 0) const override;
float toFloat(size_t n = 0) const override;
Rational toRational(size_t n = 0) const override;
Value::UniquePtr getValue() const override;
const Value& value() const override;
[[nodiscard]] uint16_t tag() const override;
[[nodiscard]] TypeId typeId() const override;
[[nodiscard]] const char* typeName() const override;
[[nodiscard]] size_t typeSize() const override;
[[nodiscard]] size_t count() const override;
[[nodiscard]] size_t size() const override;
[[nodiscard]] std::string toString() const override;
[[nodiscard]] std::string toString(size_t n) const override;
[[nodiscard]] int64_t toInt64(size_t n = 0) const override;
[[nodiscard]] float toFloat(size_t n = 0) const override;
[[nodiscard]] Rational toRational(size_t n = 0) const override;
[[nodiscard]] Value::UniquePtr getValue() const override;
[[nodiscard]] const Value& value() const override;
//@}
private:
@ -224,38 +224,38 @@ class EXIV2API IptcData {
//! @name Accessors
//@{
//! Begin of the metadata
const_iterator begin() const {
[[nodiscard]] const_iterator begin() const {
return iptcMetadata_.begin();
}
//! End of the metadata
const_iterator end() const {
[[nodiscard]] const_iterator end() const {
return iptcMetadata_.end();
}
/*!
@brief Find the first Iptcdatum with the given key, return a const
iterator to it.
*/
const_iterator findKey(const IptcKey& key) const;
[[nodiscard]] const_iterator findKey(const IptcKey& key) const;
/*!
@brief Find the first Iptcdatum with the given record and dataset
number, return a const iterator to it.
*/
const_iterator findId(uint16_t dataset, uint16_t record = IptcDataSets::application2) const;
[[nodiscard]] const_iterator findId(uint16_t dataset, uint16_t record = IptcDataSets::application2) const;
//! Return true if there is no IPTC metadata
bool empty() const {
[[nodiscard]] bool empty() const {
return count() == 0;
}
//! Get the number of metadata entries
size_t count() const {
[[nodiscard]] size_t count() const {
return iptcMetadata_.size();
}
//! @brief Return the exact size of all contained IPTC metadata
size_t size() const;
[[nodiscard]] size_t size() const;
//! @brief Return the metadata charset name or 0
const char* detectCharset() const;
[[nodiscard]] const char* detectCharset() const;
//! @brief dump iptc formatted binary data (used by printStructure kpsRecursive)
static void printStructure(std::ostream& out, const Slice<byte*>& bytes, uint32_t depth);

View File

@ -61,7 +61,7 @@ class EXIV2API Jp2Image : public Image {
//! @name Accessors
//@{
std::string mimeType() const override;
[[nodiscard]] std::string mimeType() const override;
//@}
//! @name NOT Implemented

View File

@ -241,7 +241,7 @@ class EXIV2API JpegBase : public Image {
@return the next Jpeg segment marker if successful;<BR>
throws an Error if not successful
*/
byte advanceToMarker(ErrorCode err) const;
[[nodiscard]] byte advanceToMarker(ErrorCode err) const;
//@}
DataBuf readNextSegment(byte marker);
@ -282,7 +282,7 @@ class EXIV2API JpegImage : public JpegBase {
//@}
//! @name Accessors
//@{
std::string mimeType() const override;
[[nodiscard]] std::string mimeType() const override;
//@}
// NOT Implemented
@ -343,7 +343,7 @@ class EXIV2API ExvImage : public JpegBase {
//@}
//! @name Accessors
//@{
std::string mimeType() const override;
[[nodiscard]] std::string mimeType() const override;
//@}
// NOT Implemented

View File

@ -254,28 +254,28 @@ class EXIV2API XmpKey : public Key {
//! @name Accessors
//@{
std::string key() const override;
const char* familyName() const override;
[[nodiscard]] std::string key() const override;
[[nodiscard]] const char* familyName() const override;
/*!
@brief Return the name of the group (the second part of the key).
For XMP keys, the group name is the schema prefix name.
*/
std::string groupName() const override;
std::string tagName() const override;
std::string tagLabel() const override;
[[nodiscard]] std::string groupName() const override;
[[nodiscard]] std::string tagName() const override;
[[nodiscard]] std::string tagLabel() const override;
//! Properties don't have a tag number. Return 0.
uint16_t tag() const override;
[[nodiscard]] uint16_t tag() const override;
UniquePtr clone() const;
[[nodiscard]] UniquePtr clone() const;
// Todo: Should this be removed? What about tagLabel then?
//! Return the schema namespace for the prefix of the key
std::string ns() const;
[[nodiscard]] std::string ns() const;
//@}
private:
//! Internal virtual copy constructor.
XmpKey* clone_() const override;
[[nodiscard]] XmpKey* clone_() const override;
// Pimpl idiom
struct Impl;

View File

@ -30,6 +30,8 @@ int main(int argc, char* const argv[]) try {
Exiv2::PreviewImage preview = loader.getPreviewImage(pos);
auto s = preview.writeFile(filename + "_" + Exiv2::toString(pos.width_) + "x" + Exiv2::toString(pos.height_));
if (s == 0)
return EXIT_FAILURE;
}
// Cleanup

View File

@ -149,6 +149,8 @@ void testCase(const std::string& file1, const std::string& file2, const std::str
std::cerr << "---> Writing Exif thumbnail to file " << thumb << ".*\n";
ExifThumbC et2(ed2);
auto s = et2.writeFile(thumb);
if (s == 0)
std::cerr << "---> Failed to write to file " << thumb << ".*\n";
}
// *****************************************************************************