Exiv2
metadatum.hpp
1// ***************************************************************** -*- C++ -*-
2/*
3 * Copyright (C) 2004-2021 Exiv2 authors
4 * This program is part of the Exiv2 distribution.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
19 */
20#ifndef METADATUM_HPP_
21#define METADATUM_HPP_
22
23// *****************************************************************************
24#include "exiv2lib_export.h"
25
26// included header files
27#include "value.hpp"
28
29// *****************************************************************************
30// namespace extensions
31namespace Exiv2 {
32
33// *****************************************************************************
34// class declarations
35 class ExifData;
36
37// *****************************************************************************
38// class definitions
39
44 class EXIV2API Key {
45 public:
47 typedef std::unique_ptr<Key> UniquePtr;
48
50
51
52 virtual ~Key() = default;
54
56
57
63 virtual std::string key() const =0;
65 virtual const char* familyName() const =0;
67 virtual std::string groupName() const =0;
69 virtual std::string tagName() const =0;
71 virtual std::string tagLabel() const =0;
73 virtual uint16_t tag() const =0;
79 UniquePtr clone() const;
86 std::ostream& write(std::ostream& os) const { return os << key(); }
88
89 protected:
91
92
96 Key& operator=(const Key& rhs) = default;
98
99 private:
101 virtual Key* clone_() const =0;
102
103 }; // class Key
104
106 inline std::ostream& operator<<(std::ostream& os, const Key& key)
107 {
108 return key.write(os);
109 }
110
115 class EXIV2API Metadatum {
116 public:
118
119
120 Metadatum() = default;
122 Metadatum(const Metadatum& rhs) = default;
124 virtual ~Metadatum() = default;
126
128
129
133 virtual void setValue(const Value* pValue) =0;
140 virtual int setValue(const std::string& buf) =0;
142
144
145
150 std::string print(const ExifData* pMetadata = nullptr) const;
162 virtual long copy(byte* buf, ByteOrder byteOrder) const =0;
184 virtual std::ostream& write(std::ostream& os, const ExifData* pMetadata = nullptr) const = 0;
191 virtual std::string key() const =0;
193 virtual const char* familyName() const =0;
195 virtual std::string groupName() const =0;
197 virtual std::string tagName() const =0;
199 virtual std::string tagLabel() const =0;
201 virtual uint16_t tag() const =0;
203 virtual TypeId typeId() const =0;
205 virtual const char* typeName() const =0;
207 virtual long typeSize() const =0;
209 virtual long count() const =0;
211 virtual long size() const =0;
213 virtual std::string toString() const =0;
219 virtual std::string toString(long n) const =0;
225 virtual long toLong(long n =0) const =0;
231 virtual float toFloat(long n =0) const =0;
237 virtual Rational toRational(long n =0) const =0;
251 virtual Value::UniquePtr getValue() const =0;
265 virtual const Value& value() const =0;
267
268 protected:
270
271
275 Metadatum& operator=(const Metadatum& rhs) = default;
277
278 }; // class Metadatum
279
284 inline std::ostream& operator<<(std::ostream& os, const Metadatum& md)
285 {
286 return md.write(os);
287 }
288
293 EXIV2API bool cmpMetadataByTag(const Metadatum& lhs, const Metadatum& rhs);
298 EXIV2API bool cmpMetadataByKey(const Metadatum& lhs, const Metadatum& rhs);
299
300} // namespace Exiv2
301
302#endif // #ifndef METADATUM_HPP_
A container for Exif data. This is a top-level class of the Exiv2 library. The container holds Exifda...
Definition: exif.hpp:434
Abstract base class defining the Key of a metadatum. Keys are used to identify and group metadata.
Definition: metadatum.hpp:44
virtual std::string groupName() const =0
Return the name of the group (the second part of the key)
virtual std::string key() const =0
Return the key of the metadatum as a string. The key is of the form 'familyName.groupName....
virtual std::string tagLabel() const =0
Return a label for the tag.
std::ostream & write(std::ostream &os) const
Write the key to an output stream. You do not usually have to use this function; it is used for the i...
Definition: metadatum.hpp:86
Key & operator=(const Key &rhs)=default
Assignment operator. Protected so that it can only be used by subclasses but not directly.
virtual uint16_t tag() const =0
Return the tag number.
std::unique_ptr< Key > UniquePtr
Shortcut for a Key auto pointer.
Definition: metadatum.hpp:47
virtual ~Key()=default
Destructor.
virtual std::string tagName() const =0
Return the name of the tag (which is also the third part of the key)
virtual const char * familyName() const =0
Return an identifier for the type of metadata (the first part of the key)
Abstract base class defining the interface to access information related to one metadata tag.
Definition: metadatum.hpp:115
virtual long size() const =0
Return the size of the value in bytes.
Metadatum(const Metadatum &rhs)=default
Copy constructor.
virtual TypeId typeId() const =0
Return the type id of the value.
virtual ~Metadatum()=default
Destructor.
virtual long typeSize() const =0
Return the size in bytes of one component of this type.
virtual int setValue(const std::string &buf)=0
Set the value to the string buf. Uses Value::read(const std::string& buf). If the metadatum does not ...
virtual long copy(byte *buf, ByteOrder byteOrder) const =0
Write value to a data buffer and return the number of bytes written.
virtual std::string toString(long n) const =0
Return the n-th component of the value converted to a string. The behaviour of the method is undefine...
virtual std::ostream & write(std::ostream &os, const ExifData *pMetadata=nullptr) const =0
Write the interpreted value to an output stream, return the stream.
virtual uint16_t tag() const =0
Return the tag.
virtual Value::UniquePtr getValue() const =0
Return an auto-pointer to a copy (clone) of the value. The caller owns this copy and the auto-poiner ...
virtual const char * typeName() const =0
Return the name of the type.
virtual std::string tagLabel() const =0
Return a label for the tag.
virtual const char * familyName() const =0
Return the name of the metadata family (which is also the first part of the key)
virtual long toLong(long n=0) const =0
Return the n-th component of the value converted to long. The return value is -1 if the value is not ...
virtual const Value & value() const =0
Return a constant reference to the value.
virtual long count() const =0
Return the number of components in the value.
virtual std::string tagName() const =0
Return the name of the tag (which is also the third part of the key)
virtual std::string toString() const =0
Return the value as a string.
virtual std::string groupName() const =0
Return the name of the metadata group (which is also the second part of the key)
Metadatum()=default
Default Constructor.
virtual float toFloat(long n=0) const =0
Return the n-th component of the value converted to float. The return value is -1 if the value is not...
virtual Rational toRational(long n=0) const =0
Return the n-th component of the value converted to Rational. The return value is -1/1 if the value i...
Metadatum & operator=(const Metadatum &rhs)=default
Assignment operator. Protected so that it can only be used by subclasses but not directly.
virtual void setValue(const Value *pValue)=0
Set the value. This method copies (clones) the value pointed to by pValue.
virtual std::string key() const =0
Return the key of the metadatum. The key is of the form 'familyName.groupName.tagName'....
Common interface for all types of values used with metadata.
Definition: value.hpp:51
std::unique_ptr< Value > UniquePtr
Shortcut for a Value auto pointer.
Definition: value.hpp:54
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: basicio.hpp:43
EXIV2API std::ostream & operator<<(std::ostream &os, const DataSet &dataSet)
Output operator for dataSet.
Definition: datasets.cpp:677
EXIV2API bool cmpMetadataByTag(const Metadatum &lhs, const Metadatum &rhs)
Compare two metadata by tag. Return true if the tag of metadatum lhs is less than that of rhs.
Definition: metadatum.cpp:45
TypeId
Exiv2 value type identifiers.
Definition: types.hpp:100
ByteOrder
Type to express the byte order (little or big endian)
Definition: types.hpp:83
std::pair< int32_t, int32_t > Rational
8 byte signed rational type.
Definition: types.hpp:80
EXIV2API bool cmpMetadataByKey(const Metadatum &lhs, const Metadatum &rhs)
Compare two metadata by key. Return true if the key of metadatum lhs is less than that of rhs.
Definition: metadatum.cpp:51