libzypp: zypp-core/ByteArray.h Source File

libzypp 17.38.6

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 std::string &data ) : ByteArray( data.c_str(), data.length() ) { }
23 explicit ByteArray ( const char *data, const int len = -1 ) : ByteArray( data, data + (len == -1 ? strlen(data) : len) ) { }
24 std::string asString () const {
25 if ( size() == 0 )
26 return std::string();
27 return std::string( data(), size() );
28 }
29
30#ifdef __cpp_lib_string_view
31 std::string_view asStringView () const {
32 if ( size() == 0 )
33 return std::string_view();
34 return std::string_view( data(), size() );
35 }
36#endif
37
38 static std::size_t maxSize () {
39 static const auto size = ByteArray().max_size();
40 return size;
41 }
42
43 };
44
45 class UByteArray : public std::vector<unsigned char>
46 {
47 public:
48 using vector<unsigned char>::vector;
49 explicit UByteArray ( const char *data, const int len = -1 ) : UByteArray( data, data + (len == -1 ? strlen(data) : len) ) { }
50
51 static std::size_t maxSize () {
52 static const auto size = UByteArray().max_size();
53 return size;
54 }
55 };
56}
57
58
59#endif
zypp::ByteArray::maxSize
static std::size_t maxSize()
Definition ByteArray.h:38
zypp::ByteArray::ByteArray
ByteArray(const std::string &data)
Definition ByteArray.h:22
zypp::ByteArray::asString
std::string asString() const
Definition ByteArray.h:24
zypp::ByteArray::ByteArray
ByteArray(const char *data, const int len=-1)
Definition ByteArray.h:23
zypp::UByteArray::maxSize
static std::size_t maxSize()
Definition ByteArray.h:51
zypp::UByteArray::UByteArray
UByteArray(const char *data, const int len=-1)
Definition ByteArray.h:49
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2