1
// ***************************************************************** -*- C++ -*-
3
* Copyright (C) 2004, 2005 Andreas Huggel <ahuggel@gmx.net>
5
* This program is part of the Exiv2 distribution.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
@brief Provides abstract base classes Metadatum and Key
25
@author Andreas Huggel (ahu)
26
<a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a>
27
@author Brad Schick (brad)
28
<a href="mailto:brad@robotbattle.com">brad@robotbattle.com</a>
29
@date 09-Jan-04, ahu: created<BR>
30
31-Jul-04, brad: isolated as a component<BR>
31
23-Aug-04, ahu: added Key
33
#ifndef METADATUM_HPP_
34
#define METADATUM_HPP_
36
// *****************************************************************************
37
// included header files
41
// + standard includes
45
// *****************************************************************************
46
// namespace extensions
49
// *****************************************************************************
53
@brief Abstract base class defining the %Key of a metadatum.
54
Keys are used to identify and group metadata.
58
//! Shortcut for a %Key auto pointer.
59
typedef std::auto_ptr<Key> AutoPtr;
70
@brief Return the key of the metadatum as a string. The key is of the
71
form 'familyName.groupName.tagName'. Note however that the
72
key is not necessarily unique, e.g., an ExifData may contain
73
multiple metadata with the same key.
75
virtual std::string key() const =0;
76
//! Return an identifier for the type of metadata (the first part of the key)
77
virtual const char* familyName() const =0;
78
//! Return the name of the group (the second part of the key)
79
virtual std::string groupName() const =0;
80
//! Return the name of the tag (which is also the third part of the key)
81
virtual std::string tagName() const =0;
82
//! Return the tag number
83
virtual uint16_t tag() const =0;
85
@brief Return an auto-pointer to a copy of itself (deep copy).
86
The caller owns this copy and the auto-pointer ensures that it
89
AutoPtr clone() const;
91
@brief Write the key to an output stream. You do not usually have
92
to use this function; it is used for the implementation of
93
the output operator for %Key,
94
operator<<(std::ostream &os, const Key &key).
96
std::ostream& write(std::ostream& os) const { return os << key(); }
100
//! @name Manipulators
103
@brief Assignment operator. Protected so that it can only be used
104
by subclasses but not directly.
106
Key& operator=(const Key& rhs) { return *this; }
110
//! Internal virtual copy constructor.
111
virtual Key* clone_() const =0;
115
//! Output operator for Key types
116
inline std::ostream& operator<<(std::ostream& os, const Key& key)
118
return key.write(os);
122
@brief Abstract base class defining the interface to access information
123
related to one metadata tag.
129
//! Default Constructor
132
Metadatum(const Metadatum& rhs) {}
134
virtual ~Metadatum() {}
137
//! @name Manipulators
140
@brief Set the value. This method copies (clones) the value pointed
143
virtual void setValue(const Value* pValue) =0;
145
@brief Set the value to the string buf.
146
Uses Value::read(const std::string& buf). If the metadatum does
147
not have a value yet, then an AsciiValue is created.
149
virtual void setValue(const std::string& buf) =0;
155
@brief Write value to a data buffer and return the number
158
The user must ensure that the buffer has enough memory. Otherwise
159
the call results in undefined behaviour.
161
@param buf Data buffer to write to.
162
@param byteOrder Applicable byte order (little or big endian).
163
@return Number of characters written.
165
virtual long copy(byte* buf, ByteOrder byteOrder) const =0;
167
@brief Return the key of the metadatum. The key is of the form
168
'familyName.ifdItem.tagName'. Note however that the key
169
is not necessarily unique, i.e., an ExifData may contain
170
multiple metadata with the same key.
172
virtual std::string key() const =0;
173
//! Return the name of the tag (which is also the third part of the key)
174
virtual std::string tagName() const =0;
176
virtual uint16_t tag() const =0;
177
//! Return the type id of the value
178
virtual TypeId typeId() const =0;
179
//! Return the name of the type
180
virtual const char* typeName() const =0;
181
//! Return the size in bytes of one component of this type
182
virtual long typeSize() const =0;
183
//! Return the number of components in the value
184
virtual long count() const =0;
185
//! Return the size of the value in bytes
186
virtual long size() const =0;
187
//! Return the value as a string.
188
virtual std::string toString() const =0;
190
@brief Return the n-th component of the value converted to long. The
191
return value is -1 if the value of the Metadatum is not set and
192
the behaviour of the method is undefined if there is no n-th
195
virtual long toLong(long n =0) const =0;
197
@brief Return the n-th component of the value converted to float. The
198
return value is -1 if the value of the Metadatum is not set and
199
the behaviour of the method is undefined if there is no n-th
202
virtual float toFloat(long n =0) const =0;
204
@brief Return the n-th component of the value converted to
205
Rational. The return value is -1/1 if the value of the
206
Metadatum is not set and the behaviour of the method is
207
undefined if there is no n-th component.
209
virtual Rational toRational(long n =0) const =0;
211
@brief Return an auto-pointer to a copy (clone) of the value. The
212
caller owns this copy and the auto-poiner ensures that it will
215
This method is provided for users who need full control over the
216
value. A caller may, e.g., downcast the pointer to the appropriate
217
subclass of Value to make use of the interface of the subclass to set
218
or modify its contents.
220
@return An auto-pointer containing a pointer to a copy (clone) of the
221
value, 0 if the value is not set.
223
virtual Value::AutoPtr getValue() const =0;
225
@brief Return a constant reference to the value.
227
This method is provided mostly for convenient and versatile output of
228
the value which can (to some extent) be formatted through standard
229
stream manipulators. Do not attempt to write to the value through
234
ExifData::const_iterator i = exifData.findKey(key);
235
if (i != exifData.end()) {
236
std::cout << i->key() << " " << std::hex << i->value() << "\n";
240
@return A constant reference to the value.
241
@throw Error if the value is not set.
243
virtual const Value& value() const =0;
247
//! @name Manipulators
250
@brief Assignment operator. Protected so that it can only be used
251
by subclasses but not directly.
253
Metadatum& operator=(const Metadatum& rhs) { return *this; }
256
}; // class Metadatum
258
//! Unary predicate that matches a Exifdatum with a given key
259
class FindMetadatumByKey {
261
//! Constructor, initializes the object with the tag to look for
262
FindMetadatumByKey(const std::string& key) : key_(key) {}
264
@brief Returns true if the key of the argument metadatum is equal
265
to that of the object.
267
bool operator()(const Metadatum& metadatum) const
268
{ return key_ == metadatum.key(); }
273
}; // class FindMetadatumByTag
277
@brief Output operator for Metadatum types, printing the interpreted
280
std::ostream& operator<<(std::ostream& os, const Metadatum& md);
282
@brief Compare two metadata by tag. Return true if the tag of metadatum
283
lhs is less than that of rhs.
285
bool cmpMetadataByTag(const Metadatum& lhs, const Metadatum& rhs);
287
@brief Compare two metadata by key. Return true if the key of metadatum
288
lhs is less than that of rhs.
290
bool cmpMetadataByKey(const Metadatum& lhs, const Metadatum& rhs);
294
#endif // #ifndef METADATUM_HPP_