/*! Reads the contents of a field from the stream. It is intended to be used in conjunction with readFieldHeader and uses the information obtained by it (\a fieldName, \a fieldTypeName, \a fieldSize ). If a field is not to be read, but skipped instead, its name can be passed in the \a excludeFields argument. The string has the format: "'name1' 'name2' 'name3'", the spaces between the "'" are mandatory. \param[in] fieldName Name of the field. \param[in] fieldTypeName Type of the field. \param[in] fieldSize Size in bytes of the field. \param[in] excludeFields \param[out] ptrFieldIt Iterator that points to the PtrFieldInfo structure that was created, if this is a "pointer field" - only valid if true is returned. \return True, if the field is a "pointer field", i.e. a field holding pointers to other FieldContainers, false otherwise. */ bool OSBCommonElement::readFieldContent( const std::string &fieldName, const std::string &fieldTypeName, const UInt32 fieldSize, const std::string &excludeFields, PtrFieldListIt &ptrFieldIt ) { OSG_OSB_LOG(("OSBCommonElement::readFieldContent: [%s] [%s] [%u]\n", fieldName.c_str(), fieldTypeName.c_str(), fieldSize)); BinaryReadHandler *rh = editRoot()->getReadHandler(); bool isPtrField = false; FieldDescriptionBase *fieldDesc = getContainer()->getFieldDescription(fieldName.c_str()); if((!excludeFields.empty() ) && (excludeFields.find("'" + fieldName + "'") != std::string::npos) ) { OSG_OSB_LOG(("OSBCommonElement::readFieldContent: " "Skipping excluded field [%s] [%s]\n", fieldName.c_str(), fieldTypeName.c_str())); rh->skip(fieldSize); return false; } if(fieldDesc == 0) { DynFieldContainerInterface *pIf = dynamic_cast<DynFieldContainerInterface *>(getContainer()); if(pIf != NULL) { pIf->addField(fieldTypeName.c_str(), fieldName.c_str()); fieldDesc = getContainer()->getFieldDescription(fieldName.c_str()); } } if(fieldDesc == 0) { FWARNING(("OSBCommonElement::readFieldContent: " "Skipping unknown field [%s] [%s].\n", fieldName.c_str(), fieldTypeName.c_str())); rh->skip(fieldSize); return false; } const FieldType &fieldType = fieldDesc->getFieldType(); UInt32 fieldId = fieldDesc->getFieldId (); BitVector fieldMask = fieldDesc->getFieldMask(); if(fieldType.getContentType().isDerivedFrom( FieldTraits<FieldContainer *>::getMapType()) == true) { ptrFieldIt = readAttachmentMapField(fieldId, fieldSize); isPtrField = true; } else if(fieldType.getContentType().isDerivedFrom( FieldTraits<FieldContainer *>::getType()) == true) { if(fieldType.getClass() == FieldType::ParentPtrField) { rh->skip(fieldSize); isPtrField = false; } else { if(fieldType.getCardinality() == FieldType::SingleField) { ptrFieldIt = readPtrSingleField(fieldId); isPtrField = true; } else if(fieldType.getCardinality() == FieldType::MultiField) { ptrFieldIt = readPtrMultiField(fieldId, fieldSize); isPtrField = true; } } } else { getContainer()->copyFromBin(*rh, fieldMask); isPtrField = false; } return isPtrField; }
void OSGLoader::beginFieldDecl(const Char8 *szFieldType, const UInt32 uiFieldTypeId, const Char8 *szFieldName ) { UInt32 uiOSGFieldTypeId = mapIntExtFieldType(szFieldName, uiFieldTypeId); DynFieldContainerInterface *pIf = dynamic_cast<DynFieldContainerInterface *>(_pCurrentFC.get()); if(pIf != NULL) { GetFieldHandlePtr pField = _pCurrentFC->getField(szFieldName); if(pField == NULL || pField->isValid() == false) { if(uiFieldTypeId == 0) { pIf->addField(szFieldType, szFieldName); } else { pIf->addField(uiOSGFieldTypeId, szFieldName); } } _pCurrentField = _pCurrentFC->editField(szFieldName); _pCurrentFieldDesc = _pCurrentFC->getType().getFieldDesc(szFieldName); } else { AttachmentContainer *pAttCnt = dynamic_cast<AttachmentContainer *>(_pCurrentFC.get()); if(pAttCnt != NULL) { OSGGenericAttUnrecPtr pGenAtt = dynamic_cast<OSGGenericAtt *>( pAttCnt->findAttachment(OSGGenericAtt::getClassGroupId())); if(pGenAtt == NULL) { pGenAtt = OSGGenericAtt::create(); pAttCnt->addAttachment(pGenAtt); } GetFieldHandlePtr pField = pGenAtt->getField(szFieldName); if(pField == NULL || pField->isValid() == false) { if(uiFieldTypeId == 0) { // pGenAtt->addField(szFieldType, szFieldName); } else { pGenAtt->addField(uiOSGFieldTypeId, szFieldName); } } _pCurrentField = pGenAtt->editField(szFieldName); _pCurrentFieldDesc = pGenAtt->getType().getFieldDesc(szFieldName); } } _fStack.push (_pCurrentField); _fdStack.push(_pCurrentFieldDesc); }