/*! Visits a SFFieldContainerPtr (or more specific pointer type) during
    preWrite. It creates an element for the pointed to container and
    calls preWrite on it. If the pointed to container is not in the
    root's id set it is added and thus scheduled for writing.

    \param[in] fieldId Id of the field in the container of this element.
 */
void
OSBCommonElement::preWritePtrSingleField(const UInt32 fieldId)
{
    OSG_OSB_LOG(("OSBCommonElement::preWritePtrSingleField: "
            "fieldId: [%u]\n", fieldId));

    OSBRootElement     *root       = editRoot();

    FieldContainerPtrSFieldBase::GetHandlePtr sfPtrField =
        boost::dynamic_pointer_cast<FieldContainerPtrSFieldBase::GetHandle>(
            getContainer()->getField(fieldId));

    if(sfPtrField == NULL || sfPtrField->isValid() == false)
        return;

    FieldContainer *refedFC = (*sfPtrField)->getValue();

    if(refedFC == NULL)
        return;

    UInt32             refedId  = refedFC->getId  ();
    const std::string &typeName = refedFC->getType().getName();

    // only schedule a container once
    if(root->getIdSet().count(refedId) == 0)
    {
        OSBElementBase *elem = OSBElementFactory::the()->acquire(
            typeName, root);

        root->editIdSet      ().insert   (refedId);
        root->editElementList().push_back(elem   );
        elem->setContainer(refedFC);
        elem->preWrite    (refedFC);
    }
}
Exemplo n.º 2
0
/*       FieldContainerTransitPtr.                                     */
const FieldContainerRecPtr PyFieldAccessHandler::getPtrSField(const std::string& fieldName)
{
    GetFieldHandlePtr handle = _pPythonScript->getDynamicFieldByName(fieldName.c_str());

    FieldContainerPtrSFieldBase::GetHandlePtr sfFCPtr =
        boost::dynamic_pointer_cast<
            FieldContainerPtrSFieldBase::GetHandle>(handle);
    assert(sfFCPtr);

    const FieldContainerPtrSFieldBase* field =
            static_cast<const FieldContainerPtrSFieldBase *>(sfFCPtr->getField());
    return FieldContainerTransitPtr(field->getValue());
}
Exemplo n.º 3
0
void OSGWriter::visitField(GetFieldHandlePtr hF)
{
    if(hF->isValid() == false)
    {
        return;
    }

//    const FieldType &fType       = hF->getType();

    GetMapFieldHandlePtr sfMap = 
        boost::dynamic_pointer_cast<
            GetMapFieldHandle>(hF);

    if(sfMap != NULL && sfMap->isValid() == true)
    {
        sfMap->traverse(boost::bind(&OSGWriter::visitContainer, this, _1));
    }
    else
    {
        FieldContainerPtrSFieldBase::GetHandlePtr sfFCPtr = 
            boost::dynamic_pointer_cast<
                FieldContainerPtrSFieldBase::GetHandle>(hF);

        FieldContainerPtrMFieldBase::GetHandlePtr mfFCPtr = 
            boost::dynamic_pointer_cast<
                FieldContainerPtrMFieldBase::GetHandle>(hF);

        if(sfFCPtr != NULL && sfFCPtr->isValid() == true)
        {
            visitContainer((*sfFCPtr)->getValue());
        }
        else if(mfFCPtr != NULL && mfFCPtr->isValid() == true)
        {
            SizeT mfSize = (*mfFCPtr)->size();

            for(SizeT i = 0; i < mfSize; i++)
            {
                visitContainer((**mfFCPtr)[i]);
            }
        }
    }
}
Exemplo n.º 4
0
void OSGWriter::writeField(GetFieldHandlePtr hF)
{
    if(hF->isValid() == false)
    {
        return;
    }

//    const FieldType& fType = hF->getType();

    GetMapFieldHandlePtr sfMap = 
        boost::dynamic_pointer_cast<
            GetMapFieldHandle>(hF);

    FieldContainerPtrSFieldBase::GetHandlePtr sfFCPtr = 
        boost::dynamic_pointer_cast<FieldContainerPtrSFieldBase::GetHandle>(hF);
    
    FieldContainerPtrMFieldBase::GetHandlePtr mfFCPtr = 
        boost::dynamic_pointer_cast<FieldContainerPtrMFieldBase::GetHandle>(hF);

    if(sfMap != NULL && sfMap->isValid() == true)
    {
        _outStream << BeginElem 
                   << hF->getName();

        //if the Attachment Map is empty write [] as its content
        if(sfMap->empty() == true)
        {
            _outStream << " [ ] " << EndElemNL;
        }
        else
        {
            _outStream << EndElemNL
                       << BeginElem
                       << "["
                       << EndElemNL;

            _outStream << IncIndent;
        
            EditMapFieldHandle::MapList fcList;

            sfMap->flatten(fcList);

            EditMapFieldHandle::MapList::iterator iter = fcList.begin();
            EditMapFieldHandle::MapList::iterator end  = fcList.end  ();

            for(; iter!=end; ++iter)
            {
                _outStream << BeginElem
                           << "MapHelper"
                           << EndElemNL
                           << BeginElem
                           << "{"
                           << EndElemNL;

                _outStream << IncIndent;

                _outStream << BeginElem
                           << "keys"
                           << EndElemNL
                           << BeginElem
                           << "["
                           << EndElemNL;

                _outStream << IncIndent;

                std::vector<std::string>::const_iterator kIt  = 
                    iter->first.begin();

                std::vector<std::string>::const_iterator kEnd = 
                    iter->first.end();

                for(; kIt != kEnd; ++kIt)
                {
                    _outStream << BeginElem
                               << "\""
                               << *kIt
                               << "\""
                               << EndElemNL;
                }

                _outStream << DecIndent;

                _outStream << BeginElem
                           << "]"
                           << EndElemNL;

                _outStream << BeginElem
                           << "container ";
                    
                if(iter->second == NULL)
                {
                    _outStream << "NULL"
                               << EndElemNL;
                }
                else
                {
                    writeContainer(iter->second, false);
                    _outStream << EndElemNL;
                }

                _outStream << DecIndent;
                                    
                _outStream << BeginElem
                           << "}"
                           << EndElemNL;
            }

            _outStream << DecIndent; 
            
            _outStream << BeginElem
                       << "]"
                       << EndElemNL;
        }
    }
    else if(sfFCPtr != NULL || mfFCPtr != NULL)
    {
        //this Field points to FC

        if(hF->getDescription()->isDynamic() == true)
        {
            _outStream << BeginElem 
                       << "field "
                       << hF->getType().getCName()
                       << " "
                       << hF->getName();
        }
        else
        {
            _outStream << BeginElem 
                       << hF->getName();
        }

        if(sfFCPtr != NULL && sfFCPtr->isValid() == true)
        {
            if((*sfFCPtr)->getValue() == NULL)
            {
                _outStream << " NULL" << EndElemNL;
            }
            else
            {
                _outStream << " ";
                writeContainer((*sfFCPtr)->getValue(), false);
            }
        }
        else if(mfFCPtr != NULL && mfFCPtr->isValid() == true)
        {
            _outStream << EndElemNL
                       << BeginElem
                       << "[" 
                       << EndElemNL;

            _outStream << IncIndent;

            SizeT mfSize = (*mfFCPtr)->size();

            for(SizeT i = 0; i < mfSize; i++)
            {
                if((*(*mfFCPtr))[i] == NULL)
                {
                    _outStream << BeginElem
                               << "NULL" 
                               << EndElemNL;
                }
                else
                {
                    writeContainer((*(*mfFCPtr))[i], true);
                }
            }

            _outStream << DecIndent;

            _outStream << BeginElem
                       << "]" 
                       << EndElemNL;
        }
    }
    else
    {
        //this Field contains data -> write it out

        if(hF->getDescription()->isDynamic() == true)
        {
            _outStream << BeginElem 
                       << "field "
                       << hF->getType().getCName()
                       << " "
                       << hF->getName();
        }
        else
        {
            _outStream << BeginElem << hF->getName();
        }

        //to access the content of a field via a Field*
        //one must know the cardinality
        if(hF->getCardinality() == FieldType::SingleField)
        {
            _outStream << " ";

            hF->pushValueToStream(_outStream);

            _outStream << EndElemNL;
        }
        else if(hF->getCardinality() == FieldType::MultiField)
        {
            _outStream << " #";

            hF->pushSizeToStream(_outStream);

            _outStream << EndElemNL
                       << BeginElem
                       << "[" 
                       << EndElemNL;

            _outStream << IncIndent;

#ifdef WFC
            hF->pushValueToStream(_outStream);

            _outStream << EndElemNL;
#endif


            _outStream << DecIndent;
            
            _outStream << BeginElem
                       << "]" 
                       << EndElemNL;
        }
    }
}