Exiv2
properties.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 PROPERTIES_HPP_
21#define PROPERTIES_HPP_
22
23// *****************************************************************************
24#include "exiv2lib_export.h"
25
26// included header files
27#include "datasets.hpp"
28#include <mutex>
29
30// *****************************************************************************
31// namespace extensions
32namespace Exiv2 {
33
34// *****************************************************************************
35// class declarations
36 class XmpKey;
37
38// *****************************************************************************
39// class definitions
40
42 enum XmpCategory { xmpInternal, xmpExternal };
43
45 struct EXIV2API XmpPropertyInfo {
47 bool operator==(const std::string& name) const;
48
49 const char* name_;
50 const char* title_;
51 const char* xmpValueType_;
54 const char* desc_;
55 };
56
58 struct EXIV2API XmpNsInfo {
60 struct Prefix {
62 explicit Prefix(std::string prefix);
64 std::string prefix_;
65 };
67 struct Ns {
69 explicit Ns(std::string ns);
71 std::string ns_;
72 };
74 bool operator==(const Ns& ns) const;
76 bool operator==(const Prefix& prefix) const;
77
78 const char* ns_;
79 const char* prefix_;
81 const char* desc_;
82 };
83
85 class EXIV2API XmpProperties {
89 XmpProperties(const XmpProperties& rhs);
91 XmpProperties& operator=(const XmpProperties& rhs);
92
93 private:
94 static const XmpNsInfo* nsInfoUnsafe(const std::string& prefix);
95 static void unregisterNsUnsafe(const std::string& ns);
96 static const XmpNsInfo* lookupNsRegistryUnsafe(const XmpNsInfo::Prefix& prefix);
97
98 public:
105 static const char* propertyTitle(const XmpKey& key);
112 static const char* propertyDesc(const XmpKey& key);
119 static TypeId propertyType(const XmpKey& key);
131 static const XmpPropertyInfo* propertyInfo(const XmpKey& key);
139 static std::string ns(const std::string& prefix);
147 static const char* nsDesc(const std::string& prefix);
155 static const XmpPropertyInfo* propertyList(const std::string& prefix);
163 static const XmpNsInfo* nsInfo(const std::string& prefix);
164
171 static std::string prefix(const std::string& ns);
173 static void printProperties(std::ostream& os, const std::string& prefix);
174
176 static std::ostream& printProperty(std::ostream& os,
177 const std::string& key,
178 const Value& value);
187 static void registerNs(const std::string& ns, const std::string& prefix);
196 static void unregisterNs(const std::string& ns);
197
206 static std::mutex mutex_;
207
216 static void unregisterNs();
218 typedef std::map<std::string, XmpNsInfo> NsRegistry;
222 static const XmpNsInfo* lookupNsRegistry(const XmpNsInfo::Prefix& prefix);
223
224 // DATA
226
231
232 }; // class XmpProperties
233
237 class EXIV2API XmpKey : public Key
238 {
239 public:
241 typedef std::unique_ptr<XmpKey> UniquePtr;
242
244
245
253 explicit XmpKey(const std::string& key);
263 XmpKey(const std::string& prefix, const std::string& property);
265 XmpKey(const XmpKey& rhs);
267 ~XmpKey() override;
269
271
272
273 XmpKey& operator=(const XmpKey& rhs);
275
277
278 std::string key() const override;
279 const char* familyName() const override;
284 std::string groupName() const override;
285 std::string tagName() const override;
286 std::string tagLabel() const override;
288 uint16_t tag() const override;
289
290 UniquePtr clone() const;
291
292 // Todo: Should this be removed? What about tagLabel then?
294 std::string ns() const;
296
297 private:
299 XmpKey* clone_() const override;
300
301 // Pimpl idiom
302 struct Impl;
303 std::unique_ptr<Impl> p_;
304
305 }; // class XmpKey
306
307 // *****************************************************************************
308 // free functions
309
311 EXIV2API std::ostream& operator<<(std::ostream& os, const XmpPropertyInfo& propertyInfo);
312
313} // namespace Exiv2
314
315#endif // #ifndef PROPERTIES_HPP_
Abstract base class defining the Key of a metadatum. Keys are used to identify and group metadata.
Definition: metadatum.hpp:44
std::unique_ptr< Key > UniquePtr
Shortcut for a Key auto pointer.
Definition: metadatum.hpp:47
Common interface for all types of values used with metadata.
Definition: value.hpp:51
Concrete keys for XMP metadata.
Definition: properties.hpp:238
std::string groupName() const override
Return the name of the group (the second part of the key). For XMP keys, the group name is the schema...
uint16_t tag() const override
Properties don't have a tag number. Return 0.
std::unique_ptr< XmpKey > UniquePtr
Shortcut for an XmpKey auto pointer.
Definition: properties.hpp:241
std::string tagName() const override
Return the name of the tag (which is also the third part of the key)
XmpKey(const XmpKey &rhs)
Copy constructor.
std::string key() const override
Return the key of the metadatum as a string. The key is of the form 'familyName.groupName....
std::string tagLabel() const override
Return a label for the tag.
std::string ns() const
Return the schema namespace for the prefix of the key.
XmpKey & operator=(const XmpKey &rhs)
Assignment operator.
const char * familyName() const override
Return an identifier for the type of metadata (the first part of the key)
XmpKey(const std::string &key)
Constructor to create an XMP key from a key string.
XmpKey(const std::string &prefix, const std::string &property)
Constructor to create an XMP key from a schema prefix and a property name.
~XmpKey() override
Virtual destructor.
XMP property reference, implemented as a static class.
Definition: properties.hpp:85
static const char * nsDesc(const std::string &prefix)
Return the namespace description for the schema associated with prefix.
static TypeId propertyType(const XmpKey &key)
Return the type for property key. The default for unknown keys is xmpText.
static const char * propertyDesc(const XmpKey &key)
Return the description of the property.
static std::mutex mutex_
Lock to be used while modifying properties.
Definition: properties.hpp:206
static NsRegistry nsRegistry_
Namespace registry.
Definition: properties.hpp:225
static const XmpNsInfo * lookupNsRegistry(const XmpNsInfo::Prefix &prefix)
Get the registered namespace for a specific prefix from the registry.
static void unregisterNs()
Unregister all custom namespaces.
static std::string ns(const std::string &prefix)
Return the namespace name for the schema associated with prefix.
static void unregisterNs(const std::string &ns)
Unregister a custom namespace ns.
static const XmpPropertyInfo * propertyInfo(const XmpKey &key)
Return information for the property for key.
static std::string prefix(const std::string &ns)
Return the (preferred) prefix for schema namespace ns.
static const XmpPropertyInfo * propertyList(const std::string &prefix)
Return read-only list of built-in properties for prefix.
static void printProperties(std::ostream &os, const std::string &prefix)
Print a list of properties of a schema namespace to output stream os.
static void registeredNamespaces(Exiv2::Dictionary &nsDict)
Get all registered namespaces (for both Exiv2 and XMPsdk)
static std::ostream & printProperty(std::ostream &os, const std::string &key, const Value &value)
Interpret and print the value of an XMP property.
static const char * propertyTitle(const XmpKey &key)
Return the title (label) of the property.
std::map< std::string, XmpNsInfo > NsRegistry
Type for the namespace registry.
Definition: properties.hpp:218
static void registerNs(const std::string &ns, const std::string &prefix)
Register namespace ns with preferred prefix prefix.
static const XmpNsInfo * nsInfo(const std::string &prefix)
Return information about a schema namespace for prefix. Always returns a valid pointer.
IPTC dataset and type information.
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
TypeId
Exiv2 value type identifiers.
Definition: types.hpp:100
XmpCategory
Category of an XMP property.
Definition: properties.hpp:42
std::map< std::string, std::string > Dictionary
typedef for string:string map
Definition: datasets.hpp:347
For comparison with namespace.
Definition: properties.hpp:67
std::string ns_
The namespace string.
Definition: properties.hpp:71
Ns(std::string ns)
Constructor.
For comparison with prefix.
Definition: properties.hpp:60
std::string prefix_
The prefix string.
Definition: properties.hpp:64
Prefix(std::string prefix)
Constructor.
Structure mapping XMP namespaces and (preferred) prefixes.
Definition: properties.hpp:58
const XmpPropertyInfo * xmpPropertyInfo_
List of known properties.
Definition: properties.hpp:80
bool operator==(const Prefix &prefix) const
Comparison operator for prefix.
const char * desc_
Brief description of the namespace.
Definition: properties.hpp:81
const char * prefix_
(Preferred) prefix
Definition: properties.hpp:79
const char * ns_
Namespace.
Definition: properties.hpp:78
bool operator==(const Ns &ns) const
Comparison operator for namespace.
Information about one XMP property.
Definition: properties.hpp:45
const char * name_
Property name.
Definition: properties.hpp:49
const char * desc_
Property description.
Definition: properties.hpp:54
const char * title_
Property title or label.
Definition: properties.hpp:50
bool operator==(const std::string &name) const
Comparison operator for name.
XmpCategory xmpCategory_
Category (internal or external)
Definition: properties.hpp:53
const char * xmpValueType_
XMP value type (for info only)
Definition: properties.hpp:51
TypeId typeId_
Exiv2 default type for the property.
Definition: properties.hpp:52