summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-03-26 10:09:46 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-04-18 19:11:40 (GMT)
commitbb37c9f89e4135f3128fc98c23ea19eea945c4cd (patch)
tree92e9504a27d6eaa8182bb0bab8a7556825a46ad7 /Swiften/Base
parent039636edc1b151431cba21a28986ff2be66b5349 (diff)
downloadswift-contrib-bb37c9f89e4135f3128fc98c23ea19eea945c4cd.zip
swift-contrib-bb37c9f89e4135f3128fc98c23ea19eea945c4cd.tar.bz2
Jingle refactoring.
Diffstat (limited to 'Swiften/Base')
-rw-r--r--Swiften/Base/ByteArray.cpp35
-rw-r--r--Swiften/Base/ByteArray.h10
2 files changed, 45 insertions, 0 deletions
diff --git a/Swiften/Base/ByteArray.cpp b/Swiften/Base/ByteArray.cpp
index 928e145..c3869fc 100644
--- a/Swiften/Base/ByteArray.cpp
+++ b/Swiften/Base/ByteArray.cpp
@@ -9,6 +9,10 @@
#include <fstream>
std::ostream& operator<<(std::ostream& os, const Swift::ByteArray& s) {
+ return operator<<(os, s.getDataVector());
+}
+
+std::ostream& operator<<(std::ostream& os, const std::vector<unsigned char>& s) {
std::ios::fmtflags oldFlags = os.flags();
os << std::hex;
for (Swift::ByteArray::const_iterator i = s.begin(); i != s.end(); ++i) {
@@ -37,4 +41,35 @@ void ByteArray::readFromFile(const std::string& file) {
input.close();
}
+std::vector<unsigned char> ByteArray::create(const std::string& s) {
+ return std::vector<unsigned char>(s.begin(), s.end());
+}
+
+std::vector<unsigned char> ByteArray::create(const char* c) {
+ std::vector<unsigned char> data;
+ while (*c) {
+ data.push_back(static_cast<unsigned char>(*c));
+ ++c;
+ }
+ return data;
+}
+
+std::vector<unsigned char> ByteArray::create(const char* c, size_t n) {
+ std::vector<unsigned char> data;
+ if (n > 0) {
+ data.resize(n);
+ memcpy(&data[0], c, n);
+ }
+ return data;
+}
+
+std::vector<unsigned char> ByteArray::create(const unsigned char* c, size_t n) {
+ std::vector<unsigned char> data;
+ if (n > 0) {
+ data.resize(n);
+ memcpy(&data[0], c, n);
+ }
+ return data;
+}
+
}
diff --git a/Swiften/Base/ByteArray.h b/Swiften/Base/ByteArray.h
index 2059052..9e7a928 100644
--- a/Swiften/Base/ByteArray.h
+++ b/Swiften/Base/ByteArray.h
@@ -130,9 +130,19 @@ namespace Swift {
data_.clear();
}
+ const std::vector<unsigned char>& getDataVector() const {
+ return data_;
+ }
+
+ static std::vector<unsigned char> create(const std::string& s);
+ static std::vector<unsigned char> create(const char* c);
+ static std::vector<unsigned char> create(const unsigned char* c, size_t n);
+ static std::vector<unsigned char> create(const char* c, size_t n);
+
private:
std::vector<unsigned char> data_;
};
}
std::ostream& operator<<(std::ostream& os, const Swift::ByteArray& s);
+std::ostream& operator<<(std::ostream& os, const std::vector<unsigned char>& s);