summaryrefslogtreecommitdiffstats
blob: 4a5d4e9f95923b5e05cd4f6caf596c30b85eadd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * Copyright (c) 2010-2013 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#pragma once

#include <vector>
#include <string>

#include <Swiften/Base/API.h>
#include <boost/filesystem/path.hpp>

namespace Swift {
	typedef std::vector<unsigned char> ByteArray;

	SWIFTEN_API ByteArray createByteArray(const std::string& s);
	SWIFTEN_API ByteArray createByteArray(const char* c);

	inline ByteArray createByteArray(const unsigned char* c, size_t n) {
		return ByteArray(c, c  + n);
	}

	inline ByteArray createByteArray(const char* c, size_t n) {
		return ByteArray(c, c  + n);
	}

	inline ByteArray createByteArray(char c) {
		return std::vector<unsigned char>(1, static_cast<unsigned char>(c));
	}

	template<typename T, typename A>
	static const T* vecptr(const std::vector<T, A>& v) {
		return v.empty() ? NULL : &v[0];
	}

	template<typename T, typename A>
	static T* vecptr(std::vector<T, A>& v) {
		return v.empty() ? NULL : &v[0];
	}
			
	SWIFTEN_API std::string byteArrayToString(const ByteArray& b);

	SWIFTEN_API void readByteArrayFromFile(ByteArray&, const boost::filesystem::path& file);
}