• Main Page
  • Classes
  • Files
  • File List

Swiften/Base/ByteArray.h

00001 /*
00002  * Copyright (c) 2010 Remko Tronçon
00003  * Licensed under the GNU General Public License v3.
00004  * See Documentation/Licenses/GPLv3.txt for more information.
00005  */
00006 
00007 #pragma once
00008 
00009 #include <vector>
00010 #include <string>
00011 
00012 #include <Swiften/Base/API.h>
00013 
00014 namespace Swift {
00015   typedef std::vector<unsigned char> ByteArray;
00016 
00017   SWIFTEN_API ByteArray createByteArray(const std::string& s);
00018   SWIFTEN_API ByteArray createByteArray(const char* c);
00019 
00020   inline ByteArray createByteArray(const unsigned char* c, size_t n) {
00021     return ByteArray(c, c  + n);
00022   }
00023 
00024   inline ByteArray createByteArray(const char* c, size_t n) {
00025     return ByteArray(c, c  + n);
00026   }
00027 
00028   inline ByteArray createByteArray(char c) {
00029     return std::vector<unsigned char>(1, c);
00030   }
00031 
00032   template<typename T, typename A>
00033   static const T* vecptr(const std::vector<T, A>& v) {
00034     return v.empty() ? NULL : &v[0];
00035   }
00036 
00037   template<typename T, typename A>
00038   static T* vecptr(std::vector<T, A>& v) {
00039     return v.empty() ? NULL : &v[0];
00040   }
00041       
00042   SWIFTEN_API std::string byteArrayToString(const ByteArray& b);
00043 
00044   SWIFTEN_API void readByteArrayFromFile(ByteArray&, const std::string& file);
00045 }
00046 

Generated on Fri Oct 12 2012 21:00:19 for Swiften by  doxygen 1.7.1