Exemplo n.º 1
0
void OSBChunkBlockElement::write(void)
{
    OSG_OSB_LOG(("OSBChunkBlockElement::write\n"));

    if(getContainer() == NULL)
    {
        FWARNING(("OSBChunkBlockElement::write: Attempt to write NULL.\n"));
        return;
    }

    BinaryWriteHandler *wh = editRoot()->getWriteHandler();

    wh->putValue(getFCPtrType(getContainer()));
    wh->putValue(getVersion()                );
 
    ChunkBlock *pCBlock = dynamic_cast<ChunkBlock *>(getContainer());

    if(pCBlock != NULL)
    {
        _mfSlots.clear();
        
        ChunkBlock::MFChunksType::const_iterator cIt  = 
            pCBlock->getMFChunks()->begin();
        ChunkBlock::MFChunksType::const_iterator cEnd = 
            pCBlock->getMFChunks()->end();
        
        UInt32 cIdx = 0;

        for(; cIt != cEnd; ++cIt, ++cIdx)
        {
            if(*cIt != NULL)
            {
                UInt32 uiId  = (*cIt)->getId();
                Int32  iSlot = cIdx - (*cIt)->getClassId();

                if(iSlot != -1)
                {
                    uiId |= iSlot << 24;
                }

                _mfSlots.push_back(uiId);
            }
        }

        writeFieldHeader("chunks", 
                         "MFUnrecStateChunkPtr", 
                         _mfSlots.size() * sizeof(UInt32));

        BinaryWriteHandler *wh = editRoot()->getWriteHandler();
        
        _mfSlots.copyToBin(*wh);
    }

    writeFields("'chunks'", true);
}
/*! Writes all fields to the stream, except for those whose name is in
    \a excludeFields. Optionally writes an end marker.

    The excludeFields string has the format: "'name1' 'name2' 'name3'",
    the spaces between the "'" are mandatory.

    \param[in] excludeFields String of field names that shall be skipped.
    \param[in] endMarker Write an end marker to the stream after all fields are
    processed.
 */
void
OSBCommonElement::writeFields(
    const std::string &excludeFields, const bool endMarker)
{
    OSG_OSB_LOG(("OSBCommonElement::writeFields: "
            "excludeFields: [%s]\n", excludeFields.c_str()));

    FieldContainer *fc         = getContainer();
    UInt32          fieldCount = fc->getType().getNumFieldDescs();

    // go through all fields and write them.
    for(UInt32 fieldId = 1; fieldId <= fieldCount; ++fieldId)
    {
        const FieldDescriptionBase *fieldDesc =
            fc->getFieldDescription(fieldId);
        const std::string          &fieldName = fieldDesc->getName();

        // skip internal fields
        if(fieldDesc->isInternal())
        {
            OSG_OSB_LOG(("OSBCommonElement::writeFields: "
                    "Skipping internal field: [%s]\n", fieldName.c_str()));
            continue;
        }

        // skip excluded fields
        if((!excludeFields.empty()                                        ) &&
           (excludeFields.find("'" + fieldName + "'") != std::string::npos)   )
        {
            OSG_OSB_LOG(("OSBCommonElement::writeFields: "
                    "Skipping excluded field: [%s]\n", fieldName.c_str()));
            continue;
        }

        const FieldType   &fieldType     = fieldDesc->getFieldType();
        const std::string &fieldTypeName = fieldType .getName     ();
        BitVector          fieldMask     = fieldDesc->getFieldMask();
        UInt32             fieldSize     = UInt32(fc->getBinSize(fieldMask));

        writeFieldHeader (fieldName, fieldTypeName, fieldSize);
        writeFieldContent(fieldId                            );
    }

    if(endMarker)
    {
        writeEndMarker();
    }
}