← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2869: different function checking sfinae that works with inherited functions

 

------------------------------------------------------------
revno: 2869
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sat 2012-02-18 00:34:33 +0100
message:
  different function checking sfinae that works with inherited functions
modified:
  changelog.txt
  dcpp/Util.h
  win32/HubFrame.h
  win32/TransferView.h
  win32/TypedTable.h
  win32/UsersFrame.h


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt	2012-02-12 15:34:48 +0000
+++ changelog.txt	2012-02-17 23:34:33 +0000
@@ -20,6 +20,7 @@
 * [L#925659] Safer window cleanup (poy)
 * [L#923612] Show the last chat line in taskbar previews (poy)
 * Show chat logs with a dim text color (poy)
+* Re-add lost user information tooltips (poy)
 
 -- 0.791 2012-01-14 --
 * Update translations

=== modified file 'dcpp/Util.h'
--- dcpp/Util.h	2012-01-15 16:08:29 +0000
+++ dcpp/Util.h	2012-02-17 23:34:33 +0000
@@ -89,17 +89,30 @@
 template<typename T> inline double fraction(T a, T b) { return static_cast<double>(a) / b; }
 
 /** Uses SFINAE to determine whether a type provides a function; stores the result in "value".
-Inspired by <http://stackoverflow.com/questions/257288#264088>. */
-/// @todo simplify when MSVC supports default template arguments on functions...
-#define HAS_FUNC(name, func, signature) \
-	template<typename T> struct name { \
-		typedef char yes[1]; \
-		typedef char no[2]; \
-		template<typename U, U> struct type_check; \
-		template<typename U> static yes& check(type_check<signature, &U::func>*); \
-		template<typename> static no& check(...); \
-		enum { value = sizeof(check<T>(0)) == sizeof(yes) }; \
-	}
+Inspired by <http://stackoverflow.com/a/8752988>. */
+/// @todo simplify callers when MSVC supports default template arguments on functions...
+#ifndef _MSC_VER
+#define HAS_FUNC(name, funcRet, funcTest) \
+	template<typename HAS_FUNC_T> struct name { \
+		typedef char yes[1]; \
+		typedef char no[2]; \
+		template<typename HAS_FUNC_U> static yes& check(HAS_FUNC_U* data, \
+			typename std::enable_if<std::is_same<funcRet, decltype(data->funcTest)>::value>::type* = nullptr); \
+		template<typename> static no& check(...); \
+		static const bool value = sizeof(check<HAS_FUNC_T>(nullptr)) == sizeof(yes); \
+	}
+#else
+/// @todo don't verify the return type of the function on MSVC as it fails for obscure reasons. recheck on VC11...
+#define HAS_FUNC(name, funcRet, funcTest) \
+	template<typename HAS_FUNC_T> struct name { \
+		typedef char yes[1]; \
+		typedef char no[2]; \
+		template<typename HAS_FUNC_U> static yes& check(HAS_FUNC_U* data, \
+			decltype(data->funcTest)* = nullptr); \
+		template<typename> static no& check(...); \
+		static const bool value = sizeof(check<HAS_FUNC_T>(nullptr)) == sizeof(yes); \
+	}
+#endif
 
 class Util
 {

=== modified file 'win32/HubFrame.h'
--- win32/HubFrame.h	2012-02-01 16:26:37 +0000
+++ win32/HubFrame.h	2012-02-17 23:34:33 +0000
@@ -121,7 +121,6 @@
 		}
 		int getImage(int col) const;
 		int getStyle(HFONT& font, COLORREF& textColor, COLORREF& bgColor, int) const;
-		using UserInfoBase::getTooltip;
 
 		static int compareItems(const UserInfo* a, const UserInfo* b, int col);
 		bool update(const Identity& identity, int sortCol);

=== modified file 'win32/TransferView.h'
--- win32/TransferView.h	2012-01-13 20:55:20 +0000
+++ win32/TransferView.h	2012-02-17 23:34:33 +0000
@@ -133,7 +133,6 @@
 		int getImage(int col) const {
 			return col == 0 ? (download ? IMAGE_DOWNLOAD : IMAGE_UPLOAD) : -1;
 		}
-		using UserInfoBase::getTooltip;
 
 		static int compareItems(const ConnectionInfo* a, const ConnectionInfo* b, int col);
 	};

=== modified file 'win32/TypedTable.h'
--- win32/TypedTable.h	2012-01-13 20:55:20 +0000
+++ win32/TypedTable.h	2012-02-17 23:34:33 +0000
@@ -169,25 +169,23 @@
 	}
 
 private:
-	HAS_FUNC(HasText_, getText, const tstring& (ContentType::*)(int));
-	HAS_FUNC(HasTextC_, getText, const tstring& (ContentType::*)(int) const);
-#define HasText (HasText_<T>::value || HasTextC_<T>::value)
-
-	HAS_FUNC(HasImage_, getImage, int (ContentType::*)(int));
-	HAS_FUNC(HasImageC_, getImage, int (ContentType::*)(int) const);
-#define HasImage (HasImage_<T>::value || HasImageC_<T>::value)
-
-	HAS_FUNC(HasSort_, compareItems, int (*)(ContentType*, ContentType*, int));
-	HAS_FUNC(HasSortC_, compareItems, int (*)(const ContentType*, const ContentType*, int));
-#define HasSort (HasSort_<T>::value || HasSortC_<T>::value)
-
-	HAS_FUNC(HasStyle_, getStyle, int (ContentType::*)(HFONT&, COLORREF&, COLORREF&, int));
-	HAS_FUNC(HasStyleC_, getStyle, int (ContentType::*)(HFONT&, COLORREF&, COLORREF&, int) const);
-#define HasStyle (HasStyle_<T>::value || HasStyleC_<T>::value)
-
-	HAS_FUNC(HasTooltip_, getTooltip, tstring (ContentType::*)());
-	HAS_FUNC(HasTooltipC_, getTooltip, tstring (ContentType::*)() const);
-#define HasTooltip (HasTooltip_<T>::value || HasTooltipC_<T>::value)
+	/// @todo simplify all these if/when the next C++ standard has static if or concepts...
+
+	HAS_FUNC(HasText_, const tstring&, getText(0));
+#define HasText HasText_<T>::value
+
+	HAS_FUNC(HasImage_, int, getImage(0));
+#define HasImage HasImage_<T>::value
+
+	HAS_FUNC(HasSort_, int, compareItems(nullptr, nullptr, 0));
+#define HasSort HasSort_<T>::value
+
+	// over-complicated to test for lvalue refs...
+	HAS_FUNC(HasStyle_, int, getStyle(std::function<HFONT&()>()(), std::function<COLORREF&()>()(), std::function<COLORREF&()>()(), 0));
+#define HasStyle HasStyle_<T>::value
+
+	HAS_FUNC(HasTooltip_, tstring, getTooltip());
+#define HasTooltip HasTooltip_<T>::value
 
 	template<typename T> typename std::enable_if<HasText, void>::type addTextEvent() {
 		this->onRaw([this](WPARAM, LPARAM lParam) -> LRESULT {

=== modified file 'win32/UsersFrame.h'
--- win32/UsersFrame.h	2012-01-13 20:55:20 +0000
+++ win32/UsersFrame.h	2012-02-17 23:34:33 +0000
@@ -95,7 +95,6 @@
 			default: return -1;
 			}
 		}
-		using UserInfoBase::getTooltip;
 
 		static int compareItems(const UserInfo* a, const UserInfo* b, int col) {
 			switch(col) {