/*! Visits a map field (essentially an SF that contains a std::map
    with a FieldContainer* as value type) for
    preWrite. It creates elements for the pointed to containers and
    calls preWrite on them. If the pointed to containers are not in the
    root's id set they are added and thus scheduled for writing.

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

    GetMapFieldHandlePtr sfMapField =
        boost::dynamic_pointer_cast<GetMapFieldHandle>(
            getContainer()->getField(fieldId));

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

    sfMapField->traverse(
        boost::bind(&OSBCommonElement::handleMapElementPreWrite,
                    this,
                    _1));
}
Ejemplo n.º 2
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]);
            }
        }
    }
}
Ejemplo n.º 3
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;
        }
    }
}