signal_source_obj_mem.h

Go to the documentation of this file.
00001 #ifndef _SIGX_SIGNAL_SOURCE_OBJ_MEM_HPP_
00002 #define _SIGX_SIGNAL_SOURCE_OBJ_MEM_HPP_
00003 
00004 /*
00005  * Copyright 2005 Klaus Triendl
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Library General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Library General Public
00018  * License along with this library; if not, write to the Free 
00019  * Software Foundation, 51 Franklin Street, Fifth Floor, 
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #include <sigc++/functors/functor_trait.h>
00024 #include <sigxconfig.h>
00025 #include <sigx/signal_source_base.h>
00026 
00027 
00028 namespace sigx
00029 {
00030 
00033 template<typename T_obj, typename T_signal>
00034 struct signal_source_obj_mem: public signal_source_base
00035 {
00036     typedef signal_source_obj_mem<T_obj, T_signal> self_type;
00037     typedef T_signal T_obj::*typed_signal_ptr;
00038 
00039     signal_source_obj_mem(T_obj* _A_obj, typed_signal_ptr _A_sig): 
00040         signal_source_base(reinterpret_cast<hook>(&self_type::get_signal)), 
00041         m_obj(_A_obj), 
00042         m_sig(_A_sig)
00043     {}
00044     
00045     static T_signal get_signal(signal_source_ptr base)
00046     {
00047         self_type* const this_ = static_cast<self_type*>(base);
00048         const typed_signal_ptr sig = this_->m_sig;
00049         return this_->m_obj->*sig;
00050     }
00051     
00052     T_obj* m_obj;
00053     typed_signal_ptr m_sig;
00054 };
00055 
00059 template<typename T_obj, typename T_signal>
00060 struct signal_source_pobj_mem: public signal_source_base
00061 {
00062     typedef signal_source_pobj_mem<T_obj, T_signal> self_type;
00063     typedef T_signal T_obj::*typed_signal_ptr;
00064 
00065     signal_source_pobj_mem(T_obj* const& _A_obj, typed_signal_ptr _A_sig): 
00066         signal_source_base(reinterpret_cast<hook>(&self_type::get_signal)), 
00067         m_obj(_A_obj), 
00068         m_sig(_A_sig)
00069     {}
00070     
00071     static T_signal get_signal(signal_source_ptr base)
00072     {
00073         self_type* const this_ = static_cast<self_type*>(base);
00074         const typed_signal_ptr sig = this_->m_sig;
00075         return this_->m_obj->*sig;
00076     }
00077     
00078     T_obj* const& m_obj;
00079     typed_signal_ptr m_sig;
00080 };
00081 
00086 template<typename T_obj, typename T_functor, typename T_signal>
00087 struct signal_source_pobj_mem_fun: public signal_source_base
00088 {
00089     typedef signal_source_pobj_mem_fun<T_obj, T_functor, T_signal> self_type;
00090     typedef typename sigc::functor_trait<T_functor>::functor_type functor_type;
00091 
00092     signal_source_pobj_mem_fun(T_obj* const& _A_obj, const T_functor& _A_mem_func): 
00093         signal_source_base(reinterpret_cast<hook>(&self_type::get_signal)), 
00094         m_obj(_A_obj), 
00095         m_mem_func(_A_mem_func)
00096     {}
00097     
00098     static T_signal get_signal(signal_source_ptr base)
00099     {
00100         self_type* this_ = static_cast<self_type*>(base);
00101         return this_->m_mem_func(this_->m_obj);
00102     }
00103     
00104     T_obj* const& m_obj;
00105     functor_type m_mem_func;
00106 };
00107 
00108 
00109 } // namespace sigx
00110 
00111 
00112 #endif // _SIGX_SIGNAL_SOURCE_OBJ_MEM_HPP_

Generated on Wed Jan 28 21:37:59 2009 for sigx++ by  doxygen 1.5.8