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 #ifndef _ChunkPath_h_ 11 #define _ChunkPath_h_ 12 13 #include "public/include/XMP_Environment.h" // ! This must be the first include. 14 #include "public/include/XMP_Const.h" 15 16 #include <limits.h> // For UINT_MAX. 17 #include <vector> 18 19 namespace IFF_RIFF 20 { 21 22 /** 23 A ChunkPath describes one certain chunk in the hierarchy of chunks 24 of the IFF/RIFF file format. 25 Each chunks gets identified by a structure of the type ChunkIdentifier. 26 Which consists of the 4byte ID of the chunk and, if applicable, the 4byte 27 type of the chunk. 28 */ 29 30 // IFF/RIFF ids 31 enum { 32 // invalid ID 33 kChunk_NONE = UINT_MAX, 34 35 // format chunks 36 kChunk_RIFF = 0x52494646, 37 kChunk_RF64 = 0x52463634, 38 kChunk_FORM = 0x464F524D, 39 kChunk_JUNK = 0x4A554E4B, 40 kChunk_JUNQ = 0x4A554E51, 41 42 43 // other container chunks 44 kChunk_LIST = 0x4C495354, 45 46 // other relevant chunks 47 kChunk_XMP = 0x5F504D58, // "_PMX" 48 49 kChunk_data = 0x64617461, 50 51 //should occur only in AVI 52 kChunk_Cr8r = 0x43723872, 53 kChunk_PrmL = 0x50726D4C, 54 55 //should occur only in WAV 56 kChunk_DISP = 0x44495350, 57 kChunk_bext = 0x62657874, 58 kChunk_cart = 0x63617274, 59 kChunk_ds64 = 0x64733634, 60 kChunk_iXML = 0x69584D4C, 61 62 // AIFF 63 kChunk_APPL = 0x4150504C, 64 kChunk_NAME = 0x4E414D45, 65 kChunk_AUTH = 0x41555448, 66 kChunk_CPR = 0x28632920, 67 kChunk_ANNO = 0x414E4E4F 68 }; 69 70 // IFF/RIFF types 71 enum { 72 kType_AVI_ = 0x41564920, 73 kType_AVIX = 0x41564958, 74 kType_WAVE = 0x57415645, 75 kType_AIFF = 0x41494646, 76 kType_AIFC = 0x41494643, 77 kType_INFO = 0x494E464F, 78 kType_Tdat = 0x54646174, 79 80 // AIFF 81 kType_XMP = 0x584D5020, 82 kType_FREE = 0x46524545, 83 84 kType_NONE = UINT_MAX 85 }; 86 87 88 struct ChunkIdentifier 89 { 90 XMP_Uns32 id; 91 XMP_Uns32 type; 92 }; 93 94 /** 95 * calculates the size of a ChunkIdentifier array. 96 * Has to be a macro as the sizeof operator does nto work for pointer function parameters 97 */ 98 #define SizeOfCIArray(ciArray) ( sizeof(ciArray) / sizeof(ChunkIdentifier) ) 99 100 101 class ChunkPath 102 { 103 public: 104 /** 105 ctor/dtor 106 */ 107 ChunkPath( const ChunkIdentifier* path = NULL, XMP_Uns32 size = 0 ); 108 ChunkPath( const ChunkPath& path ); 109 ChunkPath( const ChunkIdentifier& identifier ); 110 ~ChunkPath(); 111 112 ChunkPath & operator=( const ChunkPath &rhs ); 113 114 /** 115 Append a ChunkIdentifier to the end of the path 116 117 @param id 4byte id of chunk 118 @param type 4byte type of chunk 119 */ 120 void append( XMP_Uns32 id, XMP_Uns32 type = kType_NONE ); 121 void append( const ChunkIdentifier& identifier ); 122 123 /** 124 Append a whole path 125 126 @param path Array of ChunkIdentifiert objects 127 @param size number of elements in the given array 128 */ 129 void append( const ChunkIdentifier* path = NULL, XMP_Uns32 size = 0 ); 130 131 /** 132 Insert an identifier 133 134 @param identifier id and type 135 @param pos position within the path 136 */ 137 void insert( const ChunkIdentifier& identifier, XMP_Uns32 pos = 0 ); 138 139 /** 140 Remove the endmost ChunkIdentifier from the path 141 */ 142 void remove(); 143 /** 144 Remove the ChunkIdentifier at the passed position in the path. 145 Throw exception if the position is out of range. 146 147 @param pos Position of ChunkIdentifier in the path 148 */ 149 void removeAt( XMP_Int32 pos ); 150 151 /** 152 Return ChunkIdentifier at the passed position 153 154 @param pos Position of ChunkIdentifier in the path 155 @return ChunkIdentifier at passed position (throw exception if 156 the position is out of range) 157 */ 158 const ChunkIdentifier& identifier( XMP_Int32 pos ) const; 159 160 /** 161 Return the number of ChunkIdentifier's in the path 162 */ 163 XMP_Int32 length() const; 164 165 /** 166 Remove all ChunkIdentifier's from the path 167 */ 168 void clear(); 169 170 /** 171 Compare the passed ChunkPath with this path. 172 173 @param path Path to compare with this path 174 @return Match result 175 */ 176 enum MatchResult 177 { 178 kNoMatch = 0, 179 kPartMatch = 1, 180 kFullMatch = 2 181 }; 182 183 MatchResult match( const ChunkPath& path ) const; 184 185 private: 186 std::vector<ChunkIdentifier> mPath; 187 }; 188 189 } 190 191 #endif 192