forked from bblanchon/ArduinoJson
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 {};
|
||||
|
@ -12,21 +12,21 @@ class CustomWriter {
|
||||
CustomWriter& operator=(const CustomWriter&) = delete;
|
||||
|
||||
size_t write(uint8_t c) {
|
||||
_str.append(1, static_cast<char>(c));
|
||||
str_.append(1, static_cast<char>(c));
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t write(const uint8_t* s, size_t n) {
|
||||
_str.append(reinterpret_cast<const char*>(s), n);
|
||||
str_.append(reinterpret_cast<const char*>(s), n);
|
||||
return n;
|
||||
}
|
||||
|
||||
const std::string& str() const {
|
||||
return _str;
|
||||
return str_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _str;
|
||||
std::string str_;
|
||||
};
|
||||
|
||||
TEST_CASE("CustomWriter") {
|
||||
|
@ -74,18 +74,18 @@ TEST_CASE("Custom converter with overloading") {
|
||||
|
||||
class Complex {
|
||||
public:
|
||||
explicit Complex(double r, double i) : _real(r), _imag(i) {}
|
||||
explicit Complex(double r, double i) : real_(r), imag_(i) {}
|
||||
|
||||
double real() const {
|
||||
return _real;
|
||||
return real_;
|
||||
}
|
||||
|
||||
double imag() const {
|
||||
return _imag;
|
||||
return imag_;
|
||||
}
|
||||
|
||||
private:
|
||||
double _real, _imag;
|
||||
double real_, imag_;
|
||||
};
|
||||
|
||||
namespace ArduinoJson {
|
||||
|
@ -170,19 +170,19 @@ TEST_CASE("IteratorReader") {
|
||||
|
||||
class StreamStub : public Stream {
|
||||
public:
|
||||
StreamStub(const char* s) : _stream(s) {}
|
||||
StreamStub(const char* s) : stream_(s) {}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
private:
|
||||
std::istringstream _stream;
|
||||
std::istringstream stream_;
|
||||
};
|
||||
|
||||
TEST_CASE("Reader<Stream>") {
|
||||
|
@ -52,5 +52,8 @@
|
||||
#define BLOCKSIZE
|
||||
#define CAPACITY
|
||||
|
||||
// issue #1905
|
||||
#define _current
|
||||
|
||||
// catch.hpp mutes several warnings, this file also allows to detect them
|
||||
#include "ArduinoJson.h"
|
||||
|
@ -34,21 +34,21 @@ struct PrintAllAtOnce {
|
||||
|
||||
template <typename PrintPolicy>
|
||||
struct PrintableString : public Printable {
|
||||
PrintableString(const char* s) : _str(s), _total(0) {}
|
||||
PrintableString(const char* s) : str_(s), total_(0) {}
|
||||
|
||||
virtual size_t printTo(Print& p) const {
|
||||
size_t result = PrintPolicy::printStringTo(_str, p);
|
||||
_total += result;
|
||||
size_t result = PrintPolicy::printStringTo(str_, p);
|
||||
total_ += result;
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t totalBytesWritten() const {
|
||||
return _total;
|
||||
return total_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _str;
|
||||
mutable size_t _total;
|
||||
std::string str_;
|
||||
mutable size_t total_;
|
||||
};
|
||||
|
||||
TEST_CASE("Printable") {
|
||||
|
Reference in New Issue
Block a user