コード例 #1
0
void NFIOGenericAtt::writeFC(const FieldContainerPtr &/*fc*/)
{
    FDEBUG(("NFIOGenericAtt::witeFC\n"));

    // GenericAtt is not yet supported so just write a empty dummy out.
    _out->putValue(_version);

    writeEndMarker();
}
コード例 #2
0
/*! 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();
    }
}
コード例 #3
0
ファイル: OSGNFIOBase.cpp プロジェクト: mlimper/OpenSG1x
void NFIOBase::writeFCFields(const FieldContainerPtr &fc,
                             const std::string &exclude,
                             bool endMarker)
{
    FieldContainerType  &fcType = fc->getType();
    
    //go through all fields
    for(UInt32 i = 1; i <= fcType.getNumFieldDescs(); ++i)
    {
        FieldDescription    *fDesc = fcType.getFieldDescription(i);
        Field               *fieldPtr = fc->getField(i);
        const FieldType     &fType = fieldPtr->getType();
        BitVector           mask = fDesc->getFieldMask();

        if(!fDesc->isInternal())
        {
            // ignore node volume
            if(fcType == Node::getClassType() &&
               fDesc->getFieldMask() == Node::VolumeFieldMask)
            {
                continue;
            }

            // ignore parents field.
            if(!strcmp(fDesc->getCName(), "parents"))
            {
                continue;
            }

            FDEBUG(("NFIOBase::writeFCPtr: field: '%s' '%s'\n",
                    fDesc->getCName(), fType.getCName()));
            std::string fieldName = fDesc->getCName();
            std::string fieldType = fType.getCName();

            if(!exclude.empty() && exclude.find("'" + fieldName + "'") != std::string::npos)
            {
                FDEBUG(("NFIOBase::writeFields: skipping field: '%s'.\n",
                        fieldName.c_str()));
                continue;
            }
            
            if(strstr(fType.getCName(), "Ptr") != NULL)
            {
                if(fieldPtr->getCardinality() == FieldType::SINGLE_FIELD)
                {
                    _out->putValue(fieldName);
                    _out->putValue(fieldType);
                    _out->putValue(fc->getBinSize(mask));
                    writeSFFieldContainerPtr(static_cast<SFFieldContainerPtr *>(fieldPtr));
                }
                else if(fieldPtr->getCardinality() == FieldType::MULTI_FIELD)
                {
                    MFFieldContainerPtr *mfield = static_cast<MFFieldContainerPtr *>(fieldPtr);
                    if(!mfield->empty())
                    {
                        UInt32 size = sizeof(UInt32) + sizeof(UInt32) * mfield->size();
                        _out->putValue(fieldName);
                        _out->putValue(fieldType);
                        _out->putValue(size);
                        
                        writeMFFieldContainerPtr(mfield);
                    }
                }
                
            }
            else if(!strcmp(fDesc->getCName(), "attachments"))
            {
                SFAttachmentMap *amap = static_cast<SFAttachmentMap *>(fieldPtr);
                
                if(!amap->getValue().empty())
                {
                    // number of attachments
                    UInt32 size = sizeof(UInt32);
                    UInt32 noe  = 0;

                    // check for non zero bindings
                    AttachmentMap::const_iterator mapIt  = amap->getValue().begin();
                    AttachmentMap::const_iterator mapEnd = amap->getValue().end();

                    bool hasBinding = false;

                    for(; mapIt != mapEnd; ++mapIt)
                    {
                        if((mapIt->first &  0x0000ffff) != 0)
                            hasBinding = true;

                        // skip internal attachments
                        if(mapIt->second                              != NullFC &&
                           mapIt->second->getSFInternal()->getValue() == true     )
                        {
                            continue;
                        }

                        // count attachments that get written
                        ++noe;
                    }

                    if(hasBinding == true)
                    {
                        // for each attachment write id and binding
                        size += noe * (sizeof(UInt32) + sizeof(UInt16));
                    }
                    else
                    {
                        // for each attachment write id
                        size += noe * sizeof(UInt32);
                    }

                    _out->putValue(fieldName);
                    _out->putValue(fieldType);
                    _out->putValue(size);
                    writeSFAttachmentMap(amap, noe, hasBinding);
                }
            }
            else
            {
                _out->putValue(fieldName);
                _out->putValue(fieldType);
                _out->putValue(fc->getBinSize(mask));
                fc->copyToBin(*_out, mask);
            }
            
        }
    }
    
    if(endMarker)
    {
        // write fieldcontainer end marker
        writeEndMarker();
    }
}
コード例 #4
0
ファイル: OSGNFIOBase.cpp プロジェクト: mlimper/OpenSG1x
void NFIOBase::writeFieldContainer(const FieldContainerPtr &fc)
{
    FDEBUG(("NFIOBase::writeFieldContainer\n"));
    
    if(fc == NullFC)
        return;

    SceneFileHandler::the().updateWriteProgress(0);

    // need this for the progress calculation.
    UInt32 fcCount = 0;
    UInt32 currentFCCount = 0;
    if(SceneFileHandler::the().getWriteProgressCB() != NULL)
    {
        _fcSet.clear();
        getFCCount(fc, fcCount);
    }

    if(fcCount == 0)
        fcCount = 1;

    _fcList.clear();
    _fcSet.clear();
    
    // write header
    _out->putValue(std::string(OSGNFIOHEADERID));
    _out->putValue(std::string(""));
    _out->putValue(std::string(""));
    _out->putValue(UInt64(0));
    
    std::string typeName = fc->getType().getCName();
    
    _out->putValue(typeName);
    _out->putValue(getContainerId(fc));

    // add the root fc id here! without this writing a scene with
    // a root node referencing itself in its own attachment would fail!
    _fcSet.insert(getContainerId(fc));

    NFIOFactory::the().get(typeName)->writeFC(fc);
    SceneFileHandler::the().updateWriteProgress((currentFCCount++ * 100) / fcCount);

    FDEBUG(("NFIOBase::writeFC: writing fclist\n"));

    FieldContainerPtr lfc;
    for(std::list<FieldContainerPtr>::iterator i = _fcList.begin();
        i != _fcList.end(); ++i)
    {
        lfc = *i;
        typeName = lfc->getType().getCName();
        _out->putValue(typeName);
        _out->putValue(getContainerId(lfc));
        NFIOFactory::the().get(lfc->getType().getCName())->writeFC(lfc);
        SceneFileHandler::the().updateWriteProgress((currentFCCount++ * 100) / fcCount);
    }
    
    // write eof marker
    writeEndMarker();

    _fcList.clear();
    _fcSet.clear();

    SceneFileHandler::the().updateWriteProgress(100);
}