libzypp 17.31.23
ByteArray.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#ifndef ZYPP_BYTEARRAY_H
10#define ZYPP_BYTEARRAY_H
11
12#include <vector>
13#include <cstring>
14#include <string>
15#include <string_view>
16
17namespace zypp {
18 class ByteArray : public std::vector<char>
19 {
20 public:
21 using vector<char>::vector;
22 explicit ByteArray ( const char *data, const int len = -1 ) : ByteArray( data, data + (len == -1 ? strlen(data) : len) ) { }
23 std::string asString () const {
24 if ( size() == 0 )
25 return std::string();
26 return std::string( data(), size() );
27 }
28
29#ifdef __cpp_lib_string_view
30 std::string_view asStringView () const {
31 if ( size() == 0 )
32 return std::string_view();
33 return std::string_view( data(), size() );
34 }
35#endif
36
37 static std::size_t maxSize () {
38 static const auto size = ByteArray().max_size();
39 return size;
40 }
41
42 };
43
44 class UByteArray : public std::vector<unsigned char>
45 {
46 public:
47 using vector<unsigned char>::vector;
48 explicit UByteArray ( const char *data, const int len = -1 ) : UByteArray( data, data + (len == -1 ? strlen(data) : len) ) { }
49
50 static std::size_t maxSize () {
51 static const auto size = UByteArray().max_size();
52 return size;
53 }
54 };
55}
56
57
58#endif
static std::size_t maxSize()
Definition: ByteArray.h:37
std::string asString() const
Definition: ByteArray.h:23
ByteArray(const char *data, const int len=-1)
Definition: ByteArray.h:22
static std::size_t maxSize()
Definition: ByteArray.h:50
UByteArray(const char *data, const int len=-1)
Definition: ByteArray.h:48
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2