Show
Ignore:
Timestamp:
12/21/07 12:27:23 (1 year ago)
Author:
cneumann
Message:

changed: implement attachments as two mfields (pointers and bindings).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/Carsten_PtrWork2/Source/System/FieldContainer/Base/OSGAttachmentContainer.cpp

    r1033 r1034  
    5151#include "OSGReflexiveContainerTypePredicates.h" 
    5252 
    53 #include "boost/bind.hpp" 
     53#include "OSGFieldContainerAttachmentEditFieldHandle.h" 
     54#include "OSGFieldContainerAttachmentGetFieldHandle.h" 
     55 
     56#include <boost/bind.hpp> 
    5457 
    5558OSG_BEGIN_NAMESPACE 
     
    5760void AttachmentContainer::classDescInserter(TypeObject &oType) 
    5861{ 
    59     FieldDescriptionBase *pDesc; 
    60  
    61     typedef SFAttachmentObjPtrMap::Description SFDesc; 
    62  
    63     pDesc = new SFDesc( 
    64         SFAttachmentObjPtrMap::getClassType(), 
     62    FieldDescriptionBase *pDesc;     
     63 
     64    pDesc = new MFFieldContainerAttachmentChildPtr::Description( 
     65        MFFieldContainerAttachmentChildPtr::getClassType(), 
    6566        "attachments", 
    66         "List of attachments connected.", 
    67         OSG_RC_FIELD_DESC(Attachments), 
     67        "Attachments attached to this container.", 
     68        OSG_RC_FIELD_DESC(AttachmentContainer::Attachments), 
     69        FieldContainerAttachment::ParentsFieldId, 
    6870        false, 
    69         Field::SFDefaultFlags, 
    70         static_cast<FieldEditMethodSig>(&Self::editHandleAttachments), 
    71         static_cast<FieldGetMethodSig >(&Self::getHandleAttachments ) ); 
     71        Field::MFDefaultFlags, 
     72        static_cast<FieldEditMethodSig>(&AttachmentContainer::editHandleAttachments), 
     73        static_cast<FieldGetMethodSig >(&AttachmentContainer::getHandleAttachments ) ); 
     74         
     75    oType.addInitialDesc(pDesc); 
     76 
     77     
     78    pDesc = new MFUInt32::Description( 
     79        MFUInt32::getClassType(), 
     80        "attachmentBindings", 
     81        "Binding Ids used by the attachments.", 
     82        OSG_RC_FIELD_DESC(AttachmentContainer::AttachmentBindings), 
     83        true, 
     84        Field::MFDefaultFlags, 
     85        static_cast<FieldEditMethodSig>(&AttachmentContainer::editHandleAttachmentBindings), 
     86        static_cast<FieldGetMethodSig >(&AttachmentContainer::getHandleAttachmentBindings ) ); 
    7287 
    7388    oType.addInitialDesc(pDesc); 
     
    89104 
    90105AttachmentContainer::AttachmentContainer(void) : 
    91      Inherited    (), 
    92     _sfAttachments() 
    93 
     106     Inherited           (), 
     107    _mfAttachments       (), 
     108    _mfAttachmentBindings() 
     109
     110    _mfAttachments.setEnclosingFC(this); 
     111    _mfAttachments.setFieldDescription( 
     112        dynamic_cast<AttachmentsFieldType::Description *>( 
     113            getClassType().getFieldDesc(AttachmentsFieldId))); 
    94114} 
    95115 
    96116AttachmentContainer::AttachmentContainer(const AttachmentContainer &source) : 
    97      Inherited    (source               ), 
    98     _sfAttachments(source._sfAttachments) 
    99 
    100 
     117     Inherited           (source), 
     118    _mfAttachments       (      ), 
     119    _mfAttachmentBindings(      ) 
     120
     121    _mfAttachments.setEnclosingFC(this); 
     122    _mfAttachments.setFieldDescription( 
     123        dynamic_cast<AttachmentsFieldType::Description *>( 
     124            getClassType().getFieldDesc(AttachmentsFieldId))); 
     125
     126 
    101127/*-------------------------------------------------------------------------*/ 
    102128/*                             Destructor                                  */ 
     
    111137OSG_ABSTR_FIELD_CONTAINER_DEF(AttachmentContainer) 
    112138 
    113 #if 0 
    114 void AttachmentContainer::pushToField( 
    115           FieldContainerPtrConstArg pNewElement, 
    116     const UInt32                    uiFieldId   ) 
    117 { 
    118     Inherited::pushToField(pNewElement, uiFieldId); 
    119  
    120     if(uiFieldId == AttachmentsFieldId) 
    121     { 
    122         addAttachment(dynamic_cast<AttachmentObjPtr>(pNewElement)); 
    123     } 
    124 } 
    125  
    126 void AttachmentContainer::insertIntoMField( 
    127     const UInt32                    uiIndex, 
    128           FieldContainerPtrConstArg pNewElement, 
    129     const UInt32                    uiFieldId   ) 
    130 { 
    131     Inherited::insertIntoMField(uiIndex, pNewElement, uiFieldId); 
    132      
    133     FWARNING(("AttachmentContainerMixin::insertIntoMField: NIY\n")); 
    134 } 
    135  
    136 void AttachmentContainer::replaceInMField ( 
    137     const UInt32                    uiIndex, 
    138           FieldContainerPtrConstArg pNewElement, 
    139     const UInt32                    uiFieldId   ) 
    140 { 
    141     Inherited::replaceInMField(uiIndex, pNewElement, uiFieldId); 
    142  
    143     FWARNING(("AttachmentContainerMixin::replaceInMField: NIY\n")); 
    144 } 
    145  
    146 void AttachmentContainer::replaceInMField ( 
    147           FieldContainerPtrConstArg pOldElement, 
    148           FieldContainerPtrConstArg pNewElement, 
    149     const UInt32                    uiFieldId  ) 
    150 { 
    151     Inherited::replaceInMField(pOldElement, pNewElement, uiFieldId); 
    152      
    153     FWARNING(("AttachmentContainerMixin::replaceInMField: NIY\n")); 
    154 } 
    155  
    156 void AttachmentContainer::removeFromMField( 
    157     const UInt32                    uiIndex, 
    158     const UInt32                    uiFieldId ) 
    159 { 
    160     Inherited::removeFromMField(uiIndex, uiFieldId); 
    161      
    162     FWARNING(("AttachmentContainerMixin::removeFromMField: NIY\n")); 
    163 } 
    164  
    165 void AttachmentContainer::removeFromMField( 
    166           FieldContainerPtrConstArg pElement, 
    167     const UInt32                    uiFieldId ) 
    168 { 
    169     Inherited::removeFromMField(pElement, uiFieldId); 
    170      
    171     FWARNING(("AttachmentContainerMixin::removeFromMField: NIY\n")); 
    172 } 
    173  
    174 void AttachmentContainer::clearField(const UInt32 uiFieldId) 
    175 { 
    176     Inherited::clearField(uiFieldId); 
    177      
    178     FWARNING(("AttachmentContainerMixin::clearField: NIY\n")); 
    179 } 
    180 #endif 
    181  
    182139/*-------------------------------------------------------------------------*/ 
    183140/* Binary access                                                           */ 
     
    189146    if(FieldBits::NoField != (AttachmentsFieldMask & whichField)) 
    190147    { 
    191         returnValue += _sfAttachments.getBinSize(); 
     148        AttachmentsFieldType::const_iterator aI = _mfAttachments.begin(); 
     149        AttachmentsFieldType::const_iterator aE = _mfAttachments.end  (); 
     150         
     151        UInt32 numPublicObjects = 0; 
     152         
     153        for(; aI != aE; ++aI) 
     154        { 
     155            if((*aI)->getInternal().getValue() == false) 
     156                ++numPublicObjects; 
     157        } 
     158         
     159        // number of objects + (binding + id) for each 
     160        return sizeof(UInt32) +  
     161               numPublicObjects * (sizeof(UInt16) + sizeof(UInt32)); 
     162    } 
     163     
     164    if(FieldBits::NoField != (AttachmentBindingsFieldMask & whichField)) 
     165    { 
     166        return returnValue += _mfAttachmentBindings.getBinSize(); 
    192167    } 
    193168 
     
    202177    if(FieldBits::NoField != (AttachmentsFieldMask & whichField)) 
    203178    { 
    204         _sfAttachments.copyToBin(pMem); 
     179        AttachmentsFieldType::const_iterator aI = _mfAttachments.begin(); 
     180        AttachmentsFieldType::const_iterator aE = _mfAttachments.end  (); 
     181         
     182        UInt32 numPublicObjects = 0; 
     183        UInt32 containerId; 
     184        UInt16 binding; 
     185         
     186        for(; aI != aE; ++aI) 
     187        { 
     188            if((*aI)->getInternal().getValue() == false) 
     189                ++numPublicObjects; 
     190        } 
     191         
     192        pMem.putValue(numPublicObjects); 
     193         
     194        aI = _mfAttachments.begin(); 
     195        aE = _mfAttachments.end  (); 
     196         
     197        AttachmentBindingsFieldType::const_iterator bI = 
     198            _mfAttachmentBindings.begin(); 
     199        AttachmentBindingsFieldType::const_iterator bE = 
     200            _mfAttachmentBindings.end  (); 
     201             
     202        for(; aI != aE; ++aI, ++bI) 
     203        { 
     204            binding     = UInt16(*bI & 0x0000FFFF); 
     205            containerId = getContainerId(*aI); 
     206         
     207            pMem.putValue(binding    ); 
     208            pMem.putValue(containerId); 
     209        } 
     210    } 
     211     
     212    if(FieldBits::NoField != (AttachmentBindingsFieldMask & whichField)) 
     213    { 
     214        _mfAttachmentBindings.copyToBin(pMem); 
    205215    } 
    206216} 
     
    213223    if(FieldBits::NoField != (AttachmentsFieldMask & whichField)) 
    214224    { 
    215         _sfAttachments.copyFromBin(pMem); 
     225        UInt32 numObjects = 0; 
     226        UInt32 containerId; 
     227        UInt16 binding; 
     228         
     229        pMem.getValue(numObjects); 
     230         
     231        for(UInt32 i = 0; i < numObjects; ++i) 
     232        { 
     233            pMem.getValue(binding    ); 
     234            pMem.getValue(containerId); 
     235             
     236            FieldContainerAttachmentPtr pAtt = 
     237                dynamic_cast<FieldContainerAttachmentPtr>( 
     238                    FieldContainerFactory::the()->getMappedContainer(containerId)); 
     239                     
     240            addAttachment(pAtt, binding); 
     241        } 
     242    } 
     243     
     244    if(FieldBits::NoField != (AttachmentBindingsFieldMask & whichField)) 
     245    { 
     246        _mfAttachmentBindings.copyFromBin(pMem); 
    216247    } 
    217248} 
     
    235266          UInt16           binding) 
    236267{ 
    237     UInt32 key; 
    238  
    239268    if(pAttachment == NullFC) 
    240269        return; 
    241  
    242     key = (UInt32 (pAttachment->getGroupId()) << 16) | binding; 
    243  
    244     addRef(pAttachment); 
    245  
    246     pAttachment->addParent(this); 
    247  
    248     Self::editSField(AttachmentsFieldMask); 
    249  
    250     AttachmentObjPtrMapIt fcI = _sfAttachments.getValue().find(key); 
    251  
    252     if(fcI != _sfAttachments.getValue().end()) 
    253     { 
    254         (*fcI).second->subParent(this); 
    255  
    256         subRef((*fcI).second); 
    257  
    258         (*fcI).second = pAttachment; 
     270         
     271    UInt32 key = (UInt32(pAttachment->getGroupId()) << 16) | binding; 
     272 
     273    Self::editMField(AttachmentsFieldMask,        _mfAttachments       ); 
     274    Self::editMField(AttachmentBindingsFieldMask, _mfAttachmentBindings); 
     275     
     276    MFUInt32::iterator bI =  
     277        std::find(_mfAttachmentBindings.begin(), 
     278                  _mfAttachmentBindings.end  (), key); 
     279                                             
     280    if(bI != _mfAttachmentBindings.end()) 
     281    { 
     282        _mfAttachments[std::distance(_mfAttachmentBindings.begin(), bI)] = 
     283            pAttachment; 
    259284    } 
    260285    else 
    261286    { 
    262         _sfAttachments.getValue()[key] = pAttachment; 
     287        _mfAttachmentBindings.push_back(key        ); 
     288        _mfAttachments       .push_back(pAttachment); 
    263289    } 
    264290} 
     
    279305          UInt16           binding) 
    280306{ 
    281     UInt32 key; 
    282  
    283     AttachmentObjPtrMapIt fcI; 
    284  
    285307    if(pAttachment == NullFC) 
    286308        return; 
    287  
    288     key = (UInt32(pAttachment->getGroupId()) << 16) | binding; 
    289  
    290     Self::editSField(AttachmentsFieldMask); 
    291  
    292     fcI = _sfAttachments.getValue().find(key); 
    293  
    294     if(fcI != _sfAttachments.getValue().end()) 
    295     { 
    296         (*fcI).second->subParent(this); 
    297  
    298         subRef((*fcI).second); 
    299  
    300         _sfAttachments.getValue().erase(fcI); 
    301     } 
    302 
    303  
    304  
    305 const AttachmentContainer::SFAttachmentObjPtrMap * 
    306     AttachmentContainer::getSFAttachments(void) const 
    307 
    308     return &_sfAttachments; 
    309 
    310  
     309         
     310    UInt32 key = (UInt32(pAttachment->getGroupId()) << 16) | binding; 
     311 
     312    Self::editMField(AttachmentsFieldMask,        _mfAttachments       ); 
     313    Self::editMField(AttachmentBindingsFieldMask, _mfAttachmentBindings); 
     314 
     315    MFUInt32::iterator bI =  
     316        std::find(_mfAttachmentBindings.begin(), 
     317                  _mfAttachmentBindings.end  (), key); 
     318                                             
     319    if(bI != _mfAttachmentBindings.end()) 
     320    { 
     321        _mfAttachments.erase( 
     322            _mfAttachments.begin() +  
     323                std::distance(_mfAttachmentBindings.begin(), bI)); 
     324        _mfAttachmentBindings.erase(bI); 
     325    } 
     326
     327 
     328 
     329MFFieldContainerAttachmentChildPtr const * 
     330AttachmentContainer::getMFAttachments(void) const 
     331
     332    return &_mfAttachments; 
     333
     334 
     335MFFieldContainerAttachmentChildPtr const & 
     336AttachmentContainer::getAttachments(void) const 
     337
     338    return _mfAttachments; 
     339
     340 
     341MFUInt32 const * 
     342AttachmentContainer::getMFAttachmentBindings(void) const 
     343{    
     344    return &_mfAttachmentBindings; 
     345
     346 
     347MFUInt32 const & 
     348AttachmentContainer::getAttachmentBindings(void) const 
     349
     350    return _mfAttachmentBindings; 
     351
    311352 
    312353void AttachmentContainer::dump(      UInt32    uiIndent, 
     
    339380    if(FieldBits::NoField != (AttachmentsFieldMask & whichField)) 
    340381    { 
    341         _sfAttachments.syncWith(pFrom->_sfAttachments); 
     382        _mfAttachments.syncWith( 
     383            pFrom->_mfAttachments, syncMode, uiSyncInfo, oOffsets); 
     384    } 
     385     
     386    if(FieldBits::NoField != (AttachmentBindingsFieldMask & whichField)) 
     387    { 
     388        _mfAttachmentBindings.syncWith( 
     389            pFrom->_mfAttachmentBindings, syncMode, uiSyncInfo, oOffsets); 
    342390    } 
    343391} 
     
    348396    Inherited::resolveLinks(); 
    349397 
    350     AttachmentObjPtrMapIt fcI = _sfAttachments.getValue().begin(); 
    351     AttachmentObjPtrMapIt fcE = _sfAttachments.getValue().end  (); 
    352  
    353     while(fcI != fcE) 
    354     { 
    355         (*fcI).second->subParent(this); 
    356  
    357         subRef((*fcI).second); 
    358  
    359         ++fcI; 
    360     } 
     398    _mfAttachments       .clear(); 
     399    _mfAttachmentBindings.clear(); 
    361400} 
    362401 
    363402EditFieldHandlePtr AttachmentContainer::editHandleAttachments(void)  
    364403{ 
    365     SFAttachmentObjPtrMap::EditHandlePtr returnValue( 
    366         new  SFAttachmentObjPtrMap::EditHandle( 
    367              &_sfAttachments,  
     404    FieldContainerAttachmentEditFieldHandlePtr returnValue( 
     405        new  FieldContainerAttachmentEditFieldHandle( 
     406             &_mfAttachments, 
     407             &_mfAttachmentBindings, 
    368408             this->getType().getFieldDesc(AttachmentsFieldId))); 
    369409 
    370 //     returnValue->setAddMethod(boost::bind(&AttachmentContainer::addAttachment, 
    371 //                                           this, 
    372 //                                           _1, 
    373 //                                           _2)); 
    374  
    375     editSField(AttachmentsFieldMask); 
     410    returnValue->setAttachmentContainer(this); 
     411 
     412    editMField(AttachmentsFieldMask,        _mfAttachments       ); 
     413    editMField(AttachmentBindingsFieldMask, _mfAttachmentBindings); 
    376414 
    377415    return returnValue; 
     
    380418GetFieldHandlePtr AttachmentContainer::getHandleAttachments(void) const 
    381419{ 
    382     SFAttachmentObjPtrMap::GetHandlePtr returnValue( 
    383         new  SFAttachmentObjPtrMap::GetHandle( 
    384              &_sfAttachments,  
    385              this->getType().getFieldDesc(AttachmentsFieldId))); 
    386  
     420    FieldContainerAttachmentGetFieldHandlePtr returnValue( 
     421        new FieldContainerAttachmentGetFieldHandle( 
     422            &_mfAttachments, 
     423            &_mfAttachmentBindings, 
     424            this->getType().getFieldDesc(AttachmentsFieldId))); 
     425             
     426    returnValue->setAttachmentContainer(this); 
     427     
    387428    return returnValue; 
    388429} 
    389430 
    390  
    391  
     431EditFieldHandlePtr 
     432AttachmentContainer::editHandleAttachmentBindings(void) 
     433
     434    AttachmentBindingsFieldType::EditHandlePtr returnValue( 
     435        new AttachmentBindingsFieldType::EditHandle( 
     436            &_mfAttachmentBindings, 
     437            this->getType().getFieldDesc(AttachmentBindingsFieldId))); 
     438             
     439    editMField(AttachmentBindingsFieldMask, _mfAttachmentBindings); 
     440     
     441    return returnValue; 
     442
     443 
     444GetFieldHandlePtr 
     445AttachmentContainer::getHandleAttachmentBindings(void) const 
     446
     447    AttachmentBindingsFieldType::GetHandlePtr returnValue( 
     448        new AttachmentBindingsFieldType::GetHandle( 
     449            &_mfAttachmentBindings, 
     450            this->getType().getFieldDesc(AttachmentBindingsFieldId))); 
     451                 
     452    return returnValue; 
     453
    392454 
    393455/*-------------------------------------------------------------------------*/ 
     
    519581                                                cloneGroupIds, ignoreGroupIds); 
    520582#else 
    521     const SFFieldContainerAttachmentPtrMap *pAttMap
    522         src->getSFAttachments(); 
    523  
    524     FieldContainerAttachmentMap::const_iterator mapIt  = 
    525         pAttMap->getValue().begin(); 
    526  
    527     FieldContainerAttachmentMap::const_iterator mapEnd = 
    528         pAttMap->getValue().end(); 
    529  
    530     for(; mapIt != mapEnd; ++mapIt) 
    531     { 
    532         FieldContainerAttachmentRefPtr att(mapIt->second); 
    533         UInt16                         uiBinding = UInt16(mapIt->first & 
    534                                                           0x0000FFFF    ); 
    535  
     583    AttachmentContainer::AttachmentsFieldType::const_iterator attI
     584        src->getMFAttachments()->begin(); 
     585    AttachmentContainer::AttachmentsFieldType::const_iterator attE = 
     586        src->getMFAttachments()->end(); 
     587         
     588    AttachmentContainer::AttachmentBindingsFieldType::const_iterator bindI = 
     589        src->getMFAttachmentBindings()->begin(); 
     590    AttachmentContainer::AttachmentBindingsFieldType::const_iterator bindE = 
     591        src->getMFAttachmentBindings()->end(); 
     592 
     593    for(; attI != attE; ++attI, bindI) 
     594    { 
     595        FieldContainerAttachmentRefPtr att   (*attI              ); 
     596        UInt16                         uiBind(*bindI & 0x0000FFFF); 
     597         
    536598        if(att != NullFC) 
    537599        { 
    538             const FieldContainerType &attType = att->getType(); 
    539  
     600            FieldContainerType const &attType = att->getType(); 
     601         
    540602            // test if att type should NOT be ignored 
    541603            if(!TypePredicates::typeInGroupIds (ignoreGroupIds.begin(), 
     
    560622            } 
    561623        } 
    562  
    563         dst->addAttachment(att, uiBinding); 
     624         
     625        dst->addAttachment(att, uiBind); 
    564626    } 
    565627#endif 
     
    691753                                                shareGroupIds, ignoreGroupIds); 
    692754#else 
    693     const SFFieldContainerAttachmentPtrMap *pAttMap
    694         src->getSFAttachments(); 
    695  
    696     FieldContainerAttachmentMap::const_iterator mapIt  = 
    697         pAttMap->getValue().begin(); 
    698  
    699     FieldContainerAttachmentMap::const_iterator mapEnd = 
    700         pAttMap->getValue().end(); 
    701  
    702     for(; mapIt != mapEnd; ++mapIt) 
    703     { 
    704         FieldContainerAttachmentRefPtr att(mapIt->second); 
    705         UInt16                         uiBinding = UInt16(mapIt->first & 
    706                                                           0x0000FFFF    ); 
    707  
     755    AttachmentContainer::AttachmentsFieldType::const_iterator attI
     756        src->getMFAttachments()->begin(); 
     757    AttachmentContainer::AttachmentsFieldType::const_iterator attE = 
     758        src->getMFAttachments()->end(); 
     759         
     760    AttachmentContainer::AttachmentBindingsFieldType::const_iterator bindI = 
     761        src->getMFAttachmentBindings()->begin(); 
     762    AttachmentContainer::AttachmentBindingsFieldType::const_iterator bindE = 
     763        src->getMFAttachmentBindings()->end(); 
     764 
     765    for(; attI != attE; ++attI, bindI) 
     766    { 
     767        FieldContainerAttachmentRefPtr att   (*attI              ); 
     768        UInt16                         uiBind(*bindI & 0x0000FFFF); 
     769         
    708770        if(att != NullFC) 
    709771        { 
    710             const FieldContainerType &attType = att->getType(); 
     772            FieldContainerType const &attType = att->getType(); 
    711773 
    712774            // test if att type should NOT be ignored 
     
    733795        } 
    734796 
    735         dst->addAttachment(att, uiBinding); 
     797        dst->addAttachment(att, uiBind); 
    736798    } 
    737799#endif