← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3379: fun with list initialization

 

------------------------------------------------------------
revno: 3379
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2013-12-06 22:45:24 +0100
message:
  fun with list initialization
modified:
  dcpp/AdcHub.cpp
  dcpp/ConnectionManager.cpp
  dcpp/NmdcHub.cpp
  dcpp/SettingsManager.cpp
  win32/ADLSearchFrame.cpp
  win32/FavHubsFrame.cpp
  win32/FavoriteDirsPage.cpp
  win32/HubFrame.cpp
  win32/PropPage.cpp
  win32/SearchTypesPage.cpp
  win32/UCPage.cpp


--
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 'dcpp/AdcHub.cpp'
--- dcpp/AdcHub.cpp	2013-09-15 16:39:42 +0000
+++ dcpp/AdcHub.cpp	2013-12-06 21:45:24 +0000
@@ -755,60 +755,15 @@
 		return searchExts;
 
 	// the list is always immutable except for this function where it is initially being filled.
-	auto& xSearchExts = const_cast<vector<StringList>&>(searchExts);
-
-	xSearchExts.resize(6);
-
-	/// @todo simplify this as searchExts[0] = { "mp3", "etc" } when VC++ supports initializer lists
-
-	// these extensions *must* be sorted alphabetically!
-
-	{
-		StringList& l = xSearchExts[0];
-		l.push_back("ape"); l.push_back("flac"); l.push_back("m4a"); l.push_back("mid");
-		l.push_back("mp3"); l.push_back("mpc"); l.push_back("ogg"); l.push_back("ra");
-		l.push_back("wav"); l.push_back("wma");
-	}
-
-	{
-		StringList& l = xSearchExts[1];
-		l.push_back("7z"); l.push_back("ace"); l.push_back("arj"); l.push_back("bz2");
-		l.push_back("gz"); l.push_back("lha"); l.push_back("lzh"); l.push_back("rar");
-		l.push_back("tar"); l.push_back("z"); l.push_back("zip");
-	}
-
-	{
-		StringList& l = xSearchExts[2];
-		l.push_back("doc"); l.push_back("docx"); l.push_back("htm"); l.push_back("html");
-		l.push_back("nfo"); l.push_back("odf"); l.push_back("odp"); l.push_back("ods");
-		l.push_back("odt"); l.push_back("pdf"); l.push_back("ppt"); l.push_back("pptx");
-		l.push_back("rtf"); l.push_back("txt"); l.push_back("xls"); l.push_back("xlsx");
-		l.push_back("xml"); l.push_back("xps");
-	}
-
-	{
-		StringList& l = xSearchExts[3];
-		l.push_back("app"); l.push_back("bat"); l.push_back("cmd"); l.push_back("com");
-		l.push_back("dll"); l.push_back("exe"); l.push_back("jar"); l.push_back("msi");
-		l.push_back("ps1"); l.push_back("vbs"); l.push_back("wsf");
-	}
-
-	{
-		StringList& l = xSearchExts[4];
-		l.push_back("bmp"); l.push_back("cdr"); l.push_back("eps"); l.push_back("gif");
-		l.push_back("ico"); l.push_back("img"); l.push_back("jpeg"); l.push_back("jpg");
-		l.push_back("png"); l.push_back("ps"); l.push_back("psd"); l.push_back("sfw");
-		l.push_back("tga"); l.push_back("tif"); l.push_back("webp");
-	}
-
-	{
-		StringList& l = xSearchExts[5];
-		l.push_back("3gp"); l.push_back("asf"); l.push_back("asx"); l.push_back("avi");
-		l.push_back("divx"); l.push_back("flv"); l.push_back("mkv"); l.push_back("mov");
-		l.push_back("mp4"); l.push_back("mpeg"); l.push_back("mpg"); l.push_back("ogm");
-		l.push_back("pxp"); l.push_back("qt"); l.push_back("rm"); l.push_back("rmvb");
-		l.push_back("swf"); l.push_back("vob"); l.push_back("webm"); l.push_back("wmv");
-	}
+	const_cast<vector<StringList>&>(searchExts) = {
+		// these extensions *must* be sorted alphabetically!
+		{ "ape", "flac", "m4a", "mid", "mp3", "mpc", "ogg", "ra", "wav", "wma" },
+		{ "7z", "ace", "arj", "bz2", "gz", "lha", "lzh", "rar", "tar", "z", "zip" },
+		{ "doc", "docx", "htm", "html", "nfo", "odf", "odp", "ods", "odt", "pdf", "ppt", "pptx", "rtf", "txt", "xls", "xlsx", "xml", "xps" },
+		{ "app", "bat", "cmd", "com", "dll", "exe", "jar", "msi", "ps1", "vbs", "wsf" },
+		{ "bmp", "cdr", "eps", "gif", "ico", "img", "jpeg", "jpg", "png", "ps", "psd", "sfw", "tga", "tif", "webp" },
+		{ "3gp", "asf", "asx", "avi", "divx", "flv", "mkv", "mov", "mp4", "mpeg", "mpg", "ogm", "pxp", "qt", "rm", "rmvb", "swf", "vob", "webm", "wmv" }
+	};
 
 	return searchExts;
 }

