summaryrefslogtreecommitdiff
path: root/src/DownloadContext.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-06-18 14:47:09 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-06-18 14:47:09 +0000
commit8ba97188ce42be38b5427e9bd70bb7f5ba8238f9 (patch)
tree6cba1ad1496b6865c215881e7a0f21c009287912 /src/DownloadContext.cc
parent98dc02192d4b10eb6057a7d6a724b2e05a5767ef (diff)
2010-06-18 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Introduced ValueBase class, which is a replacement of BDE. In this change ValueBase is used instead of BDE except DHT messages, UTMetadata messages and XML-RPC. They'll be replaced in the later commits. DownloadContext::_attrs is now ContextAttribute rather than BDE. * src/ActivePeerConnectionCommand.cc * src/AnnounceList.cc * src/AnnounceList.h * src/BtDependency.cc * src/BtRegistry.cc * src/BtSetup.cc * src/ConsoleStatCalc.cc * src/ContextAttribute.h * src/DefaultBtAnnounce.cc * src/DefaultBtInteractive.cc * src/DownloadContext.cc * src/DownloadContext.h * src/HandshakeExtensionMessage.cc * src/InitiateConnectionCommand.cc * src/LpdReceiveMessageCommand.cc * src/MSEHandshake.cc * src/Makefile.am * src/Makefile.in * src/PeerInteractionCommand.cc * src/PeerListProcessor.h * src/ProtocolDetector.cc * src/RequestGroup.cc * src/RequestGroupMan.cc * src/TorrentAttribute.h * src/TrackerWatcherCommand.cc * src/UTMetadataDataExtensionMessage.cc * src/UTMetadataPostDownloadHandler.cc * src/UTMetadataRequestExtensionMessage.cc * src/ValueBase.cc * src/ValueBase.h * src/XmlRpcMethodImpl.cc * src/XmlRpcMethodImpl.h * src/bencode2.cc * src/bencode2.h * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/download_helper.cc * src/magnet.cc * src/magnet.h * test/AnnounceListTest.cc * test/Bencode2Test.cc * test/BencodeTest.cc * test/BittorrentHelperTest.cc * test/BtDependencyTest.cc * test/BtRegistryTest.cc * test/DefaultBtAnnounceTest.cc * test/DefaultBtProgressInfoFileTest.cc * test/HandshakeExtensionMessageTest.cc * test/MSEHandshakeTest.cc * test/MagnetTest.cc * test/Makefile.am * test/Makefile.in * test/RequestGroupManTest.cc * test/UTMetadataDataExtensionMessageTest.cc * test/UTMetadataPostDownloadHandlerTest.cc * test/UTMetadataRequestExtensionMessageTest.cc * test/ValueBaseTest.cc * test/XmlRpcMethodTest.cc
Diffstat (limited to 'src/DownloadContext.cc')
-rw-r--r--src/DownloadContext.cc36
1 files changed, 17 insertions, 19 deletions
diff --git a/src/DownloadContext.cc b/src/DownloadContext.cc
index 4a3dae52..30afcf18 100644
--- a/src/DownloadContext.cc
+++ b/src/DownloadContext.cc
@@ -40,6 +40,7 @@
#include "StringFormat.h"
#include "util.h"
#include "wallclock.h"
+#include "DlAbortEx.h"
namespace aria2 {
@@ -138,36 +139,33 @@ void DownloadContext::setFileFilter(IntSequence seq)
}
}
-void DownloadContext::ensureAttrs()
+void DownloadContext::setAttribute
+(const std::string& key, const SharedHandle<ContextAttribute>& value)
{
- if(_attrs.isNone()) {
- _attrs = BDE::dict();
+ std::map<std::string, SharedHandle<ContextAttribute> >::value_type p =
+ std::make_pair(key, value);
+ std::pair<std::map<std::string, SharedHandle<ContextAttribute> >::iterator,
+ bool> r = _attrs.insert(p);
+ if(!r.second) {
+ (*r.first).second = value;
}
}
-void DownloadContext::setAttribute(const std::string& key, const BDE& value)
+const SharedHandle<ContextAttribute>& DownloadContext::getAttribute
+(const std::string& key)
{
- ensureAttrs();
- _attrs[key] = value;
-}
-
-BDE& DownloadContext::getAttribute(const std::string& key)
-{
- ensureAttrs();
- if(_attrs.containsKey(key)) {
- return _attrs[key];
- } else {
+ std::map<std::string, SharedHandle<ContextAttribute> >::const_iterator itr =
+ _attrs.find(key);
+ if(itr == _attrs.end()) {
throw DL_ABORT_EX(StringFormat("No attribute named %s", key.c_str()).str());
+ } else {
+ return (*itr).second;
}
}
bool DownloadContext::hasAttribute(const std::string& key) const
{
- if(_attrs.isNone()) {
- return false;
- } else {
- return _attrs.containsKey(key);
- }
+ return _attrs.count(key) == 1;
}
void DownloadContext::releaseRuntimeResource()