NewNet/nnguardobject.h

00001 /*  NewNet - A networking framework in C++
00002     Copyright (C) 2006 Ingmar K. Steen (iksteen@gmail.com)
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018  */
00019 
00020 #ifndef NEWNET_GUARDOBJECT_H
00021 #define NEWNET_GUARDOBJECT_H
00022 
00023 #include <vector>
00024 #include <algorithm>
00025 
00026 namespace NewNet
00027 {
00028   class Object;
00029 
00031 
00034   class GuardObject
00035   {
00036   public:
00038 
00041     class Callback
00042     {
00043     public:
00044 #ifndef DOXYGEN_UNDOCUMENTED
00045       virtual ~Callback() {}
00046 #endif // DOXYGEN_UNDOCUMENTED
00047 
00049 
00050       virtual void operator()(Object * p) = 0;
00051     };
00052 
00054 
00055     GuardObject()
00056     {
00057     }
00058 
00059 #ifndef DOXYGEN_UNDOCUMENTED
00060     void emit(Object * p)
00061     {
00062       std::vector<Callback *>::iterator it, end = m_Callbacks.end();
00063       for(it = m_Callbacks.begin(); it != end; ++it)
00064         (*it)->operator()(p);
00065     }
00066 #endif // DOXYGEN_UNDOCUMENTED
00067 
00069 
00072     GuardObject & operator+=(Callback * p)
00073     {
00074       m_Callbacks.push_back(p);
00075       return *this;
00076     }
00077 
00079 
00083     GuardObject & operator-=(Callback * p)
00084     {
00085       m_Callbacks.erase(std::find(m_Callbacks.begin(), m_Callbacks.end(), p));
00086       return *this;
00087     }
00088 
00089   private:
00090     std::vector<Callback *> m_Callbacks;
00091   };
00092 }
00093 
00094 #endif // NEWNET_GUARDOBJECT_H

Generated on Sun Jan 7 14:00:01 2007 for NewNet by  doxygen 1.5.1