=== modified file 'dcpp/ConnectionManager.cpp'
--- dcpp/ConnectionManager.cpp	2013-09-29 14:47:02 +0000
+++ dcpp/ConnectionManager.cpp	2013-12-06 21:45:24 +0000
@@ -38,16 +38,20 @@
 {
 	TimerManager::getInstance()->addListener(this);
 
-	features.push_back(UserConnection::FEATURE_MINISLOTS);
-	features.push_back(UserConnection::FEATURE_XML_BZLIST);
-	features.push_back(UserConnection::FEATURE_ADCGET);
-	features.push_back(UserConnection::FEATURE_TTHL);
-	features.push_back(UserConnection::FEATURE_TTHF);
+	features = {
+		UserConnection::FEATURE_MINISLOTS,
+		UserConnection::FEATURE_XML_BZLIST,
+		UserConnection::FEATURE_ADCGET,
+		UserConnection::FEATURE_TTHL,
+		UserConnection::FEATURE_TTHF
+	};
 
-	adcFeatures.push_back("AD" + UserConnection::FEATURE_ADC_BAS0);
-	adcFeatures.push_back("AD" + UserConnection::FEATURE_ADC_BASE);
-	adcFeatures.push_back("AD" + UserConnection::FEATURE_ADC_TIGR);
-	adcFeatures.push_back("AD" + UserConnection::FEATURE_ADC_BZIP);
+	adcFeatures = {
+		"AD" + UserConnection::FEATURE_ADC_BAS0,
+		"AD" + UserConnection::FEATURE_ADC_BASE,
+		"AD" + UserConnection::FEATURE_ADC_TIGR,
+		"AD" + UserConnection::FEATURE_ADC_BZIP
+	};
 }
 
 string ConnectionManager::makeToken() const {

=== modified file 'dcpp/NmdcHub.cpp'
--- dcpp/NmdcHub.cpp	2013-09-15 16:39:42 +0000
+++ dcpp/NmdcHub.cpp	2013-12-06 21:45:24 +0000
@@ -548,15 +548,14 @@
 			}
 
 			if(CryptoManager::getInstance()->isExtended(lock)) {
-				StringList feat;
-				feat.push_back("UserCommand");
-				feat.push_back("NoGetINFO");
-				feat.push_back("NoHello");
-				feat.push_back("UserIP2");
-				feat.push_back("TTHSearch");
-				feat.push_back("ZPipe0");
-
-				supports(feat);
+				supports({
+					"UserCommand",
+					"NoGetINFO",
+					"NoHello",
+					"UserIP2",
+					"TTHSearch",
+					"ZPipe0"
+				});
 			}
 
 			key(CryptoManager::getInstance()->makeKey(lock));
