00001 /* 00002 * lib-controler : Un contrôleur générique de scène 3D. 00003 * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC 00004 * http://www.sic.sp2mi.univ-poitiers.fr/ 00005 * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS, 00006 * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/ 00007 * 00008 * This file is part of lib-controler 00009 * 00010 * This program is free software: you can redistribute it and/or modify 00011 * it under the terms of the GNU Lesser General Public License as published by 00012 * the Free Software Foundation, either version 3 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public License 00021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 00024 //****************************************************************************** 00025 #include "parameter.hh" 00026 #include "precompile.hh" 00027 #include "controler-types.hh" 00028 #include <cassert> 00029 using namespace std; 00030 //****************************************************************************** 00031 CParameter::CParameter(unsigned int ANbRef) : 00032 FNbRef(ANbRef) 00033 { 00034 } 00035 //****************************************************************************** 00036 CParameter::CParameter(const CParameter & AParameter) : 00037 FNbRef(0) 00038 { 00039 } 00040 //****************************************************************************** 00041 CParameter::~CParameter() 00042 { 00043 } 00044 //****************************************************************************** 00045 void CParameter::incNbRef(unsigned int AValue) 00046 { FNbRef += AValue; } 00047 //****************************************************************************** 00048 void CParameter::decNbRef(unsigned int AValue) 00049 { 00050 assert(FNbRef >= AValue); 00051 00052 FNbRef -= AValue; 00053 if ( FNbRef==0 ) delete this; 00054 } 00055 //****************************************************************************** 00056 unsigned int CParameter::getNbRef() const 00057 { return FNbRef; } 00058 //****************************************************************************** 00059 void CParameter::addPrecompileToUpdate(CPrecompile * APrecompile) 00060 { 00061 assert(APrecompile != NULL); 00062 00063 FListPrecompile.push_back(APrecompile); 00064 incNbRef(); 00065 } 00066 //****************************************************************************** 00067 void CParameter::removePrecompileToUpdate(CPrecompile * APrecompile) 00068 { 00069 assert(APrecompile != NULL); 00070 bool found = false; 00071 00072 list<CPrecompile *>::iterator it= FListPrecompile.begin(); 00073 while(!found && it!=FListPrecompile.end()) 00074 { 00075 if (*it == APrecompile) 00076 { 00077 FListPrecompile.erase(it); 00078 found = true; 00079 } 00080 else 00081 ++it; 00082 } 00083 00084 if (found) decNbRef(); 00085 } 00086 //****************************************************************************** 00087 void CParameter::putAllNeedToUpdate() 00088 { 00089 list<CPrecompile *>::iterator it = FListPrecompile.begin(); 00090 while( it!=FListPrecompile.end() ) 00091 { 00092 (*it)->setToUpdate(); 00093 ++it; 00094 } 00095 } 00096 //******************************************************************************