00001
00002
00003
00004
00005
00006
00007 #pragma once
00008
00009 #include <vector>
00010
00011 #include <Swiften/Base/API.h>
00012 #include <Swiften/Base/SafeAllocator.h>
00013 #include <Swiften/Base/ByteArray.h>
00014 #include <boost/smart_ptr/make_shared.hpp>
00015
00016 namespace Swift {
00017 typedef std::vector<unsigned char, SafeAllocator<unsigned char> > SafeByteArray;
00018
00019 inline SafeByteArray createSafeByteArray(const ByteArray& a) {
00020 return SafeByteArray(a.begin(), a.end());
00021 }
00022
00023 SWIFTEN_API SafeByteArray createSafeByteArray(const char* c);
00024
00025 inline SafeByteArray createSafeByteArray(const std::string& s) {
00026 return SafeByteArray(s.begin(), s.end());
00027 }
00028
00029 inline boost::shared_ptr<SafeByteArray> createSafeByteArrayRef(const std::string& s) {
00030 return boost::make_shared<SafeByteArray>(s.begin(), s.end());
00031 }
00032
00033 inline SafeByteArray createSafeByteArray(char c) {
00034 return SafeByteArray(1, c);
00035 }
00036
00037 inline SafeByteArray createSafeByteArray(const char* c, size_t n) {
00038 return SafeByteArray(c, c + n);
00039 }
00040
00041 inline boost::shared_ptr<SafeByteArray> createSafeByteArrayRef(const char* c, size_t n) {
00042 return boost::make_shared<SafeByteArray>(c, c + n);
00043 }
00044
00045 inline SafeByteArray createSafeByteArray(const unsigned char* c, size_t n) {
00046 return SafeByteArray(c, c + n);
00047 }
00048
00049 inline boost::shared_ptr<SafeByteArray> createSafeByteArrayRef(const unsigned char* c, size_t n) {
00050 return boost::make_shared<SafeByteArray>(c, c + n);
00051 }
00052
00053
00054
00055 inline std::string safeByteArrayToString(const SafeByteArray& b) {
00056 return byteArrayToString(ByteArray(b.begin(), b.end()));
00057 }
00058 }
00059