00001 /*---------------------------------------------------------------------------*\ 00002 * OpenSG * 00003 * * 00004 * * 00005 * Copyright (C) 2000 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 //--------------------------------------------------------------------------- 00040 // Includes 00041 //--------------------------------------------------------------------------- 00042 00043 OSG_BEGIN_NAMESPACE 00044 00045 inline 00046 NodePtr Action::getActNode(void) 00047 { 00048 return _actNode; 00049 } 00050 00051 00052 inline 00053 void Action::setActNode(NodePtrConstArg node) 00054 { 00055 _actNode = node; 00056 } 00057 00058 inline 00059 NodePtr Action::getNode(int index) 00060 { 00061 if(_actList == NULL) 00062 { 00063 return _actNode->getChild(index); 00064 } 00065 else 00066 { 00067 return (*_actList)[index]; 00068 } 00069 } 00070 00071 inline 00072 void Action::addNode(NodePtrConstArg node) 00073 { 00074 _newList.push_back(node); 00075 } 00076 00077 inline 00078 void Action::useNodeList(void) 00079 { 00080 _useNewList = true; 00081 } 00082 00083 inline 00084 UInt32 Action::getNNodes(void) const 00085 { 00086 if(_actList == NULL) 00087 { 00088 return _actNode->getNChildren(); 00089 } 00090 else 00091 { 00092 return (*_actList).size(); 00093 } 00094 } 00095 00096 00097 inline 00098 UInt32 Action::getTravMask(void) const 00099 { 00100 return _travMask; 00101 } 00102 00103 inline 00104 void Action::setTravMask(UInt32 val) 00105 { 00106 _travMask = val; 00107 } 00108 00109 /*-------------------------- your_category---------------------------------*/ 00110 00111 // callEnter/callLeave: call the right functor. If the type is unknown and new 00112 // (i.e. its index is larger than the vector) try to find the function in the 00113 // default list. 00114 00115 inline 00116 ActionBase::ResultE Action::callEnter(NodeCorePtrConstArg core) 00117 { 00118 ResultE result; 00119 00120 UInt32 uiFunctorIndex = core->getType().getId(); 00121 00122 if(uiFunctorIndex < _enterFunctors.size()) 00123 { 00124 result = _enterFunctors[uiFunctorIndex](core, this); 00125 } 00126 else if(getDefaultEnterFunctors() && 00127 uiFunctorIndex < getDefaultEnterFunctors()->size()) 00128 { 00129 // field container registered method after this action was instantiated 00130 // copy the new functors from default vector 00131 00132 std::vector<Functor> *defaultEnter = getDefaultEnterFunctors(); 00133 00134 while(defaultEnter->size() > _enterFunctors.size()) 00135 { 00136 _enterFunctors.push_back((*defaultEnter)[_enterFunctors.size()]); 00137 } 00138 00139 result = _enterFunctors[uiFunctorIndex](core, this); 00140 } 00141 else // unknown field container 00142 { 00143 result = _defaultEnterFunction(core, this); 00144 } 00145 00146 return result; 00147 } 00148 00149 inline 00150 ActionBase::ResultE Action::callLeave(NodeCorePtrConstArg core) 00151 { 00152 ResultE result; 00153 00154 UInt32 uiFunctorIndex = core->getType().getId(); 00155 00156 if(uiFunctorIndex < _leaveFunctors.size()) 00157 { 00158 result = _leaveFunctors[uiFunctorIndex](core, this); 00159 } 00160 else if(getDefaultLeaveFunctors() && 00161 uiFunctorIndex < getDefaultLeaveFunctors()->size()) 00162 { 00163 // field container registered method after this action was instantiated 00164 // copy the new functors from default vector 00165 00166 std::vector<Functor> *defaultLeave = getDefaultLeaveFunctors(); 00167 00168 while(defaultLeave->size() > _leaveFunctors.size()) 00169 { 00170 _leaveFunctors.push_back((*defaultLeave)[_leaveFunctors.size()]); 00171 } 00172 00173 result = _leaveFunctors[uiFunctorIndex](core, this); 00174 } 00175 else // unknown field container 00176 { 00177 result = _defaultLeaveFunction(core, this); 00178 } 00179 00180 return result; 00181 } 00182 00183 /*-------------------------- assignment -----------------------------------*/ 00184 00189 /*-------------------------- comparison -----------------------------------*/ 00190 00204 /*-------------------------------------------------------------------------*\ 00205 - protected - 00206 \*-------------------------------------------------------------------------*/ 00207 00208 00209 00210 /*-------------------------------------------------------------------------*\ 00211 - private - 00212 \*-------------------------------------------------------------------------*/ 00213 00214 OSG_END_NAMESPACE