~ubuntu-branches/ubuntu/natty/libextractor/natty

« back to all changes in this revision

Viewing changes to src/plugins/exiv2/metadatum.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-11-17 20:27:32 UTC
  • mfrom: (1.10.4 upstream) (5.2.5 sid)
  • Revision ID: james.westby@ubuntu.com-20091117202732-ipm2h3gks5bdw2vx
Tags: 0.5.23+dfsg-3
* Building against libltdl7.
* Updating to standards version 3.8.3.
* Adding maintainer homepage field to control.
* Marking maintainer homepage field to be also included in binary
  packages and changelog.
* Adding README.source.
* Simplifying autotools handling in rules.
* Updating README.source.
* Moving maintainer homepage field from control to copyright.
* Dropping la files.
* Simplyfing debhelper install files.
* Bumping versioned build-depends on debhelper.
* Adding depends to dpkg install info.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// ***************************************************************** -*- C++ -*-
2
 
/*
3
 
 * Copyright (C) 2004, 2005 Andreas Huggel <ahuggel@gmx.net>
4
 
 *
5
 
 * This program is part of the Exiv2 distribution.
6
 
 *
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.
11
 
 *
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.
16
 
 *
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.
20
 
 */
21
 
/*!
22
 
  @file    metadatum.hpp
23
 
  @brief   Provides abstract base classes Metadatum and Key
24
 
  @version $Rev: 560 $
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
32
 
 */
33
 
#ifndef METADATUM_HPP_
34
 
#define METADATUM_HPP_
35
 
 
36
 
// *****************************************************************************
37
 
// included header files
38
 
#include "types.hpp"
39
 
#include "value.hpp"
40
 
 
41
 
// + standard includes
42
 
#include <string>
43
 
#include <memory>
44
 
 
45
 
// *****************************************************************************
46
 
// namespace extensions
47
 
namespace Exiv2 {
48
 
 
49
 
// *****************************************************************************
50
 
// class definitions
51
 
 
52
 
    /*!
53
 
      @brief Abstract base class defining the %Key of a metadatum.
54
 
             Keys are used to identify and group metadata.
55
 
    */
56
 
    class Key {
57
 
    public:
58
 
        //! Shortcut for a %Key auto pointer.
59
 
        typedef std::auto_ptr<Key> AutoPtr;
60
 
 
61
 
        //! @name Creators
62
 
        //@{
63
 
        //! Destructor
64
 
        virtual ~Key() {}
65
 
        //@}
66
 
 
67
 
        //! @name Accessors
68
 
        //@{
69
 
        /*!
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.
74
 
         */
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;
84
 
        /*!
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
87
 
                 will be deleted.
88
 
         */
89
 
        AutoPtr clone() const;
90
 
        /*!
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).
95
 
        */
96
 
        std::ostream& write(std::ostream& os) const { return os << key(); }
97
 
        //@}
98
 
 
99
 
    protected:
100
 
        //! @name Manipulators
101
 
        //@{
102
 
        /*!
103
 
          @brief Assignment operator. Protected so that it can only be used
104
 
                 by subclasses but not directly.
105
 
         */
106
 
        Key& operator=(const Key& rhs) { return *this; }
107
 
        //@}
108
 
 
109
 
    private:
110
 
        //! Internal virtual copy constructor.
111
 
        virtual Key* clone_() const =0;
112
 
 
113
 
    }; // class Key
114
 
 
115
 
    //! Output operator for Key types
116
 
    inline std::ostream& operator<<(std::ostream& os, const Key& key)
117
 
    {
118
 
        return key.write(os);
119
 
    }
120
 
 
121
 
    /*!
122
 
      @brief Abstract base class defining the interface to access information
123
 
             related to one metadata tag.
124
 
     */
125
 
    class Metadatum {
126
 
    public:
127
 
        //! @name Creators
128
 
        //@{
129
 
        //! Default Constructor
130
 
        Metadatum() {}
131
 
        //! Copy constructor
132
 
        Metadatum(const Metadatum& rhs) {}
133
 
        //! Destructor
134
 
        virtual ~Metadatum() {}
135
 
        //@}
136
 
 
137
 
        //! @name Manipulators
138
 
        //@{
139
 
