library of assembled shared sources

http://lass.cocamware.com

callback_r_7.h

Go to the documentation of this file.
00001 /*
00002  * *** ATTENTION!  DO NOT MODIFY THIS FILE DIRECTLY! ***
00003  * 
00004  * It has automatically been generated from callback_r_x.tmpl.h
00005  * by param_expander.py on Sun Nov 09 16:55:49 2008.
00006  */
00007 
00008 /** @file
00009  *  @author Bram de Greve (bramz@users.sourceforge.net)
00010  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00011  *
00012  *  *** BEGIN LICENSE INFORMATION ***
00013  *  
00014  *  The contents of this file are subject to the Common Public Attribution License 
00015  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00016  *  the License. You may obtain a copy of the License at 
00017  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00018  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00019  *  use of software over a computer network and provide for limited attribution for 
00020  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00021  *  with Exhibit B.
00022  *  
00023  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00024  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00025  *  language governing rights and limitations under the License.
00026  *  
00027  *  The Original Code is LASS - Library of Assembled Shared Sources.
00028  *  
00029  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00030  *  The Original Developer is the Initial Developer.
00031  *  
00032  *  All portions of the code written by the Initial Developer are:
00033  *  Copyright (C) 2004-2007 the Initial Developer.
00034  *  All Rights Reserved.
00035  *  
00036  *  Contributor(s):
00037  *
00038  *  Alternatively, the contents of this file may be used under the terms of the 
00039  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00040  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00041  *  of your version of this file only under the terms of the GPL and not to allow 
00042  *  others to use your version of this file under the CPAL, indicate your decision by 
00043  *  deleting the provisions above and replace them with the notice and other 
00044  *  provisions required by the GPL License. If you do not delete the provisions above,
00045  *  a recipient may use your version of this file under either the CPAL or the GPL.
00046  *  
00047  *  *** END LICENSE INFORMATION ***
00048  */
00049 
00050 
00051 
00052 /** @class lass::util::CallbackR7
00053  *  @ingroup Callback
00054  *  @brief callback with 7 parameter7 and with returnvalue.
00055  *  @date 2002
00056  *  @author Bram de Greve [Bramz] (contact: bramz@users.sourceforge.net)
00057  *
00058  *  It's a single object that can hold a reference to a free function or an
00059  *  object/(const) method pair.  Once the callback is constructed, it works
00060  *  completely transparent.  All it shows to the client is a function that
00061  *  takes 7 parameter(s) and gives a returnvalue.
00062  */
00063 
00064 
00065 
00066 #ifndef LASS_GUARDIAN_OF_INCLUSION_UTIL_CALLBACK_R_7_H
00067 #define LASS_GUARDIAN_OF_INCLUSION_UTIL_CALLBACK_R_7_H
00068 
00069 
00070 
00071 // --- OLD INTERFACES ----------------------------------------------------------
00072 
00073 #include "util_common.h"
00074 #include "shared_ptr.h"
00075 #include "callback_common.h"
00076 #include "impl/dispatcher_r_7.h"
00077 
00078 
00079 
00080 
00081 // --- NEW INTERFACES ----------------------------------------------------------
00082 
00083 namespace lass
00084 {
00085 namespace util
00086 {
00087 
00088 
00089 // THE CALLBACK:
00090 // This is the actuall class you use to hold callbacks:
00091 
00092 template
00093 <
00094     typename R, 
00095     typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7
00096 >
00097 class CallbackR7
00098 {
00099 public:
00100 
00101     typedef CallbackR7<R, P1, P2, P3, P4, P5, P6, P7> TSelf;
00102     typedef SharedPtr< impl::DispatcherR7<R, P1, P2, P3, P4, P5, P6, P7> > TDispatcherPtr;
00103 
00104     // STRUCTORS
00105 
00106     /** Default constructor, construct empty callback.
00107      */
00108     CallbackR7()
00109     {
00110     }
00111 
00112     /** Construct function callback
00113      */
00114     template <typename FunctionType>
00115     CallbackR7(FunctionType iFunction):
00116         dispatcher_(new impl::DispatcherR7Function<R, P1, P2, P3, P4, P5, P6, P7, FunctionType>(iFunction))
00117     {
00118     }
00119 
00120     /** Construct object/method callback.
00121      */
00122     template <typename ObjectPtr, typename Method>
00123     CallbackR7(ObjectPtr iObject, Method iMethod):
00124         dispatcher_(new impl::DispatcherR7Method<R, P1, P2, P3, P4, P5, P6, P7, ObjectPtr, Method>(iObject, iMethod))
00125     {
00126     }
00127 
00128     /** copy constructor
00129      */
00130     CallbackR7(const TSelf& iOther):
00131         dispatcher_(iOther.dispatcher_)
00132     {
00133     }
00134 
00135 
00136 
00137     // OPERATORS
00138 
00139     /** assignment operator
00140      */
00141     template <typename Other>
00142     TSelf& operator=(const Other& iOther)
00143     {
00144         TSelf temp(iOther);
00145         swap(temp);
00146         return *this;
00147     }
00148 
00149     /** THE operator.  Executes the callback.
00150      */
00151     R operator()(typename util::CallTraits<P1>::TParam iP1, typename util::CallTraits<P2>::TParam iP2, typename util::CallTraits<P3>::TParam iP3, typename util::CallTraits<P4>::TParam iP4, typename util::CallTraits<P5>::TParam iP5, typename util::CallTraits<P6>::TParam iP6, typename util::CallTraits<P7>::TParam iP7) const
00152     {
00153         if (isEmpty())
00154         {
00155             LASS_THROW_EX(EmptyCallback, "You've tried to call an empty CallbackR7.  Can't return a value.");
00156         }
00157         return dispatcher_->call(iP1, iP2, iP3, iP4, iP5, iP6, iP7);
00158     }
00159 
00160 
00161     // METHODS
00162 
00163     /** Reset to empty callback.
00164      */
00165     void reset()
00166     {
00167         dispatcher_.reset();
00168     }
00169 
00170     /** Returns true if no callback dispatcher is assigned to this object.
00171      */
00172     bool isEmpty() const
00173     {
00174         return dispatcher_.isEmpty();
00175     }
00176 
00177     /** return this->isEmpty()
00178      */
00179     bool operator!() const
00180     {
00181         return dispatcher_.isEmpty(); 
00182     }
00183 
00184     /** return !this->isEmpty())
00185      */
00186     operator num::SafeBool() const
00187     {
00188         return dispatcher_.isEmpty() ? num::safeFalse : num::safeTrue;
00189     }
00190 
00191     /** Swaps the dispatcher of this callback with the dispatcher of another.
00192      */
00193     void swap(TSelf& iOther)
00194     {
00195         dispatcher_.swap(iOther.dispatcher_);
00196     }
00197 
00198 private:
00199 
00200     TDispatcherPtr dispatcher_;
00201 };
00202 
00203 
00204 
00205 /** make a CallbackR7 from a function
00206  *  @relates CallbackR7
00207  */
00208 template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7> inline
00209 CallbackR7<R, P1, P2, P3, P4, P5, P6, P7> makeCallback(R (*iFunction)(P1, P2, P3, P4, P5, P6, P7))
00210 {
00211     return CallbackR7<R, P1, P2, P3, P4, P5, P6, P7>(iFunction);
00212 }
00213 
00214 
00215 
00216 /** make a CallbackR7 from a function
00217  *  @relates CallbackR7
00218  */
00219 template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7> inline
00220 const CallbackR7<R, P1, P2, P3, P4, P5, P6, P7>& makeCallback(const CallbackR7<R, P1, P2, P3, P4, P5, P6, P7>& iCallback)
00221 {
00222     return iCallback;
00223 }
00224 
00225 
00226 
00227 /** make a CallbackR7 from a object and method
00228  *  @relates CallbackR7
00229  */
00230 template <typename ObjectPtr, typename Object, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7> inline
00231 CallbackR7<R, P1, P2, P3, P4, P5, P6, P7> makeCallback(ObjectPtr iObject, R (Object::*iMethod)(P1, P2, P3, P4, P5, P6, P7))
00232 {
00233     return CallbackR7<R, P1, P2, P3, P4, P5, P6, P7>(iObject, iMethod);
00234 }
00235 
00236 
00237 
00238 /** make a CallbackR7 from a object and const method
00239  *  @relates CallbackR7
00240  */
00241 template <typename ObjectPtr, typename Object, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7> inline
00242 CallbackR7<R, P1, P2, P3, P4, P5, P6, P7> makeCallback(ObjectPtr iObject, R (Object::*iMethod)(P1, P2, P3, P4, P5, P6, P7) const)
00243 {
00244     return CallbackR7<R, P1, P2, P3, P4, P5, P6, P7>(iObject, iMethod);
00245 }
00246 
00247 
00248 
00249 }
00250 
00251 }
00252 
00253 #define LASS_PRIM_HAVE_PY_EXPORT_TRAITS_CALLBACK_R7
00254 #ifdef LASS_GUARDIAN_OF_INCLUSION_UTIL_CALLBACK_PYTHON_H
00255 #   include "callback_python.h"
00256 #endif
00257 
00258 #endif // Guardian of Inclusion
00259 
00260 // EOF

Generated on Mon Nov 10 14:20:01 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo