00001 /*---------------------------------------------------------------------------*\ 00002 * OpenSG * 00003 * * 00004 * * 00005 * Copyright (C) 2000-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 OSG_BEGIN_NAMESPACE 00040 00041 /*-------------------------------------------------------------------------*/ 00042 /* Constructors */ 00043 00044 inline 00045 MultiFunctorStore::MultiFunctorStore(void) 00046 : _funcStore ( ), 00047 _funcMap ( ), 00048 _defaultFunc ( ), 00049 _bHasDefaultFunctor(false) 00050 { 00051 } 00052 00053 /*-------------------------------------------------------------------------*/ 00054 /* Destructor */ 00055 00056 inline 00057 MultiFunctorStore::~MultiFunctorStore(void) 00058 { 00059 } 00060 00061 /*-------------------------------------------------------------------------*/ 00062 /* Empty */ 00063 00064 inline bool 00065 MultiFunctorStore::empty(void) const 00066 { 00067 return _funcStore.empty() && !_bHasDefaultFunctor; 00068 } 00069 00070 /*-------------------------------------------------------------------------*/ 00071 /* Functor Registration */ 00072 00073 inline void 00074 MultiFunctorStore::regFunctor(const Functor &refFunc, 00075 const FieldContainerType &refType) 00076 { 00077 _funcStore.push_front(refFunc); 00078 00079 if(_funcMap.size() <= refType.getId()) 00080 { 00081 _funcMap.resize(refType.getId() + 1, _funcStore.end()); 00082 } 00083 00084 _funcMap[refType.getId()] = _funcStore.begin(); 00085 } 00086 00087 inline void 00088 MultiFunctorStore::unregFunctor(const FieldContainerType &refType) 00089 { 00090 FunctorStoreIt funcIter = _funcMap[refType.getId()]; 00091 00092 if(funcIter != _funcStore.end()) 00093 _funcStore.erase(funcIter); 00094 00095 _funcMap[refType.getId()] = _funcStore.end(); 00096 } 00097 00098 inline void 00099 MultiFunctorStore::regDefaultFunctor(const Functor &refFunc) 00100 { 00101 _defaultFunc = refFunc; 00102 _bHasDefaultFunctor = true; 00103 } 00104 00105 inline void 00106 MultiFunctorStore::unregDefaultFunctor(void) 00107 { 00108 _bHasDefaultFunctor = false; 00109 } 00110 00111 /*-------------------------------------------------------------------------*/ 00112 /* Functor Access */ 00113 00114 inline MultiFunctorStore::Functor * 00115 MultiFunctorStore::getFunctor(const FieldContainerType &refType) 00116 { 00117 Functor *pRetFunc = NULL; 00118 FunctorStoreIt funcIter = _funcStore.end(); 00119 00120 if(refType.getId() < _funcMap.size()) 00121 { 00122 funcIter = _funcMap[refType.getId()]; 00123 } 00124 00125 if(funcIter != _funcStore.end()) 00126 { 00127 pRetFunc = &(*funcIter); 00128 } 00129 else if(_bHasDefaultFunctor) 00130 { 00131 pRetFunc = &_defaultFunc; 00132 } 00133 00134 return pRetFunc; 00135 } 00136 00137 inline MultiFunctorStore::Functor * 00138 MultiFunctorStore::getDefaultFunctor(void) 00139 { 00140 Functor *pRetFunc = NULL; 00141 00142 if(_bHasDefaultFunctor) 00143 { 00144 pRetFunc = &_defaultFunc; 00145 } 00146 00147 return pRetFunc; 00148 } 00149 00150 OSG_END_NAMESPACE 00151 00152 #define OSGMULTIFUNCTORSTORE_INLINE_CVSID "@(#)$Id: OSGMultiFunctorStore.inl,v 1.5 2004/04/20 13:47:08 neumannc Exp $"
1.4.3