This commit is contained in:
Dmitry Borisenko
2021-12-22 14:09:50 +01:00
parent 5e9b15e7de
commit 24a9d55ea0
195 changed files with 15629 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
// Copyright Benoit Blanchon 2019-2021
// MIT License
#pragma once
#include <assert.h>
#include <stdlib.h> // size_t
#include <string.h> // memcpy
namespace StreamUtils {
template <typename TAllocator>
class CharArray {
public:
CharArray(size_t size, TAllocator allocator = TAllocator())
: _allocator(allocator) {
_data = reinterpret_cast<char *>(_allocator.allocate(size));
_size = _data ? size : 0;
}
CharArray(const CharArray &src) : CharArray(src._size, src._allocator) {
if (_data != nullptr)
memcpy(_data, src._data, _size);
}
~CharArray() {
_allocator.deallocate(_data);
}
size_t size() const {
return _size;
}
operator bool() const {
return _size > 0;
}
char *operator&() {
return _data;
}
char &operator[](size_t i) {
return _data[i];
}
char operator[](size_t i) const {
return _data[i];
}
protected:
TAllocator _allocator;
char *_data;
size_t _size;
};
} // namespace StreamUtils