bool AIFFMetadata::isEmptyValue( XMP_Uns32 id, ValueObject& valueObj )
{
	TValueObject<std::string>* strObj = dynamic_cast<TValueObject<std::string>*>(&valueObj);

	return ( strObj == NULL || ( strObj != NULL && strObj->getValue().empty() ) );
}
示例#2
0
XMP_Uns64 INFOMetadata::serialize( XMP_Uns8** outBuffer )
{
	XMP_Uns64 size = 0;

	if( outBuffer != NULL )
	{
		//
		// calculate required buffer size
		//
		for( ValueMap::iterator iter=mValues.begin(); iter!=mValues.end(); iter++ )
		{
			TValueObject<std::string>* strObj = dynamic_cast<TValueObject<std::string>*>(iter->second);

			XMP_Uns32 chunkSize = kChunkHeaderSize + strObj->getValue().length();

			if( chunkSize & 1 )
			{
				// take account of pad byte
				chunkSize++;
			}

			size += chunkSize;
		}
		
		size += kSizeChunkType; // add size of type "INFO"

		if( size > 0 )
		{
			XMP_Uns8* buffer = new XMP_Uns8[static_cast<size_t>(size)];		// output buffer

			memset( buffer, 0, static_cast<size_t>(size) );

			const BigEndian& BE		= BigEndian::getInstance();
			const LittleEndian& LE	= LittleEndian::getInstance();

			// Put type "INFO" in front of the buffer
			XMP_Uns32 typeInfo = BE.getUns32(&kType_INFO);
			memcpy( buffer, &typeInfo, kSizeChunkType );
			XMP_Uns64 offset = kSizeChunkType;						// pointer into the buffer

			//
			// for each stored value
			//
			for( ValueMap::iterator iter=mValues.begin(); iter!=mValues.end(); iter++ )
			{
				//
				// get: chunk data
				//		chunk id
				//		chunk size
				//
				TValueObject<std::string>* strObj = dynamic_cast<TValueObject<std::string>*>(iter->second);
				std::string value	= strObj->getValue();
				XMP_Uns32 id		= iter->first;
				XMP_Uns32 size		= value.length();

				if( size & 1 && strObj->hasChanged() )
				{
					//
					// if we modified the value of this entry
					// then fill chunk data with zero bytes
					// rather than use a pad byte, i.e.
					// size of each LIST:INFO entry has
					// an odd size
					//
					size++;
				}

				//
				// chunk id and chunk size are stored in little endian format
				//
				id		= BE.getUns32( &id );
				size	= LE.getUns32( &size );

				//
				// copy values into output buffer
				//
				memcpy( buffer+offset, &id, kSizeChunkID );
				memcpy( buffer+offset+kSizeChunkID, &size, kSizeChunkSize );
				//size has been changed in little endian format. Change it back to bigendina
				size	= LE.getUns32( &size );
				memcpy( buffer+offset+kChunkHeaderSize, value.c_str(), size );

				//
				// update pointer
				//
				offset += kChunkHeaderSize;
				offset += size;

				if( size & 1 )
				{
					//
					// take account of pad byte
					offset++;
				}
			}

			*outBuffer = buffer;
		}
	}
	else
	{
		XMP_Throw ( "Invalid buffer", kXMPErr_InternalFailure );
	}

	return size;
}