← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2687: TypedTable sfinae: accept non-const functions

 

------------------------------------------------------------
revno: 2687
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Mon 2011-11-21 20:04:08 +0100
message:
  TypedTable sfinae: accept non-const functions
modified:
  win32/DirectoryListingFrame.cpp
  win32/DirectoryListingFrame.h
  win32/FinishedFrameBase.h
  win32/SearchFrame.cpp
  win32/SearchFrame.h
  win32/TransferView.cpp
  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 'win32/DirectoryListingFrame.cpp'
--- win32/DirectoryListingFrame.cpp	2011-11-12 19:36:12 +0000
+++ win32/DirectoryListingFrame.cpp	2011-11-21 19:04:08 +0000
@@ -80,7 +80,7 @@
 	return WinUtil::getFileIcon(getText(COLUMN_FILENAME));
 }
 
-int DirectoryListingFrame::ItemInfo::compareItems(ItemInfo* a, ItemInfo* b, int col) {
+int DirectoryListingFrame::ItemInfo::compareItems(const ItemInfo* a, const ItemInfo* b, int col) {
 	if(a->type == DIRECTORY) {
 		if(b->type == DIRECTORY) {
 			switch(col) {

=== modified file 'win32/DirectoryListingFrame.h'
--- win32/DirectoryListingFrame.h	2011-10-17 19:39:46 +0000
+++ win32/DirectoryListingFrame.h	2011-11-21 19:04:08 +0000
@@ -145,7 +145,7 @@
 			int64_t total;
 		};
 
-		static int compareItems(ItemInfo* a, ItemInfo* b, int col);
+		static int compareItems(const ItemInfo* a, const ItemInfo* b, int col);
 	private:
 		tstring columns[COLUMN_LAST];
 	};

=== modified file 'win32/FinishedFrameBase.h'
--- win32/FinishedFrameBase.h	2011-11-12 19:36:12 +0000
+++ win32/FinishedFrameBase.h	2011-11-21 19:04:08 +0000
@@ -269,7 +269,7 @@
 			return col == 0 ? WinUtil::getFileIcon(file) : -1;
 		}
 
-		static int compareItems(FileInfo* a, FileInfo* b, int col) {
+		static int compareItems(const FileInfo* a, const FileInfo* b, int col) {
 			switch(col) {
 				case FILES_COLUMN_TRANSFERRED: return compare(a->entry->getTransferred(), b->entry->getTransferred());
 				case FILES_COLUMN_FILESIZE: return compare(a->entry->getFileSize(), b->entry->getFileSize());
@@ -350,7 +350,7 @@
 			return 0;
 		}
 
-		static int compareItems(UserInfo* a, UserInfo* b, int col) {
+		static int compareItems(const UserInfo* a, const UserInfo* b, int col) {
 			switch(col) {
 				case USERS_COLUMN_TRANSFERRED: return compare(a->entry->getTransferred(), b->entry->getTransferred());
 				case USERS_COLUMN_SPEED: return compare(a->entry->getAverageSpeed(), b->entry->getAverageSpeed());

=== modified file 'win32/SearchFrame.cpp'
--- win32/SearchFrame.cpp	2011-11-12 19:36:12 +0000
+++ win32/SearchFrame.cpp	2011-11-21 19:04:08 +0000
@@ -71,8 +71,7 @@
 	return sr->getType() == SearchResult::TYPE_FILE ? WinUtil::getFileIcon(sr->getFile()) : static_cast<int>(WinUtil::DIR_ICON);
 }
 
-int SearchFrame::SearchInfo::compareItems(SearchInfo* a, SearchInfo* b, int col) {
-
+int SearchFrame::SearchInfo::compareItems(const SearchInfo* a, const SearchInfo* b, int col) {
 	switch(col) {
 	case COLUMN_NICK:
 		if(a->srs.size() > 1 && b->srs.size() > 1)

=== modified file 'win32/SearchFrame.h'
--- win32/SearchFrame.h	2011-10-30 14:24:14 +0000
+++ win32/SearchFrame.h	2011-11-21 19:04:08 +0000
@@ -125,7 +125,7 @@
 		const tstring& getText(int col) const { return columns[col]; }
 		int getImage(int col) const;
 
-		static int compareItems(SearchInfo* a, SearchInfo* b, int col);
+		static int compareItems(const SearchInfo* a, const SearchInfo* b, int col);
 
 		void update();
 
@@ -146,7 +146,7 @@
 		int getImage(int) const {
 			return 0;
 		}
-		static int compareItems(HubInfo* a, HubInfo* b, int col) {
+		static int compareItems(const HubInfo* a, const HubInfo* b, int col) {
 			return (col == 0) ? lstrcmpi(a->name.c_str(), b->name.c_str()) : 0;
 		}
 		tstring url;

=== modified file 'win32/TransferView.cpp'
--- win32/TransferView.cpp	2011-11-19 00:10:54 +0000
+++ win32/TransferView.cpp	2011-11-21 19:04:08 +0000
@@ -440,7 +440,7 @@
 	return usersFromTable(connections);
 }
 
-int TransferView::ConnectionInfo::compareItems(ConnectionInfo* a, ConnectionInfo* b, int col) {
+int TransferView::ConnectionInfo::compareItems(const ConnectionInfo* a, const ConnectionInfo* b, int col) {
 	if(BOOLSETTING(ALT_SORT_ORDER)) {
 		if(a->download == b->download) {
 			if(a->status != b->status) {

=== modified file 'win32/TransferView.h'
--- win32/TransferView.h	2011-11-07 17:59:57 +0000
+++ win32/TransferView.h	2011-11-21 19:04:08 +0000
@@ -134,7 +134,7 @@
 			return col == 0 ? (download ? IMAGE_DOWNLOAD : IMAGE_UPLOAD) : -1;
 		}
 
-		static int compareItems(ConnectionInfo* a, ConnectionInfo* b, int col);
+		static int compareItems(const ConnectionInfo* a, const ConnectionInfo* b, int col);
 	};
 
 	struct UpdateInfo : public Task {
@@ -205,7 +205,7 @@
 
 		int getImage(int col) const;
 
-		static int compareItems(DownloadInfo* a, DownloadInfo* b, int col) {
+		static int compareItems(const DownloadInfo* a, const DownloadInfo* b, int col) {
 			switch(col) {
 			case DOWNLOAD_COLUMN_STATUS: return compare(fraction(a->size, a->done), fraction(b->size, b->done));
 			case DOWNLOAD_COLUMN_TIMELEFT: return compare(a->timeleft(), b->timeleft());
@@ -219,7 +219,7 @@
 		void update();
 		void update(const TickInfo& ti);
 
-		int64_t timeleft() { return bps == 0 ? 0 : (size - done) / bps; }
+		int64_t timeleft() const { return bps == 0 ? 0 : (size - done) / bps; }
 		string path;
 		int64_t done;
 		int64_t size;

=== modified file 'win32/TypedTable.h'
--- win32/TypedTable.h	2011-11-16 18:12:07 +0000
+++ win32/TypedTable.h	2011-11-21 19:04:08 +0000
@@ -30,18 +30,18 @@
 @tparam managed Whether this class should handle deleting associated objects.
 
 @note Support for texts:
-The ContentType class must provide a const tstring& getText(int col) const function.
+The ContentType class must provide a const tstring& getText(int col) [const] function.
 
 @note Support for images:
-The ContentType class must provide a int getImage(int col) const function.
+The ContentType class must provide a int getImage(int col) [const] function.
 
 @note Support for item sorting:
 The ContentType class must provide a
-static int compareItems(const ContentType* a, const ContentType* b, int col) function.
+static int compareItems([const] ContentType* a, [const] ContentType* b, int col) function.
 
 @note Support for custom styles per item (whole row) or per sub-item (each cell):
 The ContentType class must provide a
-int getStyle(HFONT& font, COLORREF& textColor, COLORREF& bgColor, int col) const function. It is
+int getStyle(HFONT& font, COLORREF& textColor, COLORREF& bgColor, int col) [const] function. It is
 called a first time with col=-1 to set the style of the whole item. It can return:
 - CDRF_DODEFAULT to keep the default style for the item.
 - CDRF_NEWFONT to change the style of the item.
@@ -159,17 +159,21 @@
 	}
 
 private:
-	HAS_FUNC(HasText_, getText, const tstring& (ContentType::*)(int) const);
-#define HasText HasText_<T>::value
-
-	HAS_FUNC(HasImage_, getImage, int (ContentType::*)(int) const);
-#define HasImage HasImage_<T>::value
-
-	HAS_FUNC(HasSort_, compareItems, int (*)(const ContentType*, const ContentType*, int));
-#define HasSort HasSort_<T>::value
-
-	HAS_FUNC(HasStyle_, getStyle, int (ContentType::*)(HFONT&, COLORREF&, COLORREF&, int) const);
-#define HasStyle HasStyle_<T>::value
+	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)
 
 	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	2011-10-17 19:39:46 +0000
+++ win32/UsersFrame.h	2011-11-21 19:04:08 +0000
@@ -96,7 +96,7 @@
 			}
 		}
 
-		static int compareItems(UserInfo* a, UserInfo* b, int col) {
+		static int compareItems(const UserInfo* a, const UserInfo* b, int col) {
 			switch(col) {
 			case COLUMN_FAVORITE: return compare(a->isFavorite, b->isFavorite);
 			case COLUMN_SLOT: return compare(a->grantSlot, b->grantSlot);