1 // =================================================================================================
2 // ADOBE SYSTEMS INCORPORATED
3 // Copyright 2010 Adobe Systems Incorporated
4 // All Rights Reserved
5 //
6 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms
7 // of the Adobe license agreement accompanying it.
8 // =================================================================================================
9
10 #include "XMPFiles/source/NativeMetadataSupport/IMetadata.h"
11
12 //-----------------------------------------------------------------------------
13 //
14 // IMetadata::IMetadata(...)
15 //
16 // Purpose: ctor/dtor
17 //
18 //-----------------------------------------------------------------------------
19
IMetadata()20 IMetadata::IMetadata()
21 : mDirty(false)
22 {
23 }
24
~IMetadata()25 IMetadata::~IMetadata()
26 {
27 for( ValueMap::iterator iter = mValues.begin(); iter != mValues.end(); iter++ )
28 {
29 delete iter->second;
30 }
31 }
32
33 //-----------------------------------------------------------------------------
34 //
35 // IMetadata::parse(...)
36 //
37 // Purpose: Parses the given memory block and creates a data model representation
38 // We assume that any metadata block is < 4GB so that we can savely use
39 // 32bit sizes.
40 // Throws exceptions if parsing is not possible
41 //
42 //-----------------------------------------------------------------------------
43
parse(const XMP_Uns8 *,XMP_Uns64)44 void IMetadata::parse( const XMP_Uns8* /*input*/, XMP_Uns64 /*size*/ )
45 {
46 XMP_Throw ( "Method not implemented", kXMPErr_Unimplemented );
47 }
48
49 //-----------------------------------------------------------------------------
50 //
51 // IMetadata::parse(...)
52 //
53 // Purpose: Parses the given file and creates a data model representation
54 // Throws exceptions if parsing is not possible
55 //
56 //-----------------------------------------------------------------------------
57
parse(XMP_IO *)58 void IMetadata::parse( XMP_IO* /*input*/ )
59 {
60 XMP_Throw ( "Method not implemented", kXMPErr_Unimplemented );
61 }
62
63 //-----------------------------------------------------------------------------
64 //
65 // IMetadata::serialize(...)
66 //
67 // Purpose: Serializes the data model to a memory block.
68 // The method creates a buffer and pass it to the parameter 'buffer'.
69 // The callee of the method is responsible to delete the buffer later on.
70 // We assume that any metadata block is < 4GB so that we can savely use
71 // 32bit sizes.
72 // Throws exceptions if serializing is not possible
73 //
74 //-----------------------------------------------------------------------------
75
serialize(XMP_Uns8 **)76 XMP_Uns64 IMetadata::serialize( XMP_Uns8** /*buffer*/ )
77 {
78 XMP_Throw ( "Method not implemented", kXMPErr_Unimplemented );
79 }
80
81 //-----------------------------------------------------------------------------
82 //
83 // IMetadata::hasChanged(...)
84 //
85 // Purpose: Return true if any values of this container was modified
86 //
87 //-----------------------------------------------------------------------------
88
hasChanged() const89 bool IMetadata::hasChanged() const
90 {
91 bool isDirty = mDirty;
92
93 for( ValueMap::const_iterator iter=mValues.begin(); ! isDirty && iter != mValues.end(); iter++ )
94 {
95 isDirty = iter->second->hasChanged();
96 }
97
98 return isDirty;
99 }
100
101 //-----------------------------------------------------------------------------
102 //
103 // IMetadata::resetChanges(...)
104 //
105 // Purpose: Reset dirty flag
106 //
107 //-----------------------------------------------------------------------------
108
resetChanges()109 void IMetadata::resetChanges()
110 {
111 mDirty = false;
112
113 for( ValueMap::iterator iter=mValues.begin(); iter != mValues.end(); iter++ )
114 {
115 iter->second->resetChanged();
116 }
117 }
118
119 //-----------------------------------------------------------------------------
120 //
121 // IMetadata::isEmpty(...)
122 //
123 // Purpose: Return true if the no metadata are available in this container
124 //
125 //-----------------------------------------------------------------------------
126
isEmpty() const127 bool IMetadata::isEmpty() const
128 {
129 return mValues.empty();
130 }
131
132 //-----------------------------------------------------------------------------
133 //
134 // IMetadata::deleteValue(...)
135 //
136 // Purpose: Remove value for passed identifier
137 //
138 //-----------------------------------------------------------------------------
139
deleteValue(XMP_Uns32 id)140 void IMetadata::deleteValue( XMP_Uns32 id )
141 {
142 ValueMap::iterator iterator = mValues.find( id );
143
144 if( iterator != mValues.end() )
145 {
146 delete iterator->second;
147 mValues.erase( iterator );
148
149 mDirty = true;
150 }
151 }
152
153 //-----------------------------------------------------------------------------
154 //
155 // IMetadata::deleteAll(...)
156 //
157 // Purpose: Remove all stored values
158 //
159 //-----------------------------------------------------------------------------
160
deleteAll()161 void IMetadata::deleteAll()
162 {
163 mDirty = ( mValues.size() > 0 );
164
165 for( ValueMap::iterator iter = mValues.begin(); iter != mValues.end(); iter++ )
166 {
167 delete iter->second;
168 }
169
170 mValues.clear();
171 }
172
173 //-----------------------------------------------------------------------------
174 //
175 // IMetadata::valueExists(...)
176 //
177 // Purpose: Return true if an value for the passed identifier exists
178 //
179 //-----------------------------------------------------------------------------
180
valueExists(XMP_Uns32 id) const181 bool IMetadata::valueExists( XMP_Uns32 id ) const
182 {
183 ValueMap::const_iterator iterator = mValues.find( id );
184
185 return ( iterator != mValues.end() );
186 }
187
188 //-----------------------------------------------------------------------------
189 //
190 // IMetadata::valueChanged(...)
191 //
192 // Purpose: Return true if the value for the passed identifier was changed
193 //
194 //-----------------------------------------------------------------------------
195
valueChanged(XMP_Uns32 id) const196 bool IMetadata::valueChanged( XMP_Uns32 id ) const
197 {
198 ValueMap::const_iterator iterator = mValues.find( id );
199
200 if( iterator != mValues.end() )
201 {
202 return iterator->second->hasChanged();
203 }
204
205 return false;
206 }
207
208 //-----------------------------------------------------------------------------
209 //
210 // IMetadata::valueValid(...)
211 //
212 // Purpose: Return true if the value for the passed identifier is valid
213 //
214 //-----------------------------------------------------------------------------
215
valueValid(XMP_Uns32,ValueObject *)216 bool IMetadata::valueValid( XMP_Uns32 /*id*/, ValueObject * /*value*/ )
217 {
218 return true;
219 }
220
221 //-----------------------------------------------------------------------------
222 //
223 // IMetadata::valueValid(...)
224 //
225 // Purpose: Return true if the value for the passed identifier is valid
226 //
227 //-----------------------------------------------------------------------------
valueModify(XMP_Uns32,ValueObject *)228 void IMetadata::valueModify(XMP_Uns32 /*id*/, ValueObject * /*value*/)
229 {
230 return;
231 }
232