summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-12-14 03:59:24 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-12-14 03:59:24 +0000
commitb618ada28a49ed0e493647a6ea149bcd993129c1 (patch)
tree636f159a851b743a68d4746a12ebba687c560336 /src
parenta67ed743a22b78c441af2db49816aa7ccadb7fd0 (diff)
2008-12-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added missing #ifdef guard. Added uc() function for String and removeKey() for Dict. * src/bencode.cc * src/bencode.h * test/BencodeTest.cc
Diffstat (limited to 'src')
-rw-r--r--src/bencode.cc17
-rw-r--r--src/bencode.h13
2 files changed, 30 insertions, 0 deletions
diff --git a/src/bencode.cc b/src/bencode.cc
index 60a790a2..ec60544f 100644
--- a/src/bencode.cc
+++ b/src/bencode.cc
@@ -120,6 +120,15 @@ const std::string& BDE::s() const throw(RecoverableException)
}
}
+const unsigned char* BDE::uc() const throw(RecoverableException)
+{
+ if(isString()) {
+ return reinterpret_cast<const unsigned char*>(_string->data());
+ } else {
+ throw RecoverableException("Not String");
+ }
+}
+
// Dictionary Interface
bool BDE::isDict() const throw()
@@ -160,6 +169,14 @@ bool BDE::containsKey(const std::string& key) const throw(RecoverableException)
}
}
+void BDE::removeKey(const std::string& key) const throw(RecoverableException)
+{
+ if(isDict()) {
+ _dict->erase(key);
+ } else {
+ throw RecoverableException("Not Dict");
+ }
+}
BDE::Dict::iterator BDE::dictBegin() throw(RecoverableException)
{
diff --git a/src/bencode.h b/src/bencode.h
index 2a7fcea3..6c98836e 100644
--- a/src/bencode.h
+++ b/src/bencode.h
@@ -32,6 +32,9 @@
* files in the program, then also delete it here.
*/
/* copyright --> */
+#ifndef _D_BENCODE_H_
+#define _D_BENCODE_H_
+
#include "common.h"
#include <string>
@@ -110,6 +113,10 @@ public:
// Returns std::string. Requires this object to be String
const std::string& s() const throw(RecoverableException);
+ // Returns std::string.data() casted to unsigned char*.
+ // Use s().size() to get length.
+ const unsigned char* uc() const throw(RecoverableException);
+
//////////////////////////////////////////////////////////////////////////////
// Dictionary Interface
@@ -133,6 +140,10 @@ public:
// Requires this object to be Dict.
bool containsKey(const std::string& key) const throw(RecoverableException);
+ // Removes specified key from dict.
+ // Requires this object to be Dict.
+ void removeKey(const std::string& key) const throw(RecoverableException);
+
// Returns a read/write iterator that points to the first pair in the dict.
// Requires this object to be Dict.
Dict::iterator dictBegin() throw(RecoverableException);
@@ -212,3 +223,5 @@ std::string encode(const BDE& bde) throw();
} // namespace bencode
} // namespace aria2
+
+#endif // _D_BENCODE_H_