1 #ifndef __iXMLMetadata_h__
2 #define __iXMLMetadata_h__ 1
3 
4 // =================================================================================================
5 // ADOBE SYSTEMS INCORPORATED
6 // Copyright 2014 Adobe Systems Incorporated
7 // All Rights Reserved
8 //
9 // NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the terms
10 // of the Adobe license agreement accompanying it.
11 // =================================================================================================
12 
13 #include "public/include/XMP_Environment.h"	// ! XMP_Environment.h must be the first included header.
14 #include "public/include/XMP_Const.h"
15 #include "public/include/XMP_IO.hpp"
16 
17 #include "XMPFiles/source/NativeMetadataSupport/IMetadata.h"
18 
19 class ExpatAdapter;
20 class XML_Node;
21 
22 namespace IFF_RIFF {
23 
24 	/**
25 	*	iXML Metadata model.
26 	*	Implements the IMetadata interface
27 	*/
28 	class iXMLMetadata : public IMetadata
29 	{
30 	public:
31 
32 		class TrackListInfo {
33 		public:
TrackListInfo()34 			TrackListInfo() : mChannelIndex( 0 ) {}
35 
TrackListInfo(XMP_Uns64 channelIndex,const std::string & name,const std::string & function)36 			TrackListInfo( XMP_Uns64 channelIndex, const std::string & name, const std::string & function )
37 				: mChannelIndex( channelIndex )
38 				, mName( name )
39 				, mFunction( function ) {}
40 
41 			bool operator == ( const TrackListInfo & other ) const {
42 				return mChannelIndex == other.mChannelIndex &&
43 					mName.compare( other.mName ) == 0 &&
44 					mFunction.compare( other.mFunction ) == 0;
45 			}
46 
47 			bool operator != ( const TrackListInfo & other ) const {
48 				return !( this->operator==( other ) );
49 			}
50 
51 			XMP_Uns64			mChannelIndex;
52 			std::string			mName;
53 			std::string			mFunction;
54 		};
55 
56 		enum
57 		{
58 			kTape,								// std::string
59 			kTake,								// std::string
60 			kScene,								// std::string
61 			kNote,								// std::string
62 			kProject,							// std::string
63 			kNoGood,							// bool( true/false )
64 			kFileSampleRate,					// XMP_Uns64
65 			kAudioBitDepth,						// XMP_Uns64
66 			kCircled,							// bool( true/false )
67 			kBWFDescription,					// std::string
68 			kBWFOriginator,						// std::string
69 			kBWFOriginatorReference,			// std::string
70 			kBWFOriginationDate,				// std::string
71 			kBWFOriginationTime,				// std::string
72 			kBWFTimeReferenceLow,				// XMP_Uns32
73 			kBWFTimeReferenceHigh,				// XMP_Uns32
74 			kBWFVersion,						// XMP_Uns16
75 			kBWFUMID,							// std::string[64]
76 			kBWFHistory,						// std::string
77 			kTimeCodeFlag,						// std::string[DF/NDF]
78 			kTimeCodeRate,						// std::string
79 			kTimeStampSampleRate,				// XMP_Uns64
80 			kTimeStampSampleSinceMidnightLow,	// XMP_Uns32
81 			kTimeStampSampleSinceMidnightHigh,	// XMP_Uns32
82 			kTrackList,							// std::vector< TrackListInfo >
83 			kLastEntry
84 		};
85 
86 	public:
87 		/**
88 		*ctor/dtor
89 		*/
90 		iXMLMetadata();
91 		~iXMLMetadata();
92 
93 		/**
94 		* Parses the given memory block and creates a data model representation
95 		* The implementation expects that the memory block is the data area of
96 		* the iXML chunk.
97 		* Throws exceptions if parsing is not possible
98 		*
99 		* @param input		The byte buffer to parse
100 		* @param size		Size of the given byte buffer
101 		*/
102 		void		parse( const XMP_Uns8* chunkData, XMP_Uns64 size );
103 
104 		/**
105 		* See IMetadata::parse( const LFA_FileRef input )
106 		*/
parse(XMP_IO * input)107 		void		parse( XMP_IO* input ) { IMetadata::parse( input ); }
108 
109 		/**
110 		* Serializes the data model to a memory block.
111 		* The memory block will be the data area of a iXML chunk.
112 		* Throws exceptions if serializing is not possible
113 		*
114 		* @param buffer	Buffer that gets filled with serialized data
115 		* @param size		Size of passed in buffer
116 		*
117 		* @return			Size of serialized data (might be smaller than buffer size)
118 		*/
119 		XMP_Uns64		serialize( XMP_Uns8** buffer );
120 
121 		void SetErrorCallback( GenericErrorCallback * errorCallback );
122 
SetExtraSpaceSize(size_t size)123 		void SetExtraSpaceSize( size_t size ) { mExtraSpaceSize = size; }
124 
GetExtraSpaceSize()125 		size_t GetExtraSpaceSize() const { return mExtraSpaceSize; }
126 
127 	protected:
128 		/**
129 		* @see IMetadata::isEmptyValue
130 		*/
131 		virtual	bool isEmptyValue( XMP_Uns32 id, ValueObject& valueObj );
132 
133 		/**
134 		 * @see iMetadata::valueValid
135 		 */
136 		virtual bool valueValid( XMP_Uns32 id, ValueObject * valueObj );
137 
138 		/**
139 		 * @see IMetadata::valueModify
140 		 */
141 		virtual void valueModify( XMP_Uns32 id, ValueObject * value );
142 
143 		void ParseAndSetProperties();
144 		void UpdateProperties();
145 
146 		std::string ParseStringValue( XML_Node * parentNode, XMP_Uns32 id );
147 		std::string ParseStringValue( XML_Node * parentNode, const char * tagName, bool recoverableError = true );
148 		XMP_Uns64 ParseUns64Value( XML_Node * parentNode, const char * tagName );
149 
150 		void ParseAndSetTrackListInfo( XML_Node * parentNode );
151 		void ParseAndSetStringProperty( XML_Node * parentNode, XMP_Uns32 id );
152 		void ParseAndSetIntegerProperty( XML_Node * parentNode, XMP_Uns32 id );
153 		void ParseAndSetBoolProperty( XML_Node * parentNode, XMP_Uns32 id );
154 
155 		void UpdateStringProperty( XML_Node * parentNode, XMP_Uns32 id );
156 		void UpdateIntegerProperty( XML_Node * parentNode, XMP_Uns32 id );
157 		void UpdateBoolProperty( XML_Node * parentNode, XMP_Uns32 id );
158 		void UpdateTrackListInfo( XML_Node * parentNode );
159 
160 		void UpdateXMLNode( XML_Node * parentNode, const char * localName, const std::string &  value );
161 		void RemoveXMLNode( XML_Node * parentNode, const char * localName );
162 
163 		void NotifyClient( XMP_ErrorSeverity severity, XMP_Error & error );
164 
165 		bool validateStringSize( ValueObject * value, size_t minSize = 1, size_t maxSize = std::string::npos );
166 		bool validateInt( ValueObject * value, XMP_Uns64 minValue = 0, XMP_Uns64 maxValue = Max_XMP_Uns64 );
167 		bool validateBool( ValueObject * value );
168 		void shortenString( ValueObject * value, size_t lengthOfString );
169 		bool validateDate( ValueObject * value );
170 		bool validateTime( ValueObject * value );
171 		bool validateUMID( ValueObject * value );
172 		bool validateTimeCodeFlag( ValueObject * value );
173 		bool validateRational( ValueObject * value );
174 		bool validateTrackListInfo( ValueObject * value );
175 	private:
176 		// Operators hidden on purpose
177 		iXMLMetadata( const iXMLMetadata& );
178 		iXMLMetadata& operator=( const iXMLMetadata& );
179 
180 		ExpatAdapter *			mExpatAdapter;
181 		XML_Node *				mRootNode;
182 		GenericErrorCallback *	mErrorCallback;
183 		size_t					mExtraSpaceSize;
184 	};
185 
186 }
187 
188 #endif  // __iXMLMetadata_h__
189