mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-29 18:27:37 +02:00
Change naming convention from _member
to member_
(fixes #1905)
Ported from 31ce648e63
This commit is contained in:
@ -62,12 +62,12 @@ class AllocatorLog {
|
||||
};
|
||||
|
||||
AllocatorLog& operator<<(const std::string& s) {
|
||||
_log << s << "\n";
|
||||
log_ << s << "\n";
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string str() const {
|
||||
auto s = _log.str();
|
||||
auto s = log_.str();
|
||||
if (s.empty())
|
||||
return "(empty)";
|
||||
s.pop_back(); // remove the trailing '\n'
|
||||
@ -84,57 +84,57 @@ class AllocatorLog {
|
||||
}
|
||||
|
||||
private:
|
||||
std::ostringstream _log;
|
||||
std::ostringstream log_;
|
||||
};
|
||||
|
||||
class SpyingAllocator : public ArduinoJson::Allocator {
|
||||
public:
|
||||
SpyingAllocator(
|
||||
Allocator* upstream = ArduinoJson::detail::DefaultAllocator::instance())
|
||||
: _upstream(upstream) {}
|
||||
: upstream_(upstream) {}
|
||||
virtual ~SpyingAllocator() {}
|
||||
|
||||
void* allocate(size_t n) override {
|
||||
auto block = reinterpret_cast<AllocatedBlock*>(
|
||||
_upstream->allocate(sizeof(AllocatedBlock) + n - 1));
|
||||
upstream_->allocate(sizeof(AllocatedBlock) + n - 1));
|
||||
if (block) {
|
||||
_log << AllocatorLog::Allocate(n);
|
||||
log_ << AllocatorLog::Allocate(n);
|
||||
block->size = n;
|
||||
return block->payload;
|
||||
} else {
|
||||
_log << AllocatorLog::AllocateFail(n);
|
||||
log_ << AllocatorLog::AllocateFail(n);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void deallocate(void* p) override {
|
||||
auto block = AllocatedBlock::fromPayload(p);
|
||||
_log << AllocatorLog::Deallocate(block->size);
|
||||
_upstream->deallocate(block);
|
||||
log_ << AllocatorLog::Deallocate(block->size);
|
||||
upstream_->deallocate(block);
|
||||
}
|
||||
|
||||
void* reallocate(void* p, size_t n) override {
|
||||
auto block = AllocatedBlock::fromPayload(p);
|
||||
auto oldSize = block->size;
|
||||
block = reinterpret_cast<AllocatedBlock*>(
|
||||
_upstream->reallocate(block, sizeof(AllocatedBlock) + n - 1));
|
||||
upstream_->reallocate(block, sizeof(AllocatedBlock) + n - 1));
|
||||
if (block) {
|
||||
_log << AllocatorLog::Reallocate(oldSize, n);
|
||||
log_ << AllocatorLog::Reallocate(oldSize, n);
|
||||
ARDUINOJSON_ASSERT(block->size == oldSize);
|
||||
block->size = n;
|
||||
return block->payload;
|
||||
} else {
|
||||
_log << AllocatorLog::ReallocateFail(oldSize, n);
|
||||
log_ << AllocatorLog::ReallocateFail(oldSize, n);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void clearLog() {
|
||||
_log = AllocatorLog();
|
||||
log_ = AllocatorLog();
|
||||
}
|
||||
|
||||
const AllocatorLog& log() const {
|
||||
return _log;
|
||||
return log_;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -151,36 +151,36 @@ class SpyingAllocator : public ArduinoJson::Allocator {
|
||||
}
|
||||
};
|
||||
|
||||
AllocatorLog _log;
|
||||
Allocator* _upstream;
|
||||
AllocatorLog log_;
|
||||
Allocator* upstream_;
|
||||
};
|
||||
|
||||
class ControllableAllocator : public ArduinoJson::Allocator {
|
||||
public:
|
||||
ControllableAllocator(
|
||||
Allocator* upstream = ArduinoJson::detail::DefaultAllocator::instance())
|
||||
: _enabled(true), _upstream(upstream) {}
|
||||
: enabled_(true), upstream_(upstream) {}
|
||||
virtual ~ControllableAllocator() {}
|
||||
|
||||
void* allocate(size_t n) override {
|
||||
return _enabled ? _upstream->allocate(n) : 0;
|
||||
return enabled_ ? upstream_->allocate(n) : 0;
|
||||
}
|
||||
|
||||
void deallocate(void* p) override {
|
||||
_upstream->deallocate(p);
|
||||
upstream_->deallocate(p);
|
||||
}
|
||||
|
||||
void* reallocate(void* ptr, size_t n) override {
|
||||
return _enabled ? _upstream->reallocate(ptr, n) : 0;
|
||||
return enabled_ ? upstream_->reallocate(ptr, n) : 0;
|
||||
}
|
||||
|
||||
void disable() {
|
||||
_enabled = false;
|
||||
enabled_ = false;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _enabled;
|
||||
Allocator* _upstream;
|
||||
bool enabled_;
|
||||
Allocator* upstream_;
|
||||
};
|
||||
|
||||
class TimebombAllocator : public ArduinoJson::Allocator {
|
||||
@ -188,32 +188,32 @@ class TimebombAllocator : public ArduinoJson::Allocator {
|
||||
TimebombAllocator(
|
||||
size_t initialCountdown,
|
||||
Allocator* upstream = ArduinoJson::detail::DefaultAllocator::instance())
|
||||
: _countdown(initialCountdown), _upstream(upstream) {}
|
||||
: countdown_(initialCountdown), upstream_(upstream) {}
|
||||
virtual ~TimebombAllocator() {}
|
||||
|
||||
void* allocate(size_t n) override {
|
||||
if (!_countdown)
|
||||
if (!countdown_)
|
||||
return nullptr;
|
||||
_countdown--;
|
||||
return _upstream->allocate(n);
|
||||
countdown_--;
|
||||
return upstream_->allocate(n);
|
||||
}
|
||||
|
||||
void deallocate(void* p) override {
|
||||
_upstream->deallocate(p);
|
||||
upstream_->deallocate(p);
|
||||
}
|
||||
|
||||
void* reallocate(void* ptr, size_t n) override {
|
||||
if (!_countdown)
|
||||
if (!countdown_)
|
||||
return nullptr;
|
||||
_countdown--;
|
||||
return _upstream->reallocate(ptr, n);
|
||||
countdown_--;
|
||||
return upstream_->reallocate(ptr, n);
|
||||
}
|
||||
|
||||
void setCountdown(size_t value) {
|
||||
_countdown = value;
|
||||
countdown_ = value;
|
||||
}
|
||||
|
||||
private:
|
||||
size_t _countdown = 0;
|
||||
Allocator* _upstream;
|
||||
size_t countdown_ = 0;
|
||||
Allocator* upstream_;
|
||||
};
|
||||
|
@ -7,18 +7,18 @@
|
||||
#include <sstream>
|
||||
|
||||
class CustomReader {
|
||||
std::stringstream _stream;
|
||||
std::stringstream stream_;
|
||||
|
||||
public:
|
||||
CustomReader(const char* input) : _stream(input) {}
|
||||
CustomReader(const char* input) : stream_(input) {}
|
||||
CustomReader(const CustomReader&) = delete;
|
||||
|
||||
int read() {
|
||||
return _stream.get();
|
||||
return stream_.get();
|
||||
}
|
||||
|
||||
size_t readBytes(char* buffer, size_t length) {
|
||||
_stream.read(buffer, static_cast<std::streamsize>(length));
|
||||
return static_cast<size_t>(_stream.gcount());
|
||||
stream_.read(buffer, static_cast<std::streamsize>(length));
|
||||
return static_cast<size_t>(stream_.gcount());
|
||||
}
|
||||
};
|
||||
|
@ -9,11 +9,11 @@
|
||||
// Reproduces Arduino's String class
|
||||
class String {
|
||||
public:
|
||||
String() : _maxCapacity(1024) {}
|
||||
explicit String(const char* s) : _str(s), _maxCapacity(1024) {}
|
||||
String() : maxCapacity_(1024) {}
|
||||
explicit String(const char* s) : str_(s), maxCapacity_(1024) {}
|
||||
|
||||
void limitCapacityTo(size_t maxCapacity) {
|
||||
_maxCapacity = maxCapacity;
|
||||
maxCapacity_ = maxCapacity;
|
||||
}
|
||||
|
||||
unsigned char concat(const char* s) {
|
||||
@ -21,45 +21,45 @@ class String {
|
||||
}
|
||||
|
||||
size_t length() const {
|
||||
return _str.size();
|
||||
return str_.size();
|
||||
}
|
||||
|
||||
const char* c_str() const {
|
||||
return _str.c_str();
|
||||
return str_.c_str();
|
||||
}
|
||||
|
||||
bool operator==(const char* s) const {
|
||||
return _str == s;
|
||||
return str_ == s;
|
||||
}
|
||||
|
||||
String& operator=(const char* s) {
|
||||
_str.assign(s);
|
||||
str_.assign(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
char operator[](unsigned int index) const {
|
||||
if (index >= _str.size())
|
||||
if (index >= str_.size())
|
||||
return 0;
|
||||
return _str[index];
|
||||
return str_[index];
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& lhs, const ::String& rhs) {
|
||||
lhs << rhs._str;
|
||||
lhs << rhs.str_;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
protected:
|
||||
// This function is protected in most Arduino cores
|
||||
unsigned char concat(const char* s, size_t n) {
|
||||
if (_str.size() + n > _maxCapacity)
|
||||
if (str_.size() + n > maxCapacity_)
|
||||
return 0;
|
||||
_str.append(s, n);
|
||||
str_.append(s, n);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _str;
|
||||
size_t _maxCapacity;
|
||||
std::string str_;
|
||||
size_t maxCapacity_;
|
||||
};
|
||||
|
||||
class StringSumHelper : public ::String {};
|
||||
|
Reference in New Issue
Block a user