libopenraw  0.3.7
metadata.cpp
1 /*
2  * libopenraw - metadata.cpp
3  *
4  * Copyright (C) 2016-2020 Hubert Figuière
5  *
6  * This library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  *
11  * This library 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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <libopenraw/metadata.h>
22 
23 #include "capi.h"
24 #include "metavalue.hpp"
25 #include "metadata.hpp"
26 #include "ifddir.hpp"
27 
29 
30 extern "C" {
31 
33 #define CHECK_PTR(p, r) \
34  if (p == nullptr) { \
35  return r; \
36  }
37 
38 API_EXPORT const char*
40 {
41  CHECK_PTR(value, nullptr);
42  auto v = reinterpret_cast<const OpenRaw::MetaValue*>(value);
43  if (idx >= v->getCount()) {
44  return nullptr;
45  }
46  return v->getString(idx).c_str();
47 }
48 
49 API_EXPORT const char*
51 {
52  // TODO validate parameters
53  return reinterpret_cast<const OpenRaw::MetaValue*>(value)->getAsString(full).c_str();
54 }
55 
56 API_EXPORT uint32_t
58 {
59  CHECK_PTR(value, 0);
60  auto obj = reinterpret_cast<OpenRaw::MetaValue*>(value);
61  return obj->getCount();
62 }
63 
64 API_EXPORT void
66 {
67  if (!value) {
68  return;
69  }
70  auto obj = reinterpret_cast<OpenRaw::MetaValue*>(value);
71  delete obj;
72 }
73 
74 
75 API_EXPORT int
77 {
78  CHECK_PTR(iterator, 0);
79  auto iter = reinterpret_cast<OpenRaw::MetadataIterator*>(iterator);
80  if (iter && iter->next()) {
81 
82  return 1;
83  }
84  return 0;
85 }
86 
87 API_EXPORT int
89  ORIfdDirRef* ifd, uint16_t* id,
90  ExifTagType* type, ORMetaValueRef* value)
91 {
92  CHECK_PTR(iterator, 0);
93  auto iter = reinterpret_cast<OpenRaw::MetadataIterator*>(iterator);
94  if (ifd) {
95  auto t = iter->getIfd();
96  if (t) {
97  auto wrap = new WrappedPointer<IfdDir>(t);
98  *ifd = reinterpret_cast<ORIfdDirRef>(wrap);
99  } else {
100  return 0;
101  }
102  }
103  if (id) {
104  auto i = iter->getEntryId();
105  if (i) {
106  *id = *i;
107  } else {
108  return 0;
109  }
110  }
111  if (type) {
112  auto t = iter->getEntryType();
113  if (t) {
114  *type = *t;
115  } else {
116  return 0;
117  }
118  }
119  if (value) {
120  auto v = iter->getMetaValue();
121  if (v) {
122  *value = reinterpret_cast<ORMetaValueRef>(v);
123  } else {
124  *value = nullptr;
125  // This shouldn't be an error.
126  LOGDBG1("Couldn't get value\n");
127  }
128  }
129  return 1;
130 }
131 
132 API_EXPORT void
134 {
135  if (!iterator) {
136  return;
137  }
138  auto iter = reinterpret_cast<OpenRaw::MetadataIterator*>(iterator);
139  delete iter;
140 }
141 
142 }
An IFD directory.
Definition: ifddir.hpp:51
Metadata value.
Definition: metavalue.hpp:35
Iterator for the metadata.
Definition: metadata.hpp:34
Internals::IfdDir::Ref getIfd() const
Get the IFD for the current entry.
Definition: metadata.cpp:97
Wrap a pointer so that we can return it.
Definition: capi.h:14
const struct _MetaValue * ORConstMetaValueRef
A const metadata value.
Definition: metadata.h:47
API_EXPORT int or_metadata_iterator_get_entry(ORMetadataIteratorRef iterator, ORIfdDirRef *ifd, uint16_t *id, ExifTagType *type, ORMetaValueRef *value)
Get the metadata entry from the iterator.
Definition: metadata.cpp:88
API_EXPORT uint32_t or_metavalue_get_count(ORMetaValueRef value)
Get the value count.
Definition: metadata.cpp:57
struct _MetadataIterator * ORMetadataIteratorRef
A metadata iterator.
Definition: metadata.h:44
API_EXPORT void or_metadata_iterator_free(ORMetadataIteratorRef iterator)
Free the iterator.
Definition: metadata.cpp:133
API_EXPORT void or_metavalue_release(ORMetaValueRef value)
Free the MetaValue.
Definition: metadata.cpp:65
API_EXPORT const char * or_metavalue_get_string(ORConstMetaValueRef value, uint32_t idx)
Get the string out of the MetaValue.
Definition: metadata.cpp:39
API_EXPORT const char * or_metavalue_get_as_string(ORConstMetaValueRef value, bool full)
Convert the MetaValue to a string.
Definition: metadata.cpp:50
struct _MetaValue * ORMetaValueRef
A metadata value.
Definition: metadata.h:46
API_EXPORT int or_metadata_iterator_next(ORMetadataIteratorRef iterator)
Move to the next metadata value.
Definition: metadata.cpp:76
ExifTagType
Definition: exif.h:271
struct _IfdDir * ORIfdDirRef
IfdDir reference.
Definition: types.h:34