Transfer Ease
Loading...
Searching...
No Matches
bytesarray.h
1#ifndef TEASE_NET_BYTESARRAY_H
2#define TEASE_NET_BYTESARRAY_H
3
4#include "transferease/transferease_global.h"
5
6#include <memory>
7#include <string>
8#include <string_view>
9#include <vector>
10
11namespace tease
12{
13
14class TEASE_EXPORT BytesArray
15{
16
17public:
18 using Byte = uint8_t;
19
20private:
21 using Container = std::vector<Byte>; /* As long as this type is not changed, ABI will be preserved */
22
23public:
24 using iterator = typename Container::iterator;
25 using const_iterator = typename Container::const_iterator;
26 using reverse_iterator = typename Container::reverse_iterator;
27 using const_reverse_iterator = typename Container::const_reverse_iterator;
28
29public:
30 BytesArray();
31 explicit BytesArray(size_t size);
32 explicit BytesArray(size_t size, Byte value);
33 explicit BytesArray(const std::initializer_list<Byte> &args);
34
35 BytesArray(const BytesArray &other);
36 BytesArray(BytesArray &&other) noexcept;
37
38 virtual ~BytesArray();
39
40public:
41 bool isEmpty() const;
42 std::size_t getSize() const;
43 std::size_t getMaxSize() const;
44
45 const Byte& at(size_t index) const;
46
47 std::string toString() const;
48 bool toFile(const std::string &pathFile) const;
49
50public:
51 void reserve(size_t size);
52 void resize(size_t size, Byte value = 0);
53
54 void pushBack(Byte value);
55 void pushBack(std::string_view strView);
56 void pushBack(const Byte *buffer, size_t len);
57 void popBack();
58
59 void setFromString(std::string_view strView);
60 bool setFromFile(const std::string &pathFile);
61
62 Byte* data();
63 const Byte* dataConst() const;
64
65public:
66 void clear();
67
68public:
69 iterator begin();
70 const_iterator cbegin() const;
71 reverse_iterator rbegin();
72 const_reverse_iterator crbegin() const;
73 iterator end();
74 const_iterator cend() const;
75 reverse_iterator rend();
76 const_reverse_iterator crend() const;
77
78public:
79 Byte& operator[](size_t index);
80 const Byte& operator[](size_t index) const;
81
82 BytesArray& operator=(const BytesArray &other);
83 BytesArray& operator=(BytesArray &&other) noexcept;
84
85public:
86 TEASE_EXPORT friend bool operator==(const BytesArray &left, const BytesArray &right);
87 TEASE_EXPORT friend bool operator!=(const BytesArray &left, const BytesArray &right);
88
89private:
90 class Impl;
91 std::unique_ptr<Impl> d_ptr;
92};
93
94} // namespace tease
95
96#endif // TEASE_NET_BYTESARRAY_H
Allow to store an array of bytes.
Definition bytesarray.h:15