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 _AIFFBEHAVIOR_h_ 11 #define _AIFFBEHAVIOR_h_ 12 13 #include "public/include/XMP_Environment.h" // ! XMP_Environment.h must be the first included header. 14 15 #include "public/include/XMP_Const.h" 16 #include "public/include/XMP_IO.hpp" 17 18 #include "XMPFiles/source/XMPFiles_Impl.hpp" 19 #include "source/XMPFiles_IO.hpp" 20 21 #include "XMPFiles/source/FormatSupport/IFF/IChunkBehavior.h" 22 #include "XMPFiles/source/FormatSupport/IFF/ChunkPath.h" 23 #include "source/Endian.h" 24 25 namespace IFF_RIFF 26 { 27 28 /** 29 AIFF behavior class. 30 31 Implements the IChunkBehavior interface 32 */ 33 34 35 class AIFFBehavior : public IChunkBehavior 36 { 37 public: 38 /** 39 ctor/dtor 40 */ AIFFBehavior()41 AIFFBehavior() : mChunksAdded(0) {} ~AIFFBehavior()42 ~AIFFBehavior() {} 43 44 /** 45 Validate the passed in size value, identify the valid size if the passed in isn't valid 46 and return the valid size. 47 throw an exception if the passed in size isn't valid and there's no way to identify a 48 valid size. 49 50 @param size Size value 51 @param id Identifier of chunk 52 @param tree Chunk tree 53 @param stream Stream handle 54 55 @return Valid size value. 56 */ 57 XMP_Uns64 getRealSize( const XMP_Uns64 size, const ChunkIdentifier& id, IChunkContainer& tree, XMP_IO* stream ); 58 59 /** 60 Return the maximum size of a single chunk, i.e. the maximum size of a top-level chunk. 61 62 @return Maximum size 63 */ 64 XMP_Uns64 getMaxChunkSize() const; 65 66 /** 67 Return true if the passed identifier is valid for top-level chunks of a certain format. 68 69 @param id Chunk identifier 70 @param chunkNo order number of top-level chunk 71 @return true, if passed id is a valid top-level chunk 72 */ 73 bool isValidTopLevelChunk( const ChunkIdentifier& id, XMP_Uns32 chunkNo ); 74 75 /** 76 Fix the hierarchy of chunks depending ones based on size changes of one or more chunks 77 and second based on format specific rules. 78 Throw an exception if the hierarchy can't be fixed. 79 80 @param tree Vector of root chunks. 81 */ 82 void fixHierarchy( IChunkContainer& tree ); 83 84 /** 85 Insert a new chunk into the hierarchy of chunks. The behavior needs to decide the position 86 of the new chunk and has to do the insertion. 87 88 @param tree Chunk tree 89 @param chunk New chunk 90 */ 91 void insertChunk( IChunkContainer& tree, Chunk& chunk ) ; 92 93 /** 94 Remove the chunk described by the passed ChunkPath. 95 96 @param tree Chunk tree 97 @param path Path to the chunk that needs to be removed 98 99 @return true if the chunk was removed and need to be deleted 100 */ 101 bool removeChunk( IChunkContainer& tree, Chunk& chunk ) ; 102 103 private: 104 105 106 /** 107 Create a FREE chunk. 108 If the chunkSize is smaller than the header+type - size then create an annotation chunk. 109 If the passed size is odd, then add a pad byte. 110 111 @param chunkSize Total size including header 112 @return New FREE chunk 113 */ 114 Chunk* createFREE( XMP_Uns64 chunkSize ); 115 116 /** 117 Check if the passed chunk is a FREE chunk. 118 (Could be also a small annotation chunk with zero bytes in its data) 119 120 @param chunk A chunk 121 122 @return true if the passed chunk is a FREE chunk 123 */ 124 XMP_Bool isFREEChunk( const Chunk& chunk ) const; 125 126 /** 127 Retrieve the free space at the passed position in the child list of the parent tree. 128 If there's a FREE chunk then return it. 129 130 @param outFreeBytes On return it takes the number of free bytes 131 @param tree Parent tree 132 @param index Position in the child list of the parent tree 133 134 @return FREE chunk if available 135 */ 136 Chunk* getFreeSpace( XMP_Int64& outFreeBytes, const IChunkContainer& tree, XMP_Uns32 index ) const; 137 138 /** 139 Return the minimum size of a FREE chunk 140 */ 141 XMP_Uns64 getMinFREESize( ) const; 142 143 private: 144 XMP_Uns32 mChunksAdded; 145 146 /** AIFF is always Big Endian */ 147 static const BigEndian& mEndian; 148 149 }; // IFF_RIFF 150 151 } 152 #endif 153