Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGAttachmentContainer.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *                     Copyright 2000-2002 by OpenSG Forum                   *
00006  *                                                                           *
00007  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00008  *                                                                           *
00009 \*---------------------------------------------------------------------------*/
00010 /*---------------------------------------------------------------------------*\
00011  *                                License                                    *
00012  *                                                                           *
00013  * This library is free software; you can redistribute it and/or modify it   *
00014  * under the terms of the GNU Library General Public License as published    *
00015  * by the Free Software Foundation, version 2.                               *
00016  *                                                                           *
00017  * This library is distributed in the hope that it will be useful, but       *
00018  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00020  * Library General Public License for more details.                          *
00021  *                                                                           *
00022  * You should have received a copy of the GNU Library General Public         *
00023  * License along with this library; if not, write to the Free Software       *
00024  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00025  *                                                                           *
00026 \*---------------------------------------------------------------------------*/
00027 /*---------------------------------------------------------------------------*\
00028  *                                Changes                                    *
00029  *                                                                           *
00030  *                                                                           *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #ifdef OSG_DOC_FILES_IN_MODULE
00038 
00041 #endif
00042 
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 
00046 #include "OSGConfig.h"
00047 #include "OSGAttachmentContainer.h"
00048 #include "OSGFieldContainerPtr.h"
00049 #include "OSGFieldContainerType.h"
00050 #include "OSGAttachment.h"
00051 #include "OSGBinaryDataHandler.h"
00052 
00053 OSG_USING_NAMESPACE
00054 
00055 const BitVector AttachmentContainer::AttachmentsFieldMask =
00056     (TypeTraits<BitVector>::One << 
00057         AttachmentContainer::AttachmentsFieldId);
00058 
00059 FieldDescription *AttachmentContainer::_desc[] =
00060 {
00061     new FieldDescription(SFAttachmentMap::getClassType(),
00062                          "attachments",
00063                          OSG_FC_FIELD_IDM_DESC(AttachmentsField),
00064                          false,
00065                          (FieldAccessMethod)
00066                              &AttachmentContainer::getSFAttachments)
00067 };
00068 
00069 FieldContainerType AttachmentContainer::_type(
00070     "AttachmentContainer",
00071     "FieldContainer",
00072     0,
00073     NULL,
00074     0,
00075     _desc,
00076     sizeof(_desc));
00077 
00078 
00079 OSG_ABSTR_FIELD_CONTAINER_DEF(AttachmentContainer, AttachmentContainerPtr)
00080 
00081 /*-------------------------------------------------------------------------*/
00082 /*                          Handle Attachments                             */
00083 
00084 void AttachmentContainer::addAttachment(const AttachmentPtr &fieldContainerP,
00085                                               UInt16         binding)
00086 {
00087     UInt32 key;
00088 
00089     if(fieldContainerP == NullFC)
00090         return;
00091 
00092     key = (UInt32 (fieldContainerP->getGroupId()) << 16) | binding;
00093 
00094     addRefCP(fieldContainerP);
00095 
00096     beginEditCP(fieldContainerP, Attachment::ParentsFieldMask);
00097     {
00098         fieldContainerP->addParent(getPtr());
00099     }
00100     endEditCP  (fieldContainerP, Attachment::ParentsFieldMask);
00101 
00102     AttachmentMap::iterator fcI = _attachmentMap.getValue().find(key);
00103 
00104     if(fcI != _attachmentMap.getValue().end())
00105     {
00106         beginEditCP((*fcI).second, Attachment::ParentsFieldMask);
00107         {
00108             (*fcI).second->subParent(getPtr());
00109         }
00110         endEditCP  ((*fcI).second, Attachment::ParentsFieldMask);
00111 
00112         subRefCP((*fcI).second);
00113 
00114         (*fcI).second = fieldContainerP;
00115     }
00116     else
00117     {
00118         _attachmentMap.getValue()[key] = fieldContainerP;
00119     }
00120 }
00121 
00122 void AttachmentContainer::subAttachment(const AttachmentPtr &fieldContainerP,
00123                                               UInt16         binding)
00124 {
00125     UInt32 key;
00126 
00127     AttachmentMap::iterator fcI;
00128 
00129     if(fieldContainerP == NullFC)
00130         return;
00131 
00132     key = (UInt32(fieldContainerP->getGroupId()) << 16) | binding;
00133 
00134     fcI = _attachmentMap.getValue().find(key);
00135 
00136     if(fcI != _attachmentMap.getValue().end())
00137     {
00138         beginEditCP(fieldContainerP, Attachment::ParentsFieldMask);
00139         {
00140             (*fcI).second->subParent(getPtr());
00141         }
00142         endEditCP  (fieldContainerP, Attachment::ParentsFieldMask);
00143 
00144         subRefCP((*fcI).second);
00145 
00146         _attachmentMap.getValue().erase(fcI);
00147     }
00148 }
00149 
00150 AttachmentPtr AttachmentContainer::findAttachment(UInt32 groupId,
00151                                                   UInt16 binding)
00152 {
00153     UInt32 key = (UInt32(groupId) << 16) | binding;
00154 
00155     AttachmentMap::iterator fcI = _attachmentMap.getValue().find(key);
00156 
00157     if(fcI == _attachmentMap.getValue().end())
00158     {
00159         return NullFC;
00160     }
00161     else
00162     {
00163         return (*fcI).second;
00164     }
00165 }
00166 
00167 /*-------------------------------------------------------------------------*/
00168 /*                            Field Access                                 */
00169 
00170 SFAttachmentMap *AttachmentContainer::getSFAttachments(void)
00171 {
00172     return &_attachmentMap;
00173 }
00174 
00175 /*-------------------------------------------------------------------------*/
00176 /*                             Changed                                     */
00177 
00178 void AttachmentContainer::changed(BitVector whichField,
00179                                   UInt32    origin    )
00180 {
00181     if(whichField & AttachmentsFieldMask)
00182     {
00183         if(origin & ChangedOrigin::Abstract)
00184         {
00185             if(origin & ChangedOrigin::AbstrIncRefCount)
00186             {
00187                 AttachmentMap::iterator attIt  = 
00188                     _attachmentMap.getValue().begin();
00189                 AttachmentMap::iterator attEnd = 
00190                     _attachmentMap.getValue().end();
00191 
00192                 while(attIt != attEnd)
00193                 {
00194                     addRefCP((*attIt).second);
00195                     
00196                     ++attIt;
00197                 }
00198             }
00199         }
00200     }
00201 }
00202 
00203 /*-------------------------------------------------------------------------*/
00204 /*                           Binary Access                                 */
00205 
00206 UInt32 AttachmentContainer::getBinSize(const BitVector &whichField)
00207 {
00208     UInt32 returnValue = 0;
00209 
00210     if(FieldBits::NoField != (AttachmentsFieldMask & whichField))
00211     {
00212         returnValue += _attachmentMap.getBinSize();
00213     }
00214 
00215     return returnValue;
00216 }
00217 
00218 void AttachmentContainer::copyToBin  (      BinaryDataHandler &pMem,
00219                                       const BitVector    &whichField)
00220 {
00221     if(FieldBits::NoField != (AttachmentsFieldMask & whichField))
00222     {
00223         _attachmentMap.copyToBin(pMem);
00224     }
00225 }
00226 
00227 void AttachmentContainer::copyFromBin(      BinaryDataHandler &pMem,
00228                                       const BitVector    &whichField)
00229 {
00230     if(FieldBits::NoField != (AttachmentsFieldMask & whichField))
00231     {
00232         _attachmentMap.copyFromBin(pMem);
00233     }
00234 }
00235 
00236 /*-------------------------------------------------------------------------*/
00237 /*                                Dump                                     */
00238 
00239 void AttachmentContainer::dump(      UInt32    uiIndent,
00240                                const BitVector bvFlags) const
00241 {
00242     AttachmentMap::const_iterator fcI;
00243 
00244     fcI = _attachmentMap.getValue().begin();
00245 
00246     while(fcI != _attachmentMap.getValue().end())
00247     {
00248         (*fcI).second->dump(uiIndent + 4, bvFlags);
00249         ++fcI;
00250     }
00251 }
00252 
00253 /*-------------------------------------------------------------------------*/
00254 /*                            Constructors                                 */
00255 
00256 AttachmentContainer::AttachmentContainer(void) :
00257      Inherited    (),
00258     _attachmentMap()
00259 {
00260 }
00261 
00262 AttachmentContainer::AttachmentContainer(const AttachmentContainer &source) :
00263      Inherited    (source),
00264     _attachmentMap()
00265 {
00266     AttachmentMap::const_iterator fcI =
00267         source._attachmentMap.getValue().begin();
00268 
00269     AttachmentMap::const_iterator fcEnd =
00270         source._attachmentMap.getValue().end  ();
00271 
00272     while(fcI != fcEnd)
00273     {
00274         addAttachment((*fcI).second);
00275 
00276         fcI++;
00277     }
00278 }
00279 
00280 /*-------------------------------------------------------------------------*/
00281 /*                             Destructor                                  */
00282 
00283 AttachmentContainer::~AttachmentContainer(void)
00284 {
00285     AttachmentMap::iterator attIt  = _attachmentMap.getValue().begin();
00286     AttachmentMap::iterator attEnd = _attachmentMap.getValue().end();
00287 
00288     AttachmentContainerPtr thisP = getPtr();
00289 
00290     while(attIt != attEnd)
00291     {
00292         beginEditCP((*attIt).second, Attachment::ParentsFieldMask);
00293         {
00294             (*attIt).second->subParent(thisP);
00295         }
00296         endEditCP  ((*attIt).second, Attachment::ParentsFieldMask);
00297 
00298         subRefCP   ((*attIt).second);
00299 
00300         ++attIt;
00301     }
00302 
00303     _attachmentMap.getValue().clear();
00304 }
00305 
00306 /*-------------------------------------------------------------------------*/
00307 /*                                Sync                                     */
00308 
00309 #if !defined(OSG_FIXED_MFIELDSYNC)
00310 void AttachmentContainer::executeSync(      FieldContainer &other,
00311                                       const BitVector      &whichField)
00312 {
00313     this->executeSyncImpl((AttachmentContainer *) &other, whichField);
00314 }
00315 
00316 void AttachmentContainer::executeSyncImpl(
00317           AttachmentContainer *pOther,
00318     const BitVector           &whichField)
00319 {
00320     Inherited::executeSyncImpl(pOther, whichField);
00321 
00322     if (FieldBits::NoField != (AttachmentsFieldMask & whichField))
00323     {
00324         _attachmentMap.syncWith(pOther->_attachmentMap);
00325     }
00326 }
00327 #else
00328 void AttachmentContainer::executeSync(      FieldContainer &other,
00329                                       const BitVector      &whichField,
00330                                       const SyncInfo       &sInfo     )
00331 {
00332     this->executeSyncImpl((AttachmentContainer *) &other, whichField, sInfo);
00333 }
00334 
00335 void AttachmentContainer::executeSyncImpl(
00336           AttachmentContainer *pOther,
00337     const BitVector           &whichField,
00338     const SyncInfo            &sInfo     )
00339 {
00340     Inherited::executeSyncImpl(pOther, whichField, sInfo);
00341 
00342     if (FieldBits::NoField != (AttachmentsFieldMask & whichField))
00343     {
00344         _attachmentMap.syncWith(pOther->_attachmentMap);
00345     }
00346 }
00347 #endif
00348 
00349 /*-------------------------------------------------------------------------*/
00350 /*                                Pointer                                  */
00351 
00352 AttachmentContainerPtr AttachmentContainer::getPtr(void)
00353 {
00354     return AttachmentContainerPtr(*this);
00355 }
00356 
00357 
00358 /*-------------------------------------------------------------------------*/
00359 /*                              cvs id's                                   */
00360 
00361 #ifdef __sgi
00362 #pragma set woff 1174
00363 #endif
00364 
00365 #ifdef OSG_LINUX_ICC
00366 #pragma warning( disable : 177 )
00367 #endif
00368 
00369 namespace
00370 {
00371     static Char8 cvsid_cpp[] = "@(#)$Id: $";
00372     static Char8 cvsid_hpp[] = OSGATTACHMENTCONTAINER_HEADER_CVSID;
00373     static Char8 cvsid_inl[] = OSGATTACHMENTCONTAINER_INLINE_CVSID;
00374 }
00375 

Generated on Thu Aug 25 04:01:00 2005 for OpenSG by  doxygen 1.4.3