c++-gtk-utils
|
00001 /* Copyright (C) 2010 and 2011 Chris Vine 00002 00003 The library comprised in this file or of which this file is part is 00004 distributed by Chris Vine under the GNU Lesser General Public 00005 License as follows: 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public License 00009 as published by the Free Software Foundation; either version 2.1 of 00010 the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, but 00013 WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License, version 2.1, for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License, version 2.1, along with this library (see the file LGPL.TXT 00019 which came with this source code package in the c++-gtk-utils 00020 sub-directory); if not, write to the Free Software Foundation, Inc., 00021 59 Temple Place - Suite 330, Boston, MA, 02111-1307, USA. 00022 00023 However, it is not intended that the object code of a program whose 00024 source code instantiates a template from this file or uses macros or 00025 inline functions (of any length) should by reason only of that 00026 instantiation or use be subject to the restrictions of use in the GNU 00027 Lesser General Public License. With that in mind, the words "and 00028 macros, inline functions and instantiations of templates (of any 00029 length)" shall be treated as substituted for the words "and small 00030 macros and small inline functions (ten lines or less in length)" in 00031 the fourth paragraph of section 5 of that licence. This does not 00032 affect any other reason why object code may be subject to the 00033 restrictions in that licence (nor for the avoidance of doubt does it 00034 affect the application of section 2 of that licence to modifications 00035 of the source code in this file). 00036 00037 */ 00038 00039 #ifndef CGU_PARAM_H 00040 #define CGU_PARAM_H 00041 00042 #include <c++-gtk-utils/cgu_config.h> 00043 00044 namespace Cgu { 00045 00046 /** 00047 * @class Param param.h c++-gtk-utils/param.h 00048 * @brief Struct for automatic typing of function parameter arguments 00049 * 00050 * @details This struct uses template partial specialisation in order 00051 * to provide automatic type mapping for function arguments. It is 00052 * used by the unbound arguments of callback objects and their related 00053 * functors and emitter objects. 00054 * 00055 * Mapping is as follows: 00056 * 00057 * A value argument is mapped to reference to const of the value 00058 * type. 00059 * 00060 * A pointer argument is mapped to pointer argument (its original 00061 * type). 00062 * 00063 * A non-const reference argument is mapped to non-const reference 00064 * (its original type). 00065 * 00066 * A const reference argument is mapped to const reference (its 00067 * original type). 00068 */ 00069 00070 template<class T> 00071 struct Param { 00072 typedef const T& ParamType; 00073 }; 00074 00075 template<class T> 00076 struct Param<T&> { 00077 typedef T& ParamType; 00078 }; 00079 00080 template<class T> 00081 struct Param<T*> { 00082 typedef T* ParamType; 00083 }; 00084 00085 /** 00086 * @class RemoveRefCond param.h c++-gtk-utils/param.h 00087 * @brief Struct which will conditionally convert a reference type to 00088 * a value type 00089 * 00090 * @details This struct is used by Callback::make(), 00091 * Callback::make_val() and Callback::make_ref() so that where a call 00092 * is made to Callback::make_ref() and the target function's arguments 00093 * include one with a reference, that reference is removed. 00094 * 00095 * Since 2.0.0-rc3 00096 */ 00097 template<class T, bool unref> 00098 struct RemoveRefCond {}; 00099 00100 template<class T> 00101 struct RemoveRefCond<T, true> { 00102 typedef T Type; 00103 }; 00104 00105 template<class T> 00106 struct RemoveRefCond<T&, true> { 00107 typedef T Type; 00108 }; 00109 00110 template<class T> 00111 struct RemoveRefCond<T, false> { 00112 typedef T Type; 00113 }; 00114 00115 // explicatory only - we could do without this specialisation 00116 template<class T> 00117 struct RemoveRefCond<T&, false> { 00118 typedef T& Type; 00119 }; 00120 00121 } // namespace Cgu 00122 00123 #endif // CGU_PARAM_H