@@ -1013,13 +1012,13 @@
 	refreshLocalIp();
 
 	if(aTick > (lastProtectedIPsUpdate + 24*3600*1000)) {
-		protectedIPs.clear();
-
-		protectedIPs.push_back("dcpp.net");
-		protectedIPs.push_back("dchublist.com");
-		protectedIPs.push_back("hublist.eu");
-		protectedIPs.push_back("hublista.hu");
-		protectedIPs.push_back("dcbase.org");
+		protectedIPs = {
+			"dcpp.net",
+			"dchublist.com",
+			"hublist.eu",
+			"hublista.hu",
+			"dcbase.org"
+		};
 		for(auto i = protectedIPs.begin(); i != protectedIPs.end();) {
 			*i = Socket::resolve(*i, AF_INET);
 			if(Util::isPrivateIp(*i))

=== modified file 'dcpp/SettingsManager.cpp'
--- dcpp/SettingsManager.cpp	2013-11-10 21:06:28 +0000
+++ dcpp/SettingsManager.cpp	2013-12-06 21:45:24 +0000
@@ -119,24 +119,24 @@
 	"SENTRY"
 };
 
-SettingsManager::SettingsManager()
-{
-
-	connectionSpeeds.push_back("0.005");
-	connectionSpeeds.push_back("0.01");
-	connectionSpeeds.push_back("0.02");
-	connectionSpeeds.push_back("0.05");
-	connectionSpeeds.push_back("0.1");
-	connectionSpeeds.push_back("0.2");
-	connectionSpeeds.push_back("0.5");
-	connectionSpeeds.push_back("1");
-	connectionSpeeds.push_back("2");
-	connectionSpeeds.push_back("5");
-	connectionSpeeds.push_back("10");
-	connectionSpeeds.push_back("20");
-	connectionSpeeds.push_back("50");
-	connectionSpeeds.push_back("100");
-	connectionSpeeds.push_back("1000");
+SettingsManager::SettingsManager() {
+	connectionSpeeds = {
+		"0.005",
+		"0.01",
+		"0.02",
+		"0.05",
+		"0.1",
+		"0.2",
+		"0.5",
+		"1",
+		"2",
+		"5",
+		"10",
+		"20",
+		"50",
+		"100",
+		"1000"
+	};
 
 	for(int i=0; i<SETTINGS_LAST; i++)
 		isSet[i] = false;

=== modified file 'win32/ADLSearchFrame.cpp'
--- win32/ADLSearchFrame.cpp	2013-03-16 14:57:07 +0000
+++ win32/ADLSearchFrame.cpp	2013-12-06 21:45:24 +0000
@@ -326,14 +326,14 @@
 }
 
 void ADLSearchFrame::addEntry(ADLSearch& search, int index, bool scroll) {
-	TStringList l;
-	l.push_back(Text::toT(search.searchString));
-	l.push_back(search.isRegEx() ? T_("Yes") : T_("No"));
-	l.push_back(Text::toT(search.SourceTypeToString(search.sourceType)));
-	l.push_back(Text::toT(search.destDir));
-	l.push_back((search.minFileSize >= 0) ? Text::toT(Util::toString(search.minFileSize)) + _T(" ") + Text::toT(search.SizeTypeToString(search.typeFileSize)) : Util::emptyStringT);
-	l.push_back((search.maxFileSize >= 0) ? Text::toT(Util::toString(search.maxFileSize)) + _T(" ") + Text::toT(search.SizeTypeToString(search.typeFileSize)) : Util::emptyStringT);
-	int itemCount = items->insert(l, 0, index);
+	int itemCount = items->insert({
+		Text::toT(search.searchString),
+		search.isRegEx() ? T_("Yes") : T_("No"),
+		Text::toT(search.SourceTypeToString(search.sourceType)),
+		Text::toT(search.destDir),
+		(search.minFileSize >= 0) ? Text::toT(Util::toString(search.minFileSize)) + _T(" ") + Text::toT(search.SizeTypeToString(search.typeFileSize)) : Util::emptyStringT,
+		(search.maxFileSize >= 0) ? Text::toT(Util::toString(search.maxFileSize)) + _T(" ") + Text::toT(search.SizeTypeToString(search.typeFileSize)) : Util::emptyStringT
+	}, 0, index);
 	if(index == -1)
 		index = itemCount;
 	items->setChecked(index, search.isActive);

=== modified file 'win32/FavHubsFrame.cpp'
--- win32/FavHubsFrame.cpp	2013-11-29 22:04:09 +0000
+++ win32/FavHubsFrame.cpp	2013-12-06 21:45:24 +0000
@@ -427,17 +427,16 @@
 			statusIcon = HUB_ON_ICON;
 		}
 
-		TStringList l;
-		l.push_back(statusText);
-		l.push_back(Text::toT(entry->getName()));
-		l.push_back(Text::toT(entry->getHubDescription()));
-		l.push_back(Text::toT(entry->get(HubSettings::Nick)));
-		l.emplace_back(entry->getPassword().size(), '*');
-		l.push_back(Text::toT(entry->getServer()));
-		l.push_back(Text::toT(entry->get(HubSettings::Description)));
-		l.push_back(Text::toT(group));
-
-		auto row = hubs->insert(l, reinterpret_cast<LPARAM>(entry), index);
+		auto row = hubs->insert({
+			statusText,
+			Text::toT(entry->getName()),
+			Text::toT(entry->getHubDescription()),
+			Text::toT(entry->get(HubSettings::Nick)),
+			tstring(entry->getPassword().size(), '*'),
+			Text::toT(entry->getServer()),
+			Text::toT(entry->get(HubSettings::Description)),
+			Text::toT(group)
+		}, reinterpret_cast<LPARAM>(entry), index);
 
 		hubs->setIcon(row, COLUMN_STATUS, statusIcon);
 	}

=== modified file 'win32/FavoriteDirsPage.cpp'
--- win32/FavoriteDirsPage.cpp	2013-01-18 21:28:38 +0000
+++ win32/FavoriteDirsPage.cpp	2013-12-06 21:45:24 +0000
@@ -165,10 +165,7 @@
 }
 
 void FavoriteDirsPage::addRow(const tstring& name, const tstring& path) {
-	TStringList row;
-	row.push_back(name);
-	row.push_back(path);
-	directories->insert(row);
+	directories->insert({ name, path });
 }
 
 void FavoriteDirsPage::addDirectory(const tstring& aPath) {

=== modified file 'win32/HubFrame.cpp'
--- win32/HubFrame.cpp	2013-12-02 13:58:16 +0000
+++ win32/HubFrame.cpp	2013-12-06 21:45:24 +0000
@@ -1577,10 +1577,6 @@
 
 	if(setTabIcon)
 	{
-		std::vector<int> icons;
-		icons.push_back(IDI_HUB);
-		icons.push_back(tabIcon);
-
-		setIcon(WinUtil::mergeIcons(icons));
+		setIcon(WinUtil::mergeIcons({ IDI_HUB, tabIcon }));
 	}
 }

