linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #05241
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2833: use boost containers on MSVC - various hacks to pull them into the std namespace
------------------------------------------------------------
revno: 2833
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Mon 2012-01-23 18:56:18 +0100
message:
use boost containers on MSVC - various hacks to pull them into the std namespace
added:
msvc/container/
msvc/container/custom_hash.h
msvc/container/deque
msvc/container/list
msvc/container/map
msvc/container/readme.txt
msvc/container/set
msvc/container/unordered_map
msvc/container/unordered_set
msvc/container/vector
modified:
build_util.py
dcpp/CID.h
dcpp/HashManager.cpp
dcpp/NmdcHub.cpp
dcpp/SConscript
dcpp/ShareManager.cpp
dcpp/UploadManager.cpp
dwt/include/dwt/widgets/RichTextBox.h
dwt/src/SConscript
dwt/test/SConscript
dwt/test/TreeTest.cpp
test/SConscript
utils/SConscript
win32/ConnectivityManualPage.cpp
win32/ConnectivityManualPage.h
win32/DirectoryListingFrame.cpp
win32/MainWindow.cpp
win32/SConscript
win32/StylesPage.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 'build_util.py'
--- build_util.py 2012-01-10 18:45:17 +0000
+++ build_util.py 2012-01-23 17:56:18 +0000
@@ -220,6 +220,13 @@
asciidoc = 'python ' + asciidoc
return asciidoc
+ # switch to boost containers instead of default STL containers on MSVC for the given project.
+ def msvc_boost_containers(self, env):
+ if 'msvc' in env['TOOLS']:
+ env.Append(CPPPATH = ['#/msvc/container/'])
+ # define include guards of STL files to make sure only boost containers are used.
+ env.Append(CPPDEFINES = ['_DEQUE_', '_LIST_', '_MAP_', '_SET_', '_UNORDERED_MAP_', '_UNORDERED_SET_', '_VECTOR_'])
+
# source is *one* SCons file node (not a list!) designating the .po file
def get_po_name(source):
# rely on the comments at the beginning of the po file to find the language name.
@@ -312,7 +319,6 @@
re.sub('(' + line + ')+', line, re.sub('\s*<br ?/?>\s*', line,
string.replace('\\', '\\\\').replace('{', '\\{').replace('}', '\\}'))))))).replace('<u>', '{\\ul ')
-
def msvcproj_workarounds(target, source, env):
f = open(str(target[0]), 'rb')
contents = f.read()
=== modified file 'dcpp/CID.h'
--- dcpp/CID.h 2012-01-13 20:55:20 +0000
+++ dcpp/CID.h 2012-01-23 17:56:18 +0000
@@ -63,10 +63,8 @@
namespace std {
template<>
struct hash<dcpp::CID> {
- size_t operator()(const dcpp::CID& rhs) const {
- size_t hvHash;
- memcpy(&hvHash, rhs.data(), sizeof(size_t));
- return hvHash;
+ size_t operator()(const dcpp::CID& cid) const {
+ return cid.toHash();
}
};
}
=== modified file 'dcpp/HashManager.cpp'
--- dcpp/HashManager.cpp 2012-01-20 22:57:52 +0000
+++ dcpp/HashManager.cpp 2012-01-23 17:56:18 +0000
@@ -251,7 +251,7 @@
}
for (auto i = fileIndex.begin(); i != fileIndex.end(); ++i) {
- auto fi = newFileIndex.insert(make_pair(i->first, FileInfoList())).first;
+ auto fi = newFileIndex.emplace(i->first, FileInfoList()).first;
for (auto j = i->second.begin(); j != i->second.end(); ++j) {
if (newTreeIndex.find(j->getRoot()) != newTreeIndex.end()) {
=== modified file 'dcpp/NmdcHub.cpp'
--- dcpp/NmdcHub.cpp 2012-01-13 20:55:20 +0000
+++ dcpp/NmdcHub.cpp 2012-01-23 17:56:18 +0000
@@ -270,7 +270,7 @@
uint64_t tick = GET_TICK();
clearFlooders(tick);
- seekers.push_back(make_pair(seeker, tick));
+ seekers.emplace_back(seeker, tick);
// First, check if it's a flooder
for(auto fi = flooders.begin(); fi != flooders.end(); ++fi) {
@@ -290,7 +290,7 @@
else
fire(ClientListener::SearchFlood(), this, str(F_("%1% (Nick unknown)") % seeker));
- flooders.push_back(make_pair(seeker, tick));
+ flooders.emplace_back(seeker, tick);
return;
}
}
=== modified file 'dcpp/SConscript'
--- dcpp/SConscript 2011-12-08 17:29:46 +0000
+++ dcpp/SConscript 2012-01-23 17:56:18 +0000
@@ -8,6 +8,8 @@
env.Append(CPPDEFINES = ['BUILDING_DCPP=1'])
+dev.msvc_boost_containers(env)
+
headers=dev.get_sources(source_path, "*.h")
dev.i18n(source_path, env, [sources, headers], 'libdcpp')
=== modified file 'dcpp/ShareManager.cpp'
--- dcpp/ShareManager.cpp 2012-01-13 20:55:20 +0000
+++ dcpp/ShareManager.cpp 2012-01-23 17:56:18 +0000
@@ -338,7 +338,7 @@
const string& virtualName = aXml.getChildAttrib("Virtual");
string vName = validateVirtual(virtualName.empty() ? Util::getLastDir(realPath) : virtualName);
- shares.insert(std::make_pair(realPath, vName));
+ shares.emplace(realPath, vName);
if(getByVirtual(vName) == directories.end()) {
directories.push_back(Directory::create(vName));
}
@@ -477,7 +477,7 @@
{
Lock l(cs);
- shares.insert(std::make_pair(realPath, vName));
+ shares.emplace(realPath, vName);
updateIndices(*merge(dp));
setDirty();
@@ -508,7 +508,7 @@
if(findFile(subSource->getName()) != files.end()) {
dcdebug("File named the same as directory");
} else {
- directories.insert(std::make_pair(subSource->getName(), subSource));
+ directories.emplace(subSource->getName(), subSource);
subSource->parent = this;
}
} else {
@@ -723,7 +723,7 @@
dir.addType(getType(f.getName()));
- tthIndex.insert(make_pair(f.getTTH(), i));
+ tthIndex.emplace(f.getTTH(), i);
bloom.add(Text::toLower(f.getName()));
}
@@ -757,7 +757,7 @@
Lock l(cs);
StringPairList ret;
for(auto i = shares.begin(); i != shares.end(); ++i) {
- ret.push_back(make_pair(i->second, i->first));
+ ret.emplace_back(i->second, i->first);
}
return ret;
}
@@ -1423,7 +1423,7 @@
// Get rid of false constness...
auto f = const_cast<Directory::File*>(&(*i));
f->setTTH(root);
- tthIndex.insert(make_pair(f->getTTH(), i));
+ tthIndex.emplace(f->getTTH(), i);
} else {
string name = Util::getFileName(fname);
int64_t size = File::getSize(fname);
=== modified file 'dcpp/UploadManager.cpp'
--- dcpp/UploadManager.cpp 2012-01-13 20:55:20 +0000
+++ dcpp/UploadManager.cpp 2012-01-23 17:56:18 +0000
@@ -357,7 +357,7 @@
Lock l(cs);
auto it = find_if(waitingUsers.begin(), waitingUsers.end(), CompareFirst<UserPtr, uint32_t>(source.getUser()));
if (it==waitingUsers.end()) {
- waitingUsers.push_back(WaitingUser(source.getHintedUser(), GET_TICK()));
+ waitingUsers.emplace_back(source.getHintedUser(), GET_TICK());
} else {
it->second = GET_TICK();
}
=== modified file 'dwt/include/dwt/widgets/RichTextBox.h'
--- dwt/include/dwt/widgets/RichTextBox.h 2012-01-13 20:55:20 +0000
+++ dwt/include/dwt/widgets/RichTextBox.h 2012-01-23 17:56:18 +0000
@@ -36,12 +36,12 @@
#ifndef DWT_RichTextBox_h
#define DWT_RichTextBox_h
+#include <boost/algorithm/string.hpp>
+
#include "TextBox.h"
#include "../tstring.h"
#include <richedit.h>
-#include <boost/algorithm/string.hpp>
-
namespace dwt {
/// RichEdit Control class
=== modified file 'dwt/src/SConscript'
--- dwt/src/SConscript 2012-01-10 18:45:17 +0000
+++ dwt/src/SConscript 2012-01-23 17:56:18 +0000
@@ -4,6 +4,8 @@
env.Append(CPPPATH = ['#/dwt/include'])
+dev.msvc_boost_containers(env)
+
def get_msvcproj_files(env):
def parse_patterns(patterns):
array = []
=== modified file 'dwt/test/SConscript'
--- dwt/test/SConscript 2012-01-10 18:45:17 +0000
+++ dwt/test/SConscript 2012-01-23 17:56:18 +0000
@@ -8,6 +8,8 @@
env.Append(CPPPATH = ['#/dwt/include'])
+dev.msvc_boost_containers(env)
+
# imitate build_util's prepare_build
env.VariantDir(dev.get_build_path(source_path), '.', duplicate = 0)
if env['msvcproj']:
=== modified file 'dwt/test/TreeTest.cpp'
--- dwt/test/TreeTest.cpp 2012-01-12 22:19:35 +0000
+++ dwt/test/TreeTest.cpp 2012-01-23 17:56:18 +0000
@@ -1,3 +1,7 @@
+#ifdef _MSC_VER
+#include <map> // fix some include trouble on MSVC
+#endif
+
#include <dwt/widgets/Window.h>
#include <dwt/widgets/Tree.h>
#include <dwt/Texts.h>
=== added directory 'msvc/container'
=== added file 'msvc/container/custom_hash.h'
--- msvc/container/custom_hash.h 1970-01-01 00:00:00 +0000
+++ msvc/container/custom_hash.h 2012-01-23 17:56:18 +0000
@@ -0,0 +1,16 @@
+#ifndef DCPP_BOOST_CONTAINER_CUSTOM_HASH
+#define DCPP_BOOST_CONTAINER_CUSTOM_HASH
+
+/* boost & STL have different ways of specifying a custom hash. since DC++ only uses the STL way,
+ * this defines a generic boost hash function that redirects to STL ones. */
+
+namespace boost {
+ template<typename T>
+ inline size_t hash_value(const T& t) {
+ return std::hash<T>()(t);
+ }
+}
+
+#endif
+
+// vim: set filetype=cpp :
=== added file 'msvc/container/deque'
--- msvc/container/deque 1970-01-01 00:00:00 +0000
+++ msvc/container/deque 2012-01-23 17:56:18 +0000
@@ -0,0 +1,12 @@
+#ifndef DCPP_BOOST_CONTAINER_DEQUE
+#define DCPP_BOOST_CONTAINER_DEQUE
+
+#include <boost/container/deque.hpp>
+
+namespace std {
+ using boost::container::deque;
+}
+
+#endif
+
+// vim: set filetype=cpp :
=== added file 'msvc/container/list'
--- msvc/container/list 1970-01-01 00:00:00 +0000
+++ msvc/container/list 2012-01-23 17:56:18 +0000
@@ -0,0 +1,12 @@
+#ifndef DCPP_BOOST_CONTAINER_LIST
+#define DCPP_BOOST_CONTAINER_LIST
+
+#include <boost/container/list.hpp>
+
+namespace std {
+ using boost::container::list;
+}
+
+#endif
+
+// vim: set filetype=cpp :
=== added file 'msvc/container/map'
--- msvc/container/map 1970-01-01 00:00:00 +0000
+++ msvc/container/map 2012-01-23 17:56:18 +0000
@@ -0,0 +1,12 @@
+#ifndef DCPP_BOOST_CONTAINER_MAP
+#define DCPP_BOOST_CONTAINER_MAP
+
+#include <boost/container/map.hpp>
+
+namespace std {
+ using boost::container::map;
+}
+
+#endif
+
+// vim: set filetype=cpp :
=== added file 'msvc/container/readme.txt'
--- msvc/container/readme.txt 1970-01-01 00:00:00 +0000
+++ msvc/container/readme.txt 2012-01-23 17:56:18 +0000
@@ -0,0 +1,3 @@
+This directory contains include files that short-circuit MSVC's standard container implementation
+in favor of the one provided by Boost.Container. This allows, in particular, emplace / emplace_back
+with variable arguments which MSVC is lacking (as of 2010).
=== added file 'msvc/container/set'
--- msvc/container/set 1970-01-01 00:00:00 +0000
+++ msvc/container/set 2012-01-23 17:56:18 +0000
@@ -0,0 +1,12 @@
+#ifndef DCPP_BOOST_CONTAINER_SET
+#define DCPP_BOOST_CONTAINER_SET
+
+#include <boost/container/set.hpp>
+
+namespace std {
+ using boost::container::set;
+}
+
+#endif
+
+// vim: set filetype=cpp :
=== added file 'msvc/container/unordered_map'
--- msvc/container/unordered_map 1970-01-01 00:00:00 +0000
+++ msvc/container/unordered_map 2012-01-23 17:56:18 +0000
@@ -0,0 +1,17 @@
+#ifndef DCPP_BOOST_CONTAINER_UNORDERED_MAP
+#define DCPP_BOOST_CONTAINER_UNORDERED_MAP
+
+#include <vector>
+
+#include <boost/unordered/unordered_map.hpp>
+
+namespace std {
+ using boost::unordered_map;
+ using boost::unordered_multimap;
+}
+
+#include "custom_hash.h"
+
+#endif
+
+// vim: set filetype=cpp :
=== added file 'msvc/container/unordered_set'
--- msvc/container/unordered_set 1970-01-01 00:00:00 +0000
+++ msvc/container/unordered_set 2012-01-23 17:56:18 +0000
@@ -0,0 +1,17 @@
+#ifndef DCPP_BOOST_CONTAINER_UNORDERED_SET
+#define DCPP_BOOST_CONTAINER_UNORDERED_SET
+
+#include <vector>
+
+#include <boost/unordered/unordered_set.hpp>
+
+namespace std {
+ using boost::unordered_set;
+ using boost::unordered_multiset;
+}
+
+#include "custom_hash.h"
+
+#endif
+
+// vim: set filetype=cpp :
=== added file 'msvc/container/vector'
--- msvc/container/vector 1970-01-01 00:00:00 +0000
+++ msvc/container/vector 2012-01-23 17:56:18 +0000
@@ -0,0 +1,12 @@
+#ifndef DCPP_BOOST_CONTAINER_VECTOR
+#define DCPP_BOOST_CONTAINER_VECTOR
+
+#include <boost/container/vector.hpp>
+
+namespace std {
+ using boost::container::vector;
+}
+
+#endif
+
+// vim: set filetype=cpp :
=== modified file 'test/SConscript'
--- test/SConscript 2012-01-11 20:53:02 +0000
+++ test/SConscript 2012-01-23 17:56:18 +0000
@@ -46,6 +46,8 @@
openssl_lib += env['arch'] + '/'
env.Append(LIBPATH = [openssl_lib])
+dev.msvc_boost_containers(env)
+
if env['msvcproj']:
ret = dev.build_lib(env, target, sources, dev.cpp_lib)
else:
=== modified file 'utils/SConscript'
--- utils/SConscript 2012-01-10 18:45:17 +0000
+++ utils/SConscript 2012-01-23 17:56:18 +0000
@@ -35,6 +35,8 @@
openssl_lib += env['arch'] + '/'
env.Append(LIBPATH = [openssl_lib])
+dev.msvc_boost_containers(env)
+
# imitate build_util's prepare_build
env.VariantDir(dev.get_build_path(source_path), '.', duplicate = 0)
if env['msvcproj']:
=== modified file 'win32/ConnectivityManualPage.cpp'
--- win32/ConnectivityManualPage.cpp 2012-01-13 20:55:20 +0000
+++ win32/ConnectivityManualPage.cpp 2012-01-23 17:56:18 +0000
@@ -42,7 +42,7 @@
autoDetect(0),
directIn(0),
upnp(0),
-nat(0),
+manual(0),
passive(0),
externalIP(0),
mapper(0)
@@ -70,8 +70,8 @@
upnp = cur->addChild(RadioButton::Seed(T_("Let DC++ configure my router (NAT-PMP / UPnP)")));
upnp->setHelpId(IDH_SETTINGS_CONNECTIVITY_FIREWALL_UPNP);
- nat = cur->addChild(RadioButton::Seed(T_("Manual port forwarding (I have configured my router by myself)")));
- nat->setHelpId(IDH_SETTINGS_CONNECTIVITY_FIREWALL_NAT);
+ manual = cur->addChild(RadioButton::Seed(T_("Manual port forwarding (I have configured my router by myself)")));
+ manual->setHelpId(IDH_SETTINGS_CONNECTIVITY_FIREWALL_NAT);
passive = cur->addChild(RadioButton::Seed(T_("Passive mode (last resort - has serious limitations)")));
passive->setHelpId(IDH_SETTINGS_CONNECTIVITY_FIREWALL_PASSIVE);
@@ -149,7 +149,7 @@
// Set the connection mode
int c = upnp->getChecked() ? SettingsManager::INCOMING_FIREWALL_UPNP :
- nat->getChecked() ? SettingsManager::INCOMING_FIREWALL_NAT :
+ manual->getChecked() ? SettingsManager::INCOMING_FIREWALL_NAT :
passive->getChecked() ? SettingsManager::INCOMING_FIREWALL_PASSIVE :
SettingsManager::INCOMING_DIRECT;
if(SETTING(INCOMING_CONNECTIONS) != c) {
@@ -180,7 +180,7 @@
void ConnectivityManualPage::read() {
switch(SETTING(INCOMING_CONNECTIONS)) {
case SettingsManager::INCOMING_FIREWALL_UPNP: upnp->setChecked(); break;
- case SettingsManager::INCOMING_FIREWALL_NAT: nat->setChecked(); break;
+ case SettingsManager::INCOMING_FIREWALL_NAT: manual->setChecked(); break;
case SettingsManager::INCOMING_FIREWALL_PASSIVE: passive->setChecked(); break;
default: directIn->setChecked(); break;
}
@@ -209,7 +209,7 @@
directIn->setChecked(false);
upnp->setChecked(false);
- nat->setChecked(false);
+ manual->setChecked(false);
passive->setChecked(false);
mapper->clear();
=== modified file 'win32/ConnectivityManualPage.h'
--- win32/ConnectivityManualPage.h 2012-01-13 20:55:20 +0000
+++ win32/ConnectivityManualPage.h 2012-01-23 17:56:18 +0000
@@ -39,7 +39,7 @@
RadioButtonPtr directIn;
RadioButtonPtr upnp;
- RadioButtonPtr nat;
+ RadioButtonPtr manual;
RadioButtonPtr passive;
TextBoxPtr externalIP;
=== modified file 'win32/DirectoryListingFrame.cpp'
--- win32/DirectoryListingFrame.cpp 2012-01-22 20:27:14 +0000
+++ win32/DirectoryListingFrame.cpp 2012-01-23 17:56:18 +0000
@@ -634,7 +634,12 @@
searchGrid->setVisible(false);
grid->row(0).mode = GridInfo::STATIC;
} else {
+#ifndef _MSC_VER
for(auto i = lastSearches.crbegin(), iend = lastSearches.crend(); i != iend; ++i) {
+#else
+ // crbegin / crend don't play well with boost containers & MSVC...
+ for(auto i = lastSearches.rbegin(), iend = lastSearches.rend(); i != iend; ++i) {
+#endif
auto p = i->get();
searchBox->setData(searchBox->addValue(p->first), reinterpret_cast<LPARAM>(p));
}
=== modified file 'win32/MainWindow.cpp'
--- win32/MainWindow.cpp 2012-01-22 20:39:56 +0000
+++ win32/MainWindow.cpp 2012-01-23 17:56:18 +0000
@@ -644,7 +644,7 @@
const FavHubGroups& groups = FavoriteManager::getInstance()->getFavHubGroups();
for(auto i = groups.begin(), iend = groups.end(); i != iend; ++i)
- groupMenus.insert(make_pair(i->first, nullptr));
+ groupMenus.emplace(i->first, nullptr);
for(auto i = groupMenus.begin(); i != groupMenus.end(); ++i) {
i->second = menu->appendPopup(escapeMenu(Text::toT(i->first)));
=== modified file 'win32/SConscript'
--- win32/SConscript 2012-01-15 16:08:29 +0000
+++ win32/SConscript 2012-01-23 17:56:18 +0000
@@ -32,6 +32,8 @@
openssl_lib += env['arch'] + '/'
env.Append(LIBPATH = [openssl_lib])
+dev.msvc_boost_containers(env)
+
if env['RC'] == 'rc': # MSVC
env.Append(RCFLAGS = ['/d' + env['arch']])
elif env['RC'].find('windres') != -1: # MinGW
=== modified file 'win32/StylesPage.cpp'
--- win32/StylesPage.cpp 2012-01-19 20:18:37 +0000
+++ win32/StylesPage.cpp 2012-01-23 17:56:18 +0000
@@ -151,7 +151,7 @@
auto add = [this, grouped](tstring&& text, unsigned helpId, int group, int fontSetting, int textColorSetting, int bgColorSetting) -> Data* {
auto data = new SettingsData(forward<tstring>(text), helpId, fontSetting, textColorSetting, bgColorSetting);
- table->insert(grouped ? group : -1, data);
+ this->table->insert(grouped ? group : -1, data);
return data;
};