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

OSGCoredNodePtr.inl

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 OSG_BEGIN_NAMESPACE
00047 
00048 
00049 inline
00050 CoredNodePtrBase::CoredNodePtrBase(void) : _node(NullFC)
00051 {}
00052 
00053 inline
00054 CoredNodePtrBase::CoredNodePtrBase(NodePtr node)
00055 {
00056     setNode(node);
00057 }
00058 
00059 inline
00060 CoredNodePtrBase::~CoredNodePtrBase()
00061 {
00062     setNode(NullFC);
00063 }
00064 
00065 inline
00066 NodePtr CoredNodePtrBase::node(void) const
00067 { 
00068     return _node; 
00069 }
00070 
00071 inline
00072 void CoredNodePtrBase::setNode(const NodePtr &node)
00073 {
00074     if(_node == node)
00075         return;
00076 
00077     if(_node != NullFC)
00078         subRefCP(_node);
00079 
00080     _node = node;
00081 
00082     if(_node != NullFC)
00083         addRefCP(_node);
00084 }
00085 
00086 inline
00087 void CoredNodePtrBase::setNode(const NullFieldContainerPtr &)
00088 {
00089     if(_node != NullFC)
00090         subRefCP(_node);
00091 
00092     _node = NullFC;
00093 }
00094 
00095 // CoredNodePtr methods
00096 
00097 template< class Core > inline
00098 CoredNodePtr<Core>::CoredNodePtr(void) : 
00099     CoredNodePtrBase(NullFC), _core(NullFC)
00100 {}
00101 
00102 template< class Core > inline
00103 CoredNodePtr<Core>::CoredNodePtr(const NodePtr& node) : 
00104     CoredNodePtrBase(node)
00105 {
00106     setCore(Core::Ptr::dcast(CoredNodePtrBase::node()->getCore()));
00107 }
00108 
00109 template< class Core > inline
00110 CoredNodePtr<Core>::CoredNodePtr(const NodeCorePtr& core) : 
00111     CoredNodePtrBase()
00112 {
00113     setCore(Core::Ptr::dcast(core));
00114     updateNode();
00115 }
00116 
00117 template< class Core > inline
00118 CoredNodePtr<Core>::CoredNodePtr(const typename Core::Ptr& core) : 
00119     CoredNodePtrBase()
00120 {
00121     setCore(core);
00122     updateNode();
00123 }
00124 
00125 template< class Core > inline
00126 CoredNodePtr<Core>::CoredNodePtr(const CoredNodePtr<Core>& ptr) : 
00127     CoredNodePtrBase()
00128 {
00129     setCore(ptr._core);
00130     setNode(ptr.node());
00131 }
00132 
00133 template< class Core > inline
00134 CoredNodePtr<Core>::~CoredNodePtr()
00135 {
00136     setCore(NullFC);
00137     setNode(NullFC);
00138 }
00139 
00140 template< class Core > inline
00141 CoredNodePtr<Core> CoredNodePtr<Core>::create(void)
00142 {
00143     return CoredNodePtr<Core>(Core::create());
00144 }
00145 
00146 template< class Core > inline
00147 void CoredNodePtr<Core>::coreChanged(void)
00148 {
00149     setCore(node()->getCore());
00150 }
00151 
00152 template< class Core > inline
00153 typename Core::Ptr CoredNodePtr<Core>::core(void) const
00154 {
00155 #ifdef OSG_DEBUG
00156     FFASSERT((node()->getCore() == _core), false, 
00157               ("CoredNodePtr::core: core changed!"););
00158 #endif
00159     return _core;
00160 }
00161 
00162 template< class Core > inline
00163 typename Core::Ptr& CoredNodePtr<Core>::operator->(void)
00164 {
00165 #ifdef OSG_DEBUG
00166     FFASSERT((node()->getCore() == _core), false, 
00167               ("CoredNodePtr::operator ->: core changed!"););
00168 #endif
00169     return _core;
00170 }
00171 
00172 template< class Core > inline
00173 CoredNodePtr<Core>::operator NodePtr()
00174 {
00175 #ifdef OSG_DEBUG
00176     FFASSERT((node()->getCore() == _core), false, 
00177               ("CoredNodePtr::operator NodePtr: core changed!"););
00178 #endif
00179     return node();
00180 }
00181 
00182 template< class Core > inline
00183 CoredNodePtr<Core>::operator typename Core::Ptr()
00184 {
00185 #ifdef OSG_DEBUG
00186     FFASSERT((node()->getCore() == _core), false, 
00187               ("CoredNodePtr::operator Core::Ptr: core changed!"););
00188 #endif
00189     return _core;
00190 }
00191 
00192 /* Assignment. Create a new CNP if necessary */
00193 
00194 template< class Core > inline
00195 CoredNodePtr<Core>& CoredNodePtr<Core>::operator =(const NodePtr& node)
00196 {
00197     setNode(node);
00198     setCore(Core::Ptr::dcast(node->getCore()));
00199     return *this;
00200 }
00201 
00202 template< class Core > inline
00203 CoredNodePtr<Core>& CoredNodePtr<Core>::operator =(const typename Core::Ptr& core)
00204 {
00205     setCore(core);
00206     updateNode();
00207 
00208     return *this;
00209 }
00210 
00211 template< class Core > inline
00212 CoredNodePtr<Core>& CoredNodePtr<Core>::operator =(const CoredNodePtr<Core>& cnp)
00213 {
00214     setNode(cnp.node());
00215     setCore(cnp._core);
00216     return *this;
00217 }
00218 
00219 template< class Core > inline
00220 CoredNodePtr<Core>& CoredNodePtr<Core>::operator =(const NullFieldContainerPtr &)
00221 {
00222     setNode(NullFC);
00223     setCore(NullFC);
00224     return *this;
00225 }
00226 
00227 template< class Core > inline
00228 NodeCorePtr CoredNodePtr<Core>::getCoreV(void) const
00229 {
00230     return _core;
00231 }
00232 
00233 template< class Core > inline
00234 void CoredNodePtr<Core>::setCore(const NodeCorePtr &core)
00235 {
00236     setCore(Core::Ptr::dcast(core));
00237 }
00238 
00239 template< class Core > inline
00240 void CoredNodePtr<Core>::setCore(const typename Core::Ptr &core)
00241 {
00242     if(_core == core)
00243         return;
00244 
00245     if(_core != NullFC)
00246         subRefCP(_core);
00247 
00248     _core = core;
00249 
00250     if(_core != NullFC)
00251         addRefCP(_core);
00252 }
00253 
00254 template< class Core > inline
00255 void CoredNodePtr<Core>::setCore(const NullFieldContainerPtr&)
00256 {
00257     if(_core != NullFC)
00258         subRefCP(_core);
00259 
00260     _core = NullFC;
00261 }
00262 
00263 template< class Core > inline
00264 void CoredNodePtr<Core>::updateNode(void)
00265 {
00266     if(node() == NullFC)
00267     {
00268         setNode(Node::create());
00269     }
00270 
00271     beginEditCP(node(), Node::CoreFieldMask);
00272     node()->setCore(_core);
00273     endEditCP(node(), Node::CoreFieldMask); 
00274 }
00275 
00276 
00277 // begin/endEdit functions. 
00278 
00279 template< class Core > inline
00280 void beginEditCP(const CoredNodePtr<Core> &objectP, 
00281                        BitVector         whichField,
00282                        UInt32            origin)
00283 {
00284     beginEditCP(objectP.node(), whichField, origin);
00285     beginEditCP(objectP.core(), whichField, origin);   
00286 }
00287 
00288 template< class Core > inline
00289 void endEditCP  (const CoredNodePtr<Core> &objectP, 
00290                        BitVector         whichField,
00291                        UInt32            origin)
00292 {
00293     endEditCP(objectP.node(), whichField, origin);
00294     endEditCP(objectP.core(), whichField, origin);   
00295 }
00296 
00297 
00298 // Output operator
00299 
00300 template< class Core >
00301 inline std::ostream &operator << (std::ostream &str, 
00302                                   const CoredNodePtr<Core>& cnp)
00303 {
00304     str << "CoredNodePtr<" << Core::getClassType().getName()
00305         << ">: Node: ";
00306     if(cnp.node())
00307     {
00308         str << cnp.node();
00309     }
00310     else
00311     {
00312         str << "(unset)";
00313     }
00314     
00315     str << " Core: ";
00316     if(cnp.node() && cnp.core())
00317     {
00318         str << cnp.core();
00319     }
00320     else
00321     {
00322         str << "(unset)";
00323     }
00324     
00325     return str;
00326 }
00327 
00328 OSG_END_NAMESPACE
00329 
00330 #define OSGCOREDNODEPTR_INLINE_CVSID "@(#)$Id: OSGCoredNodePtr.inl,v 1.5 2005/05/31 19:53:45 dirk Exp $"
00331 

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