00001 /*************************************************************************** 00002 * Copyright (C) 2005-2011 LpzRobots development team * 00003 * Georg Martius <georg dot martius at web dot de> * 00004 * Frank Guettler <guettler at informatik dot uni-leipzig dot de * 00005 * Frank Hesse <frank at nld dot ds dot mpg dot de> * 00006 * Ralf Der <ralfder at mis dot mpg dot de> * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the * 00020 * Free Software Foundation, Inc., * 00021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00022 * * 00023 ***************************************************************************/ 00024 00025 #ifndef __BACKCALLERVECTOR_H_ 00026 #define __BACKCALLERVECTOR_H_ 00027 00028 #include <vector> 00029 00030 /** 00031 * Establishes for some methods the notifications for registered Callbackable instances 00032 * (use addCallbackable(...)). 00033 * @warning Only the following methods are currently supported: 00034 push_back(...), pop_back(), erase() and clear()! 00035 * You can use iterators with the limitation to not delete or insert. 00036 */ 00037 template<typename _Tp, typename _Alloc = std::allocator<_Tp> > 00038 class BackCallerVector : public std::vector<_Tp,_Alloc>, public BackCaller { 00039 public: 00040 00041 typedef typename std::vector<_Tp,_Alloc>::iterator iterator; 00042 00043 BackCallerVector() {} 00044 virtual ~BackCallerVector(){ 00045 callBack(BACKCALLER_VECTOR_BEING_DELETED); 00046 } 00047 00048 /** 00049 * Indicates that the list/vector has been modified, 00050 a new instance was either added or removed. 00051 */ 00052 static const CallbackableType BACKCALLER_VECTOR_MODIFIED = 10219; 00053 00054 /** 00055 * Indicates that the list is being deleted. 00056 */ 00057 static const CallbackableType BACKCALLER_VECTOR_BEING_DELETED = 10220; 00058 00059 00060 void push_back(const _Tp & i){ 00061 std::vector<_Tp,_Alloc>::push_back(i); 00062 callBack(BACKCALLER_VECTOR_MODIFIED); 00063 } 00064 00065 iterator erase(iterator pos){ 00066 iterator i = std::vector<_Tp,_Alloc>::erase(pos); 00067 callBack(BACKCALLER_VECTOR_MODIFIED); 00068 return i; 00069 } 00070 00071 void pop_back(){ 00072 std::vector<_Tp,_Alloc>::pop_back(); 00073 callBack(BACKCALLER_VECTOR_MODIFIED); 00074 } 00075 00076 void clear(){ 00077 std::vector<_Tp,_Alloc>::clear(); 00078 callBack(BACKCALLER_VECTOR_MODIFIED); 00079 } 00080 }; 00081 00082 #endif /* __BACKCALLERVECTOR_H_ */ 00083