=== modified file 'win32/PropPage.cpp'
--- win32/PropPage.cpp	2013-11-01 18:38:32 +0000
+++ win32/PropPage.cpp	2013-12-06 21:45:24 +0000
@@ -114,9 +114,8 @@
 
 	SettingsManager* settings = SettingsManager::getInstance();
 	for(size_t i = 0; listItems[i].setting != 0; ++i) {
-		TStringList row;
-		row.push_back(T_(listItems[i].desc));
-		list->setChecked(list->insert(row), settings->get(static_cast<SettingsManager::BoolSetting>(listItems[i].setting), true));
+		list->setChecked(list->insert({ T_(listItems[i].desc) }),
+			settings->get(static_cast<SettingsManager::BoolSetting>(listItems[i].setting), true));
 	}
 
 	list->setColumnWidth(0, LVSCW_AUTOSIZE);

=== modified file 'win32/SearchTypesPage.cpp'
--- win32/SearchTypesPage.cpp	2013-01-18 21:28:38 +0000
+++ win32/SearchTypesPage.cpp	2013-12-06 21:45:24 +0000
@@ -255,11 +255,11 @@
 }
 
 void SearchTypesPage::addRow(const tstring& name, bool predefined, const TStringList& extensions) {
-	TStringList row;
-	row.push_back(name);
-	row.push_back(predefined ? T_("Predefined") : Util::emptyStringT);
-	row.push_back(Util::toString(_T(";"), extensions));
-	types->insert(row);
+	types->insert({
+		name,
+		predefined ? T_("Predefined") : Util::emptyStringT,
+		Util::toString(_T(";"), extensions)
+	});
 }
 
 void SearchTypesPage::findRealName(string& name) const {

=== modified file 'win32/UCPage.cpp'
--- win32/UCPage.cpp	2013-03-16 14:57:07 +0000
+++ win32/UCPage.cpp	2013-12-06 21:45:24 +0000
@@ -191,9 +191,9 @@
 }
 
 void UCPage::addEntry(const UserCommand& uc, int index) {
-	TStringList row;
-	row.push_back((uc.getType() == UserCommand::TYPE_SEPARATOR) ? T_("Separator") : Text::toT(uc.getName()));
-	row.push_back(Text::toT(uc.getCommand()));
-	row.push_back(Text::toT(uc.getHub()));
-	commands->insert(row, (LPARAM)uc.getId(), index);
+	commands->insert({
+		(uc.getType() == UserCommand::TYPE_SEPARATOR) ? T_("Separator") : Text::toT(uc.getName()),
+		Text::toT(uc.getCommand()),
+		Text::toT(uc.getHub())
+	}, static_cast<LPARAM>(uc.getId()), index);
 }