Code-style consistency improvement:

Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files.
make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type.
This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
erwincoumans
2018-09-23 14:17:31 -07:00
parent b73b05e9fb
commit ab8f16961e
1773 changed files with 1081087 additions and 474249 deletions

View File

@@ -2,11 +2,11 @@
#include <algorithm>
#if !defined(_WIN32) && !defined(__OpenBSD__) && !defined(__FreeBSD__)
# include <alloca.h>
#include <alloca.h>
#endif
#if defined (__MINGW32__)
# define alloca __builtin_alloca
#if defined(__MINGW32__)
#define alloca __builtin_alloca
#endif
#include "serial/serial.h"
@@ -20,395 +20,397 @@
using std::invalid_argument;
using std::min;
using std::numeric_limits;
using std::vector;
using std::size_t;
using std::string;
using std::vector;
using serial::bytesize_t;
using serial::flowcontrol_t;
using serial::IOException;
using serial::parity_t;
using serial::Serial;
using serial::SerialException;
using serial::IOException;
using serial::bytesize_t;
using serial::parity_t;
using serial::stopbits_t;
using serial::flowcontrol_t;
class Serial::ScopedReadLock {
class Serial::ScopedReadLock
{
public:
ScopedReadLock(SerialImpl *pimpl) : pimpl_(pimpl) {
this->pimpl_->readLock();
}
~ScopedReadLock() {
this->pimpl_->readUnlock();
}
private:
// Disable copy constructors
ScopedReadLock(const ScopedReadLock&);
const ScopedReadLock& operator=(ScopedReadLock);
ScopedReadLock(SerialImpl *pimpl) : pimpl_(pimpl)
{
this->pimpl_->readLock();
}
~ScopedReadLock()
{
this->pimpl_->readUnlock();
}
SerialImpl *pimpl_;
private:
// Disable copy constructors
ScopedReadLock(const ScopedReadLock &);
const ScopedReadLock &operator=(ScopedReadLock);
SerialImpl *pimpl_;
};
class Serial::ScopedWriteLock {
class Serial::ScopedWriteLock
{
public:
ScopedWriteLock(SerialImpl *pimpl) : pimpl_(pimpl) {
this->pimpl_->writeLock();
}
~ScopedWriteLock() {
this->pimpl_->writeUnlock();
}
ScopedWriteLock(SerialImpl *pimpl) : pimpl_(pimpl)
{
this->pimpl_->writeLock();
}
~ScopedWriteLock()
{
this->pimpl_->writeUnlock();
}
private:
// Disable copy constructors
ScopedWriteLock(const ScopedWriteLock&);
const ScopedWriteLock& operator=(ScopedWriteLock);
SerialImpl *pimpl_;
// Disable copy constructors
ScopedWriteLock(const ScopedWriteLock &);
const ScopedWriteLock &operator=(ScopedWriteLock);
SerialImpl *pimpl_;
};
Serial::Serial (const string &port, uint32_t baudrate, serial::Timeout timeout,
bytesize_t bytesize, parity_t parity, stopbits_t stopbits,
flowcontrol_t flowcontrol)
: pimpl_(new SerialImpl (port, baudrate, bytesize, parity,
stopbits, flowcontrol))
Serial::Serial(const string &port, uint32_t baudrate, serial::Timeout timeout,
bytesize_t bytesize, parity_t parity, stopbits_t stopbits,
flowcontrol_t flowcontrol)
: pimpl_(new SerialImpl(port, baudrate, bytesize, parity,
stopbits, flowcontrol))
{
pimpl_->setTimeout(timeout);
pimpl_->setTimeout(timeout);
}
Serial::~Serial ()
Serial::~Serial()
{
delete pimpl_;
delete pimpl_;
}
void
Serial::open ()
void Serial::open()
{
pimpl_->open ();
pimpl_->open();
}
void
Serial::close ()
void Serial::close()
{
pimpl_->close ();
pimpl_->close();
}
bool
Serial::isOpen () const
bool Serial::isOpen() const
{
return pimpl_->isOpen ();
return pimpl_->isOpen();
}
size_t
Serial::available ()
Serial::available()
{
return pimpl_->available ();
return pimpl_->available();
}
bool
Serial::waitReadable ()
bool Serial::waitReadable()
{
serial::Timeout timeout(pimpl_->getTimeout ());
return pimpl_->waitReadable(timeout.read_timeout_constant);
serial::Timeout timeout(pimpl_->getTimeout());
return pimpl_->waitReadable(timeout.read_timeout_constant);
}
void
Serial::waitByteTimes (size_t count)
void Serial::waitByteTimes(size_t count)
{
pimpl_->waitByteTimes(count);
pimpl_->waitByteTimes(count);
}
size_t
Serial::read_ (uint8_t *buffer, size_t size)
Serial::read_(uint8_t *buffer, size_t size)
{
return this->pimpl_->read (buffer, size);
return this->pimpl_->read(buffer, size);
}
size_t
Serial::read (uint8_t *buffer, size_t size)
Serial::read(uint8_t *buffer, size_t size)
{
ScopedReadLock lock(this->pimpl_);
return this->pimpl_->read (buffer, size);
ScopedReadLock lock(this->pimpl_);
return this->pimpl_->read(buffer, size);
}
size_t
Serial::read (std::vector<uint8_t> &buffer, size_t size)
Serial::read(std::vector<uint8_t> &buffer, size_t size)
{
ScopedReadLock lock(this->pimpl_);
uint8_t *buffer_ = new uint8_t[size];
size_t bytes_read = this->pimpl_->read (buffer_, size);
buffer.insert (buffer.end (), buffer_, buffer_+bytes_read);
delete[] buffer_;
return bytes_read;
ScopedReadLock lock(this->pimpl_);
uint8_t *buffer_ = new uint8_t[size];
size_t bytes_read = this->pimpl_->read(buffer_, size);
buffer.insert(buffer.end(), buffer_, buffer_ + bytes_read);
delete[] buffer_;
return bytes_read;
}
size_t
Serial::read (std::string &buffer, size_t size)
Serial::read(std::string &buffer, size_t size)
{
ScopedReadLock lock(this->pimpl_);
uint8_t *buffer_ = new uint8_t[size];
size_t bytes_read = this->pimpl_->read (buffer_, size);
buffer.append (reinterpret_cast<const char*>(buffer_), bytes_read);
delete[] buffer_;
return bytes_read;
ScopedReadLock lock(this->pimpl_);
uint8_t *buffer_ = new uint8_t[size];
size_t bytes_read = this->pimpl_->read(buffer_, size);
buffer.append(reinterpret_cast<const char *>(buffer_), bytes_read);
delete[] buffer_;
return bytes_read;
}
string
Serial::read (size_t size)
Serial::read(size_t size)
{
std::string buffer;
this->read (buffer, size);
return buffer;
std::string buffer;
this->read(buffer, size);
return buffer;
}
size_t
Serial::readline (string &buffer, size_t size, string eol)
Serial::readline(string &buffer, size_t size, string eol)
{
ScopedReadLock lock(this->pimpl_);
size_t eol_len = eol.length ();
uint8_t *buffer_ = static_cast<uint8_t*>
(alloca (size * sizeof (uint8_t)));
size_t read_so_far = 0;
while (true)
{
size_t bytes_read = this->read_ (buffer_ + read_so_far, 1);
read_so_far += bytes_read;
if (bytes_read == 0) {
break; // Timeout occured on reading 1 byte
}
if (string (reinterpret_cast<const char*>
(buffer_ + read_so_far - eol_len), eol_len) == eol) {
break; // EOL found
}
if (read_so_far == size) {
break; // Reached the maximum read length
}
}
buffer.append(reinterpret_cast<const char*> (buffer_), read_so_far);
return read_so_far;
ScopedReadLock lock(this->pimpl_);
size_t eol_len = eol.length();
uint8_t *buffer_ = static_cast<uint8_t *>(alloca(size * sizeof(uint8_t)));
size_t read_so_far = 0;
while (true)
{
size_t bytes_read = this->read_(buffer_ + read_so_far, 1);
read_so_far += bytes_read;
if (bytes_read == 0)
{
break; // Timeout occured on reading 1 byte
}
if (string(reinterpret_cast<const char *>(buffer_ + read_so_far - eol_len), eol_len) == eol)
{
break; // EOL found
}
if (read_so_far == size)
{
break; // Reached the maximum read length
}
}
buffer.append(reinterpret_cast<const char *>(buffer_), read_so_far);
return read_so_far;
}
string
Serial::readline (size_t size, string eol)
Serial::readline(size_t size, string eol)
{
std::string buffer;
this->readline (buffer, size, eol);
return buffer;
std::string buffer;
this->readline(buffer, size, eol);
return buffer;
}
vector<string>
Serial::readlines (size_t size, string eol)
Serial::readlines(size_t size, string eol)
{
ScopedReadLock lock(this->pimpl_);
std::vector<std::string> lines;
size_t eol_len = eol.length ();
uint8_t *buffer_ = static_cast<uint8_t*>
(alloca (size * sizeof (uint8_t)));
size_t read_so_far = 0;
size_t start_of_line = 0;
while (read_so_far < size) {
size_t bytes_read = this->read_ (buffer_+read_so_far, 1);
read_so_far += bytes_read;
if (bytes_read == 0) {
if (start_of_line != read_so_far) {
lines.push_back (
string (reinterpret_cast<const char*> (buffer_ + start_of_line),
read_so_far - start_of_line));
}
break; // Timeout occured on reading 1 byte
}
if (string (reinterpret_cast<const char*>
(buffer_ + read_so_far - eol_len), eol_len) == eol) {
// EOL found
lines.push_back(
string(reinterpret_cast<const char*> (buffer_ + start_of_line),
read_so_far - start_of_line));
start_of_line = read_so_far;
}
if (read_so_far == size) {
if (start_of_line != read_so_far) {
lines.push_back(
string(reinterpret_cast<const char*> (buffer_ + start_of_line),
read_so_far - start_of_line));
}
break; // Reached the maximum read length
}
}
return lines;
ScopedReadLock lock(this->pimpl_);
std::vector<std::string> lines;
size_t eol_len = eol.length();
uint8_t *buffer_ = static_cast<uint8_t *>(alloca(size * sizeof(uint8_t)));
size_t read_so_far = 0;
size_t start_of_line = 0;
while (read_so_far < size)
{
size_t bytes_read = this->read_(buffer_ + read_so_far, 1);
read_so_far += bytes_read;
if (bytes_read == 0)
{
if (start_of_line != read_so_far)
{
lines.push_back(
string(reinterpret_cast<const char *>(buffer_ + start_of_line),
read_so_far - start_of_line));
}
break; // Timeout occured on reading 1 byte
}
if (string(reinterpret_cast<const char *>(buffer_ + read_so_far - eol_len), eol_len) == eol)
{
// EOL found
lines.push_back(
string(reinterpret_cast<const char *>(buffer_ + start_of_line),
read_so_far - start_of_line));
start_of_line = read_so_far;
}
if (read_so_far == size)
{
if (start_of_line != read_so_far)
{
lines.push_back(
string(reinterpret_cast<const char *>(buffer_ + start_of_line),
read_so_far - start_of_line));
}
break; // Reached the maximum read length
}
}
return lines;
}
size_t
Serial::write (const string &data)
Serial::write(const string &data)
{
ScopedWriteLock lock(this->pimpl_);
return this->write_ (reinterpret_cast<const uint8_t*>(data.c_str()),
data.length());
ScopedWriteLock lock(this->pimpl_);
return this->write_(reinterpret_cast<const uint8_t *>(data.c_str()),
data.length());
}
size_t
Serial::write (const std::vector<uint8_t> &data)
Serial::write(const std::vector<uint8_t> &data)
{
ScopedWriteLock lock(this->pimpl_);
return this->write_ (&data[0], data.size());
ScopedWriteLock lock(this->pimpl_);
return this->write_(&data[0], data.size());
}
size_t
Serial::write (const uint8_t *data, size_t size)
Serial::write(const uint8_t *data, size_t size)
{
ScopedWriteLock lock(this->pimpl_);
return this->write_(data, size);
ScopedWriteLock lock(this->pimpl_);
return this->write_(data, size);
}
size_t
Serial::write_ (const uint8_t *data, size_t length)
Serial::write_(const uint8_t *data, size_t length)
{
return pimpl_->write (data, length);
return pimpl_->write(data, length);
}
void
Serial::setPort (const string &port)
void Serial::setPort(const string &port)
{
ScopedReadLock rlock(this->pimpl_);
ScopedWriteLock wlock(this->pimpl_);
bool was_open = pimpl_->isOpen ();
if (was_open) close();
pimpl_->setPort (port);
if (was_open) open ();
ScopedReadLock rlock(this->pimpl_);
ScopedWriteLock wlock(this->pimpl_);
bool was_open = pimpl_->isOpen();
if (was_open) close();
pimpl_->setPort(port);
if (was_open) open();
}
string
Serial::getPort () const
Serial::getPort() const
{
return pimpl_->getPort ();
return pimpl_->getPort();
}
void
Serial::setTimeout (serial::Timeout &timeout)
void Serial::setTimeout(serial::Timeout &timeout)
{
pimpl_->setTimeout (timeout);
pimpl_->setTimeout(timeout);
}
serial::Timeout
Serial::getTimeout () const {
return pimpl_->getTimeout ();
Serial::getTimeout() const
{
return pimpl_->getTimeout();
}
void
Serial::setBaudrate (uint32_t baudrate)
void Serial::setBaudrate(uint32_t baudrate)
{
pimpl_->setBaudrate (baudrate);
pimpl_->setBaudrate(baudrate);
}
uint32_t
Serial::getBaudrate () const
Serial::getBaudrate() const
{
return uint32_t(pimpl_->getBaudrate ());
return uint32_t(pimpl_->getBaudrate());
}
void
Serial::setBytesize (bytesize_t bytesize)
void Serial::setBytesize(bytesize_t bytesize)
{
pimpl_->setBytesize (bytesize);
pimpl_->setBytesize(bytesize);
}
bytesize_t
Serial::getBytesize () const
Serial::getBytesize() const
{
return pimpl_->getBytesize ();
return pimpl_->getBytesize();
}
void
Serial::setParity (parity_t parity)
void Serial::setParity(parity_t parity)
{
pimpl_->setParity (parity);
pimpl_->setParity(parity);
}
parity_t
Serial::getParity () const
Serial::getParity() const
{
return pimpl_->getParity ();
return pimpl_->getParity();
}
void
Serial::setStopbits (stopbits_t stopbits)
void Serial::setStopbits(stopbits_t stopbits)
{
pimpl_->setStopbits (stopbits);
pimpl_->setStopbits(stopbits);
}
stopbits_t
Serial::getStopbits () const
Serial::getStopbits() const
{
return pimpl_->getStopbits ();
return pimpl_->getStopbits();
}
void
Serial::setFlowcontrol (flowcontrol_t flowcontrol)
void Serial::setFlowcontrol(flowcontrol_t flowcontrol)
{
pimpl_->setFlowcontrol (flowcontrol);
pimpl_->setFlowcontrol(flowcontrol);
}
flowcontrol_t
Serial::getFlowcontrol () const
Serial::getFlowcontrol() const
{
return pimpl_->getFlowcontrol ();
return pimpl_->getFlowcontrol();
}
void Serial::flush ()
void Serial::flush()
{
ScopedReadLock rlock(this->pimpl_);
ScopedWriteLock wlock(this->pimpl_);
pimpl_->flush ();
ScopedReadLock rlock(this->pimpl_);
ScopedWriteLock wlock(this->pimpl_);
pimpl_->flush();
}
void Serial::flushInput ()
void Serial::flushInput()
{
ScopedReadLock lock(this->pimpl_);
pimpl_->flushInput ();
ScopedReadLock lock(this->pimpl_);
pimpl_->flushInput();
}
void Serial::flushOutput ()
void Serial::flushOutput()
{
ScopedWriteLock lock(this->pimpl_);
pimpl_->flushOutput ();
ScopedWriteLock lock(this->pimpl_);
pimpl_->flushOutput();
}
void Serial::sendBreak (int duration)
void Serial::sendBreak(int duration)
{
pimpl_->sendBreak (duration);
pimpl_->sendBreak(duration);
}
void Serial::setBreak (bool level)
void Serial::setBreak(bool level)
{
pimpl_->setBreak (level);
pimpl_->setBreak(level);
}
void Serial::setRTS (bool level)
void Serial::setRTS(bool level)
{
pimpl_->setRTS (level);
pimpl_->setRTS(level);
}
void Serial::setDTR (bool level)
void Serial::setDTR(bool level)
{
pimpl_->setDTR (level);
pimpl_->setDTR(level);
}
bool Serial::waitForChange()
{
return pimpl_->waitForChange();
return pimpl_->waitForChange();
}
bool Serial::getCTS ()
bool Serial::getCTS()
{
return pimpl_->getCTS ();
return pimpl_->getCTS();
}
bool Serial::getDSR ()
bool Serial::getDSR()
{
return pimpl_->getDSR ();
return pimpl_->getDSR();
}
bool Serial::getRI ()
bool Serial::getRI()
{
return pimpl_->getRI ();
return pimpl_->getRI();
}
bool Serial::getCD ()
bool Serial::getCD()
{
return pimpl_->getCD ();
return pimpl_->getCD();
}