        /*!
140
 
          @brief Set the value. This method copies (clones) the value pointed
141
 
                 to by pValue.
142
 
         */
143
 
        virtual void setValue(const Value* pValue) =0;
144
 
        /*!
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.
148
 
         */
149
 
        virtual void setValue(const std::string& buf) =0;
150
 
        //@}
151
 
 
152
 
        //! @name Accessors
153
 
        //@{
154
 
        /*!
155
 
          @brief Write value to a data buffer and return the number
156
 
                 of bytes written.
157
 
 
158
 
          The user must ensure that the buffer has enough memory. Otherwise
159
 
          the call results in undefined behaviour.
160
 
 
161
 
          @param buf Data buffer to write to.
162
 
          @param byteOrder Applicable byte order (little or big endian).
163
 
          @return Number of characters written.
164
 
        */
165
 
        virtual long copy(byte* buf, ByteOrder byteOrder) const =0;
166
 
        /*!
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.
171
 
         */
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;
175
 
        //! Return the tag
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;
189
 
        /*!
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
193
 
                 component.
194
 
         */
195
 
        virtual long toLong(long n =0) const =0;
196
 
        /*!
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
200
 
                 component.
201
 
         */
202
 
        virtual float toFloat(long n =0) const =0;
203
 
        /*!
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.
208
 
         */
209
 
        virtual Rational toRational(long n =0) const =0;
210
 
        /*!
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
213
 
                 be deleted.
214
 
 
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.
219
 
 
220
 
          @return An auto-pointer containing a pointer to a copy (clone) of the
221
 
                  value, 0 if the value is not set.
222
 
         */
223
 
        virtual Value::AutoPtr getValue() const =0;
224
 
        /*!
225
 
          @brief Return a constant reference to the value.
226
 
 
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
230
 
          this reference.
231
 
 
232
 
          <b>Example:</b> <br>
233
 
          @code
234
 
          ExifData::const_iterator i = exifData.findKey(key);
235
 
          if (i != exifData.end()) {
236
 
              std::cout << i->key() << " " << std::hex << i->value() << "\n";
237
 
          }
238
 
          @endcode
239
 
 
240
 
          @return A constant reference to the value.
241
 
          @throw Error if the value is not set.
242
 
         */
243
 
        virtual const Value& value() const =0;
244
 
        //@}
245
 
 
246
 
    protected:
247
 
        //! @name Manipulators
248
 
        //@{
249
 
        /*!
250
 
          @brief Assignment operator. Protected so that it can only be used
251
 
                 by subclasses but not directly.
252
 
         */
253
 
        Metadatum& operator=(const Metadatum& rhs) { return *this; }
254
 
        //@}
255
 
 
256
 
    }; // class Metadatum
257
 
 
258
 
    //! Unary predicate that matches a Exifdatum with a given key
259
 
    class FindMetadatumByKey {
260
 
    public:
261
 
        //! Constructor, initializes the object with the tag to look for
262
 
        FindMetadatumByKey(const std::string& key) : key_(key) {}
263
 
        /*!
264
 
          @brief Returns true if the key of the argument metadatum is equal
265
 
          to that of the object.
266
 
        */
267
 
        bool operator()(const Metadatum& metadatum) const
268
 
            { return key_ == metadatum.key(); }
269
 
 
270
 
    private:
271
 
        std::string key_;
272
 
 
273
 
    }; // class FindMetadatumByTag
274
 
 
275
 
 
276
 
    /*!
277
 
      @brief Output operator for Metadatum types, printing the interpreted
278
 
             tag value.
279
 
     */
280
 
    std::ostream& operator<<(std::ostream& os, const Metadatum& md);
281
 
    /*!
282
 
      @brief Compare two metadata by tag. Return true if the tag of metadatum
283
 
             lhs is less than that of rhs.
284
 
     */
285
 
    bool cmpMetadataByTag(const Metadatum& lhs, const Metadatum& rhs);
286
 
    /*!
287
 
      @brief Compare two metadata by key. Return true if the key of metadatum
288
 
             lhs is less than that of rhs.
289
 
     */
290
 
    bool cmpMetadataByKey(const Metadatum& lhs, const Metadatum& rhs);
291
 
 
292
 
}                                       // namespace Exiv2
293
 
 
294
 
#endif                                  // #ifndef METADATUM_HPP_