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

OSGSimpleAttachments.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *           Copyright (C) 2000,2001,2002 by the OpenSG Forum                *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #ifdef OSG_DOC_FILES_IN_MODULE
00040 
00043 #endif
00044 
00045 #define OSG_COMPILESIMPLEATTACHMENTSINST
00046 
00047 #include <stdlib.h>
00048 #include <stdio.h>
00049 
00050 #include "OSGConfig.h"
00051 
00052 #include "OSGAttachmentContainer.h"
00053 #include "OSGSimpleAttachments.h"
00054 
00055 OSG_USING_NAMESPACE
00056 
00057 
00058 #ifdef WIN32
00059 OSG_FC_TYPE_FUNCTIONS_INL_TMPL_DEF(AttachmentDescT,
00060                                    SimpleAttachment);
00061 #endif
00062 
00063 /*-------------------------------------------------------------------------*/
00064 /*                            Name Attachment                              */
00065 
00066 FieldDescription *NameAttachmentDesc::_desc[] =
00067 {
00068     new FieldDescription(
00069         FieldTypeT::getClassType(), 
00070         getFieldName(), 
00071         OSG_FC_FIELD_IDM_DESC(
00072             SimpleAttachment<NameAttachmentDesc>::SimpleField),
00073         false,
00074         (FieldAccessMethod) &SimpleAttachment<
00075                                   NameAttachmentDesc>::getFieldPtr)
00076 };
00077 
00078 OSG_BEGIN_NAMESPACE
00079 
00080 OSG_FC_DLLEXPORT_DEF(SimpleAttachment,
00081                      NameAttachmentDesc,
00082                      OSG_SYSTEMLIB_DLLTMPLMAPPING);
00083 
00084 OSG_END_NAMESPACE
00085 
00086 /*-------------------------------------------------------------------------*/
00087 /*                            VoidP Attachment                             */
00088 
00089 FieldDescription *VoidPAttachmentDesc::_desc[] =
00090 {
00091     new FieldDescription(
00092         FieldTypeT::getClassType(), 
00093         getFieldName(), 
00094         OSG_FC_FIELD_IDM_DESC(
00095             SimpleAttachment<VoidPAttachmentDesc>::SimpleField),
00096         false,
00097         (FieldAccessMethod) &SimpleAttachment<
00098                                   VoidPAttachmentDesc>::getFieldPtr)
00099 };
00100 
00101 OSG_BEGIN_NAMESPACE
00102 
00103 OSG_FC_DLLEXPORT_DEF(SimpleAttachment,
00104                      VoidPAttachmentDesc,
00105                      OSG_SYSTEMLIB_DLLTMPLMAPPING);
00106 
00107 
00108 /*-------------------------------------------------------------------------*/
00109 /*                   Name Attachment Utility Functions                     */
00110 
00116 const Char8 *getName(AttachmentContainerPtr container)
00117 {
00118     if(container == NullFC)
00119         return NULL;
00120    
00121     // Get attachment pointer
00122     AttachmentPtr att = 
00123         container->findAttachment(Name::getClassType().getGroupId());
00124 
00125     if(att == NullFC)
00126         return NULL;
00127    
00128     // Cast to name pointer                           
00129 
00130     NamePtr name = NamePtr::dcast(att);
00131 
00132     if(name == NullFC)
00133         return NULL;
00134    
00135     return name->getFieldPtr()->getValue().c_str();
00136 }
00137 
00142 void setName(      AttachmentContainerPtr  container, 
00143              const std::string            &namestring)
00144 {
00145     if(container == NullFC)
00146     {
00147         FFATAL(("setName: no container?!?\n"));
00148         return;
00149     }
00150    
00151     // Get attachment pointer
00152 
00153     NamePtr       name = NullFC;
00154     AttachmentPtr att  = 
00155         container->findAttachment(Name::getClassType().getGroupId());
00156     
00157     if(att == NullFC)
00158     {
00159         name = Name::create();
00160         beginEditCP(container, AttachmentContainer::AttachmentsFieldMask);
00161         {
00162             container->addAttachment(name);
00163         }
00164         endEditCP(container, AttachmentContainer::AttachmentsFieldMask);
00165     }
00166     else
00167     {   
00168         name = NamePtr::dcast(att);
00169 
00170         if(name == NullFC)
00171         {
00172             FFATAL(("setName: Name Attachment is not castable to Name?!?\n"));
00173             return;
00174         }
00175     }
00176     
00177   
00178     beginEditCP(name);
00179     {
00180         name->getFieldPtr()->getValue().assign(namestring);   
00181     }
00182     endEditCP(name);
00183 }
00184 
00191 void setName(AttachmentContainerPtr container, const Char8 *name)
00192 {
00193     if(name == NULL)
00194     {
00195         AttachmentPtr att = 
00196             container->findAttachment(Name::getClassType().getGroupId());
00197  
00198         if(att != NullFC)
00199         {
00200             container->subAttachment(att);
00201         }       
00202     }
00203     else
00204     {
00205         setName(container, std::string(name));
00206     }
00207 }
00208 
00209 
00210 /*-------------------------------------------------------------------------*/
00211 /*                   VoidP Attachment Utility Functions                    */
00212 
00218 void *getVoidP(AttachmentContainerPtr container)
00219 {
00220     if(container == NullFC)
00221         return NULL;
00222    
00223     // Get attachment pointer
00224     AttachmentPtr att = 
00225        container->findAttachment(VoidPAttachment::getClassType().getGroupId());
00226 
00227     if(att == NullFC)
00228         return NULL;
00229    
00230     // Cast to name pointer                           
00231 
00232     VoidPAttachmentPtr pVoid = VoidPAttachmentPtr::dcast(att);
00233 
00234     if(pVoid == NullFC)
00235         return NULL;
00236    
00237     return pVoid->getFieldPtr()->getValue();
00238 }
00239 
00245 void setVoidP(AttachmentContainerPtr  container, 
00246               void                   *pData    )
00247 {
00248     if(container == NullFC)
00249     {
00250         FFATAL(("setVoidP: no container?!?\n"));
00251         return;
00252     }
00253    
00254     // Get attachment pointer
00255 
00256     VoidPAttachmentPtr  pVoid = NullFC;
00257     AttachmentPtr       att   = 
00258        container->findAttachment(VoidPAttachment::getClassType().getGroupId());
00259     
00260     if(att == NullFC)
00261     {
00262         pVoid = VoidPAttachment::create();
00263         container->addAttachment(pVoid);
00264     }
00265     else
00266     {   
00267         pVoid = VoidPAttachmentPtr::dcast(att);
00268 
00269         if(pVoid == NullFC)
00270         {
00271             FFATAL(("setVoidP: VoidP Attachment is not castable "
00272                     "to VoidPAttachment?!?\n"));
00273             return;
00274         }
00275     }
00276   
00277     pVoid->getFieldPtr()->setValue(pData);
00278 }
00279 
00280 OSG_END_NAMESPACE
00281 
00282 
00283 /*-------------------------------------------------------------------------*/
00284 /*                              cvs id's                                   */
00285 
00286 #ifdef __sgi
00287 #pragma set woff 1174
00288 #endif
00289 
00290 #ifdef OSG_LINUX_ICC
00291 #pragma warning( disable : 177 )
00292 #endif
00293 
00294 namespace
00295 {
00296     static Char8 cvsid_cpp[] = "@(#)$Id: $";
00297     static Char8 cvsid_hpp[] = OSGSIMPLEATTACHMENTS_HEADER_CVSID;
00298 }
00299 

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