// @mfunc Attempt to write the number of elements given by // <p elementCount> and described by <p elementType> and // <p internalElementSize> to the data stream from the buffer // at address <p elements>. The actual number of elements written // is returned in <p elementsWritten>. // @parm The element type // @parm The internal element size // @parm The address of the buffer from which the elements should // be written. // @parm The number of elements to write. // @parm The actual number of elements that were written. void OMDataStreamProperty::writeTypedElements(const OMType* elementType, OMUInt32 internalElementSize, const OMByte* elements, OMUInt32 elementCount, OMUInt32& elementsWritten) { TRACE("OMDataStreamProperty::writeTypedElements"); PRECONDITION("Valid element type", elementType != 0); PRECONDITION("Valid element size", internalElementSize!= 0); PRECONDITION("Valid buffer", elements != 0); PRECONDITION("Valid element count", elementCount > 0); PRECONDITION("Stream byte order is known", hasByteOrder()); bool reorder = false; if (byteOrder() != hostByteOrder()) { reorder = true; } // Allocate buffer for one element OMUInt32 externalBytesSize = elementType->externalSize( const_cast<OMByte*>(elements), internalElementSize); OMByte* buffer = new OMByte[externalBytesSize]; for (OMUInt32 i = 0; i < elementCount; i++) { // Externalize an element of the property value elementType->externalize( const_cast<OMByte*>(&elements[i * internalElementSize]), internalElementSize, buffer, externalBytesSize, hostByteOrder()); // Reorder an element of the property value if (reorder) { elementType->reorder(buffer, externalBytesSize); } // Write an element of the property value OMUInt32 actualByteCount; write(buffer, externalBytesSize, actualByteCount); ASSERT("All bytes written", actualByteCount == externalBytesSize); } delete [] buffer; elementsWritten = elementCount; setPresent(); }
// @mfunc Get the value of this <c OMWeakObjectReference>. // The value is a pointer to the referenced <c OMStorable>. // @rdesc A pointer to the referenced <c OMStorable>. // @this const OMStorable* OMWeakObjectReference::getValue(void) const { TRACE("OMWeakObjectReference::getValue"); OMWeakObjectReference* nonConstThis = const_cast<OMWeakObjectReference*>(this); if ((_pointer == 0) && (!isNullIdentification(_identification, _identificationSize))) { OMStorable* object = 0; set()->find(_identification, object); nonConstThis->_pointer = object; } #if 1 // HACK4MEIP2 if ((_pointer == 0) && (!isNullIdentification(_identification, _identificationSize))) { // We failed to resolve the reference as an object id, try again as a label // We should only come here for KLV encoded files. ASSERT("Referenced object ID can be a label", _identificationSize == sizeof(OMUniqueObjectIdentification)); OMUniqueObjectIdentification bid; memcpy(&bid, _identification, sizeof(OMUniqueObjectIdentification)); if (hostByteOrder() != bigEndian) { OMUniqueObjectIdentificationType::instance()->reorder( reinterpret_cast<OMByte*>(&bid), sizeof(bid)); } OMKLVKey k; memcpy(&k, &bid, sizeof(OMKLVKey)); OMUniqueObjectIdentification id; convert(id, k); memcpy(_identification, &id, sizeof(OMUniqueObjectIdentification)); OMStorable* object = 0; set()->find(_identification, object); nonConstThis->_pointer = object; } #endif // If the following assertion is violated we have a dangling weak // reference. The reference illegally designates an object that is // not present in the target set. Code elsewhere prevents the // removal of objects that are weakly referenced hence a dangling // reference is an assertion violation rather than a run-time error. // POSTCONDITION("Object found", IMPLIES(!isNullIdentification(_identification, _identificationSize), _pointer != 0)); return _pointer; }
// @mfunc Attempt to read the number of elements given by // <p elementCount> and described by <p elementType> and // <p externalElementSize> from the data stream into the buffer // at address <p elements>. The actual number of elements read // is returned in <p elementsRead>. // @parm The element type // @parm The external element size // @parm The address of the buffer into which the elements should be read. // @parm The number of elements to read. // @parm The actual number of elements that were read. // @this const void OMDataStreamProperty::readTypedElements(const OMType* elementType, OMUInt32 externalElementSize, OMByte* elements, OMUInt32 elementCount, OMUInt32& elementsRead) const { TRACE("OMDataStreamProperty::readTypedElements"); PRECONDITION("Optional property is present", IMPLIES(isOptional(), isPresent())); PRECONDITION("Valid element type", elementType != 0); PRECONDITION("Valid element size", externalElementSize!= 0); PRECONDITION("Valid buffer", elements != 0); PRECONDITION("Valid element count", elementCount > 0); PRECONDITION("Stream byte order is known", hasByteOrder()); OMUInt64 currentPosition = position(); OMUInt64 streamSize = size(); OMUInt32 readCount = 0; if (currentPosition < streamSize) { OMUInt64 remaining = (streamSize - currentPosition) / externalElementSize; if (remaining < elementCount) { readCount = static_cast<OMUInt32>(remaining); } else { readCount = elementCount; } } if (readCount > 0) { bool reorder = false; if (byteOrder() != hostByteOrder()) { reorder = true; } // Allocate buffer for one element OMByte* buffer = new OMByte[externalElementSize]; for (OMUInt32 i = 0; i < readCount; i++) { // Read an element of the property value OMUInt32 actualByteCount; read(buffer, externalElementSize, actualByteCount); ASSERT("All bytes read", actualByteCount == externalElementSize); // Reorder an element of the property value if (reorder) { elementType->reorder(buffer, externalElementSize); } // Internalize an element of the property value OMUInt32 requiredBytesSize = elementType->internalSize( buffer, externalElementSize); elementType->internalize(buffer, externalElementSize, &elements[i * requiredBytesSize], requiredBytesSize, hostByteOrder()); } delete [] buffer; } elementsRead = readCount; }