00001 /*---------------------------------------------------------------------------*\ 00002 * OpenSG * 00003 * * 00004 * * 00005 * Copyright (C) 2000-2002,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 #ifndef _OSGFIELDCONTAINERFACTORYIMPL_INL_ 00040 #define _OSGFIELDCONTAINERFACTORYIMPL_INL_ 00041 00042 #ifdef OSG_DOC_FILES_IN_MODULE 00043 00046 #endif 00047 00048 OSG_BEGIN_NAMESPACE 00049 00050 /*-------------------------------------------------------------------------*/ 00051 /* Mapper */ 00052 00053 inline 00054 void FieldContainerFactory::setMapper(FieldContainerMapper *pMapper) 00055 { 00056 _pMapper = pMapper; 00057 } 00058 00059 /*-------------------------------------------------------------------------*/ 00060 /* Get */ 00061 00062 inline 00063 FieldContainerPtr FieldContainerFactory::getContainer( 00064 UInt32 uiContainerId) const 00065 { 00066 FieldContainerPtr returnValue = NullFC; 00067 00068 _pStoreLock->aquire(); 00069 00070 if(uiContainerId < _pFieldContainerStore->size()) 00071 { 00072 returnValue = (*_pFieldContainerStore)[uiContainerId]; 00073 } 00074 00075 _pStoreLock->release(); 00076 00077 return returnValue; 00078 } 00079 00080 inline 00081 FieldContainerPtr FieldContainerFactory::getMappedContainer( 00082 UInt32 uiContainerId) const 00083 { 00084 if(_pMapper != NULL) 00085 { 00086 return getContainer(_pMapper->map(uiContainerId)); 00087 } 00088 else 00089 { 00090 return getContainer(uiContainerId); 00091 } 00092 } 00093 00094 /*-------------------------------------------------------------------------*/ 00095 /* Register */ 00096 00097 inline 00098 UInt32 FieldContainerFactory::registerFieldContainer( 00099 const FieldContainerPtr &pFieldContainer) 00100 { 00101 UInt32 returnValue = 0; 00102 00103 if(_pStoreLock != NULL) 00104 _pStoreLock->aquire(); 00105 00106 if(_pFieldContainerStore == NULL) 00107 { 00108 _pFieldContainerStore = new FieldContainerStore; 00109 00110 _pFieldContainerStore->push_back(NullFC); 00111 } 00112 00113 _pFieldContainerStore->push_back(pFieldContainer); 00114 00115 returnValue = _pFieldContainerStore->size() - 1; 00116 00117 if(_pStoreLock != NULL) 00118 _pStoreLock->release(); 00119 00120 return returnValue; 00121 } 00122 00123 inline 00124 bool FieldContainerFactory::unregisterFieldContainer( 00125 const FieldContainerPtr &pFieldContainer) 00126 { 00127 if(pFieldContainer == NullFC) 00128 return false; 00129 00130 if(_pStoreLock != NULL) 00131 _pStoreLock->aquire(); 00132 00133 if(_pFieldContainerStore != NULL) 00134 { 00135 #ifdef OSG_DEBUG 00136 if (pFieldContainer.getFieldContainerId() >= 00137 (*_pFieldContainerStore).size()) 00138 { 00139 FWARNING(("FieldContainerFactory::unregisterFieldContainer:" 00140 "id %d inconsistent with store size %d!\n", 00141 pFieldContainer.getFieldContainerId(), 00142 (*_pFieldContainerStore).size() )); 00143 return true; 00144 } 00145 else 00146 #endif 00147 00148 (*_pFieldContainerStore)[pFieldContainer.getFieldContainerId()] = 00149 NullFC; 00150 } 00151 00152 if(_pStoreLock != NULL) 00153 _pStoreLock->release(); 00154 00155 return false; 00156 } 00157 00158 OSG_END_NAMESPACE 00159 00160 #define OSGFIELDCONTAINERFACTORY_INLINE_CVSID "@(#)$Id: $" 00161 00162 #endif /* _OSGFIELDCONTAINERFACTORYIMPL_INL_ */
1.4.3