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 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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. (A more detailed explanation is that 00054 * it is used where a virtual function is at the end of a call chain, 00055 * notably the dispatch() method of callback objects, with the result 00056 * that we cannot templatise the virtual function itself in order to 00057 * use std::forward for argument passing, but instead have to type-map 00058 * the arguments using class templates.) 00059 * 00060 * Mapping is as follows: 00061 * 00062 * A value argument is mapped to reference to const of the value 00063 * type. 00064 * 00065 * A pointer argument is mapped to pointer argument (its original 00066 * type). 00067 * 00068 * A non-const reference argument is mapped to non-const reference 00069 * (its original type). 00070 * 00071 * A const reference argument is mapped to const reference (its 00072 * original type). 00073 */ 00074 00075 template<class T> 00076 struct Param { 00077 typedef const T& ParamType; 00078 }; 00079 00080 template<class T> 00081 struct Param<T&> { 00082 typedef T& ParamType; 00083 }; 00084 00085 template<class T> 00086 struct Param<T*> { 00087 typedef T* ParamType; 00088 }; 00089 00090 /** 00091 * @class RemoveRefCond param.h c++-gtk-utils/param.h 00092 * @brief Struct which will conditionally convert a reference type to 00093 * a value type 00094 * 00095 * @details This struct is used by Callback::make(), 00096 * Callback::make_val() and Callback::make_ref() so that where a call 00097 * is made to Callback::make_ref() and the target function's arguments 00098 * include one with a reference, that reference is removed. 00099 * 00100 * Since 2.0.0-rc3 00101 */ 00102 template<class T, bool unref> 00103 struct RemoveRefCond {}; 00104 00105 template<class T> 00106 struct RemoveRefCond<T, true> { 00107 typedef T Type; 00108 }; 00109 00110 template<class T> 00111 struct RemoveRefCond<T&, true> { 00112 typedef T Type; 00113 }; 00114 00115 template<class T> 00116 struct RemoveRefCond<T, false> { 00117 typedef T Type; 00118 }; 00119 00120 // explicatory only - we could do without this specialisation 00121 template<class T> 00122 struct RemoveRefCond<T&, false> { 00123 typedef T& Type; 00124 }; 00125 00126 } // namespace Cgu 00127 00128 #endif // CGU_PARAM_H