Run astyle

pull/7822/head
Donatien Garnier 2018-08-24 17:59:30 +01:00
parent 6c4fe20f09
commit 8e8ce973c6
19 changed files with 90 additions and 76 deletions

View File

@ -45,7 +45,7 @@ public:
* Construct a NFCNDEFCapable instance.
* @param[in] buffer a bytes array used to store NDEF messages
*/
NFCNDEFCapable(const Span<uint8_t>& buffer);
NFCNDEFCapable(const Span<uint8_t> &buffer);
/**
* Check if this instance actually supports NDEF content.

View File

@ -49,7 +49,7 @@ public:
* @param[in] buffer a bytes array used to store NDEF messages
* @param[in] buffer_size the array size in bytes
*/
NFCRemoteInitiator(NFCController *controller, const Span<uint8_t>& buffer);
NFCRemoteInitiator(NFCController *controller, const Span<uint8_t> &buffer);
virtual ~NFCRemoteInitiator();
/**

View File

@ -62,9 +62,9 @@ public:
* record inserted fit.
*/
bool append_record(
const RecordType &type,
const RecordPayload &payload = RecordPayload(),
bool is_last_record = false
const RecordType &type,
const RecordPayload &payload = RecordPayload(),
bool is_last_record = false
);
/**
@ -109,17 +109,17 @@ private:
// append fields
void append_header(const Record &record);
void append_type_length(const Record &record);
void append_payload_length(const Record&);
void append_id_length(const Record&);
void append_type(const Record&);
void append_id(const Record&);
void append_payload(const Record&);
void append_payload_length(const Record &);
void append_id_length(const Record &);
void append_type(const Record &);
void append_id(const Record &);
void append_payload(const Record &);
// helpers
static size_t compute_record_size(const Record &record);
static bool is_short_payload(const Record &record);
// builder state.
// builder state.
Span<uint8_t> _message_buffer;
size_t _position;
bool _message_started;

View File

@ -161,7 +161,7 @@ private:
void report_parsing_started();
void report_record_parsed(const Record &record);
void report_parsing_terminated();
void report_parsing_error(error_t error, parsing_state_t& parsing_state);
void report_parsing_error(error_t error, parsing_state_t &parsing_state);
Delegate *_delegate;
};

View File

@ -193,12 +193,12 @@ struct Record {
/**
* If true, this record is a chunked record.
*/
bool chunk:1;
bool chunk: 1;
/**
* If true, this record is the last one of the payload containing it.
*/
bool last_record:1;
bool last_record: 1;
};

View File

@ -97,7 +97,7 @@ struct GenericRecordParser : public RecordParser {
virtual bool parse(const Record &record)
{
ParsingResult parsed_value;
if (static_cast<ParserImplementation*>(this)->do_parse(record, parsed_value)) {
if (static_cast<ParserImplementation *>(this)->do_parse(record, parsed_value)) {
if (_delegate) {
_delegate->on_record_parsed(parsed_value, record.id);
}

View File

@ -74,7 +74,7 @@ public:
* @param to_copy The Mime object to copy.
* @return a reference to this object
*/
Mime& operator=(const Mime &other);
Mime &operator=(const Mime &other);
/**
* Set all attributes of a mime object.

View File

@ -44,8 +44,7 @@ class SimpleMessageParser :
MessageParser::Delegate,
URIParser::Delegate,
TextParser::Delegate,
MimeParser::Delegate
{
MimeParser::Delegate {
public:
/**
* Delegate invoked when the parser raise an event.

View File

@ -84,7 +84,7 @@ public:
* @param to_copy The Text instance to copy
* @return a reference to this object.
*/
Text& operator=(const Text &to_copy);
Text &operator=(const Text &to_copy);
/**
* Copy a text from an external buffer.

View File

@ -115,7 +115,7 @@ public:
* @param to_copy The URI to copy.
* @return a reference to this object
*/
URI& operator=(const URI &to_copy);
URI &operator=(const URI &to_copy);
/**
* Replace the value of the URI.

View File

@ -40,9 +40,9 @@ namespace common {
* character.
*/
template<size_t N>
Span<const uint8_t, N-1> span_from_cstr(const char (&cstr)[N])
Span < const uint8_t, N - 1 > span_from_cstr(const char (&cstr)[N])
{
return Span<const uint8_t, N-1>((const uint8_t*)cstr, N-1);
return Span < const uint8_t, N - 1 > ((const uint8_t *)cstr, N - 1);
}
/**

View File

@ -25,7 +25,7 @@
using namespace mbed;
using namespace mbed::nfc;
NFCNDEFCapable::NFCNDEFCapable(const Span<uint8_t>& buffer) : _delegate(NULL)
NFCNDEFCapable::NFCNDEFCapable(const Span<uint8_t> &buffer) : _delegate(NULL)
{
ndef_msg_init(&_ndef_message, s_ndef_encode, s_ndef_decode, buffer.data(), buffer.size(), this);
}

View File

@ -31,10 +31,11 @@ MessageBuilder::MessageBuilder(const Span<uint8_t> &buffer) :
{ }
bool MessageBuilder::append_record(
const RecordType &type,
const RecordPayload &payload,
bool is_last_record
) {
const RecordType &type,
const RecordPayload &payload,
bool is_last_record
)
{
Record record(
type,
payload,
@ -93,10 +94,10 @@ bool MessageBuilder::append_record(const Record &record)
}
if (record.type.tnf == RecordType::well_known_type ||
record.type.tnf == RecordType::media_type ||
record.type.tnf == RecordType::absolute_uri ||
record.type.tnf == RecordType::external_type
) {
record.type.tnf == RecordType::media_type ||
record.type.tnf == RecordType::absolute_uri ||
record.type.tnf == RecordType::external_type
) {
if (record.type.value.empty()) {
return false;
}

View File

@ -102,9 +102,9 @@ struct MessageParser::parsing_state_t {
{ }
buffer_iterator_t it;
bool first_record_parsed:1;
bool last_record_parsed:1;
bool error:1;
bool first_record_parsed: 1;
bool last_record_parsed: 1;
bool error: 1;
};
MessageParser::MessageParser() :
@ -120,7 +120,7 @@ void MessageParser::parse(const Span<const uint8_t> &data_buffer)
{
parsing_state_t parsing_state(data_buffer);
report_parsing_started();
while(parsing_state.it && parse_record(parsing_state));
while (parsing_state.it && parse_record(parsing_state));
if (!parsing_state.error && !parsing_state.last_record_parsed) {
report_parsing_error(MISSING_MESSAGE_END, parsing_state);
}
@ -251,8 +251,8 @@ bool MessageParser::parse_record(parsing_state_t &s)
uint8_t MessageParser::compute_lengths_size(uint8_t header)
{
return 1 /* type_length size */ +
((header & Header::short_record_bit) ? 1 : 4) /* payload length */ +
((header & Header::id_length_bit) ? 1 : 0);
((header & Header::short_record_bit) ? 1 : 4) /* payload length */ +
((header & Header::id_length_bit) ? 1 : 0);
}
uint8_t MessageParser::extract_type_length(parsing_state_t &s)
@ -267,7 +267,7 @@ uint32_t MessageParser::extract_payload_length(parsing_state_t &s, uint8_t heade
payload_length = *s.it++;
} else {
s.it.read_be(
reinterpret_cast<uint8_t*>(&payload_length),
reinterpret_cast<uint8_t *>(&payload_length),
sizeof(payload_length)
);
}
@ -279,7 +279,8 @@ uint8_t MessageParser::extract_id_length(parsing_state_t &s, uint8_t header)
return (header & Header::id_length_bit) ? *s.it++ : 0;
}
void MessageParser::report_parsing_started() {
void MessageParser::report_parsing_started()
{
if (_delegate) {
_delegate->on_parsing_started();
}

View File

@ -53,7 +53,7 @@ Mime::~Mime()
delete[] _mime;
}
Mime& Mime::operator=(const Mime &to_copy)
Mime &Mime::operator=(const Mime &to_copy)
{
if (this == &to_copy) {
return * this;
@ -72,7 +72,8 @@ Mime& Mime::operator=(const Mime &to_copy)
void Mime::set_mime(
const Span<const uint8_t> &mime_type,
const Span<const uint8_t> &content
) {
)
{
delete[] _mime;
_mime = new uint8_t[mime_type.size() + content.size()];
@ -95,22 +96,24 @@ Span<const uint8_t> Mime::get_mime_content() const
bool Mime::append_as_record(
MessageBuilder &message_builder,
bool is_last_record
) {
)
{
return message_builder.append_record(
RecordType(
RecordType::media_type,
get_mime_type()
),
get_mime_content(),
is_last_record
);
RecordType(
RecordType::media_type,
get_mime_type()
),
get_mime_content(),
is_last_record
);
}
void Mime::move_data(
uint8_t *mime_record,
size_t mime_type_size,
size_t mime_content_size
) {
)
{
delete[] _mime;
_mime = mime_record;
_type_size = mime_type_size;

View File

@ -89,7 +89,8 @@ void SimpleMessageParser::on_parsing_terminated()
void SimpleMessageParser::on_record_parsed(
const URI &uri,
const RecordID &id
) {
)
{
if (_delegate) {
_delegate->on_uri_parsed(uri, id);
}
@ -98,7 +99,8 @@ void SimpleMessageParser::on_record_parsed(
void SimpleMessageParser::on_record_parsed(
const Text &text,
const RecordID &id
) {
)
{
if (_delegate) {
_delegate->on_text_parsed(text, id);
}
@ -107,7 +109,8 @@ void SimpleMessageParser::on_record_parsed(
void SimpleMessageParser::on_record_parsed(
const Mime &mime,
const RecordID &id
) {
)
{
if (_delegate) {
_delegate->on_mime_parsed(mime, id);
}

View File

@ -59,7 +59,7 @@ Text::~Text()
delete[] _text_record;
}
Text& Text::operator=(const Text &other)
Text &Text::operator=(const Text &other)
{
if (this == &other) {
return *this;
@ -82,7 +82,8 @@ void Text::set_text(
encoding_t text_encoding,
const Span<const uint8_t> &language_code,
const Span<const uint8_t> &text
) {
)
{
delete[] _text_record;
_text_record_size = header_size + language_code.size() + text.size();
@ -107,23 +108,26 @@ Text::encoding_t Text::get_encoding() const
return (_text_record[header_index] & utf16_encoding_bit) ? UTF16 : UTF8;
}
Span<const uint8_t> Text::get_language_code() const {
Span<const uint8_t> Text::get_language_code() const
{
return make_const_Span(
_text_record + language_code_index,
_text_record[header_index] & language_code_size_mask
);
_text_record + language_code_index,
_text_record[header_index] & language_code_size_mask
);
}
Span<const uint8_t> Text::get_text() const {
Span<const uint8_t> Text::get_text() const
{
size_t language_code_size = get_language_code().size();
return make_const_Span(
_text_record + header_size + language_code_size,
_text_record_size - header_size - language_code_size
);
_text_record + header_size + language_code_size,
_text_record_size - header_size - language_code_size
);
}
void Text::move_data(uint8_t *text, size_t size) {
void Text::move_data(uint8_t *text, size_t size)
{
delete[] _text_record;
_text_record = text;
_text_record_size = size;
@ -132,7 +136,8 @@ void Text::move_data(uint8_t *text, size_t size) {
bool Text::append_as_record(
MessageBuilder &message_builder,
bool is_last_record
) {
)
{
// Build the record type
RecordType type(
RecordType::well_known_type,
@ -152,8 +157,8 @@ bool TextParser::do_parse(const Record &record, Text &text)
// the record type value should be equal to `T`
if (record.type.value != make_const_Span(text_record_type_value) ||
record.payload.empty()
) {
record.payload.empty()
) {
return false;
}

View File

@ -32,7 +32,8 @@ namespace common {
URI::URI() :
_uri(NULL),
_uri_size(0) {
_uri_size(0)
{
}
URI::URI(uri_identifier_code_t id, const Span<const uint8_t> &uri_field) :
@ -55,7 +56,7 @@ URI::~URI()
delete[] _uri;
}
URI& URI::operator=(const URI &other)
URI &URI::operator=(const URI &other)
{
delete[] _uri;
@ -74,7 +75,8 @@ URI& URI::operator=(const URI &other)
void URI::set_uri(
uri_identifier_code_t id,
const Span<const uint8_t> &uri_field
) {
)
{
delete[] _uri;
if (uri_field.empty()) {
@ -104,9 +106,9 @@ Span<const uint8_t> URI::get_uri_field() const
return Span<const uint8_t>();
}
return make_const_Span(
_uri + uri_field_index,
_uri_size - uri_id_code_size
);
_uri + uri_field_index,
_uri_size - uri_id_code_size
);
}
bool URI::append_as_record(MessageBuilder &message_builder, bool is_last_record)
@ -142,8 +144,8 @@ bool URIParser::do_parse(const Record &record, URI &uri)
// the record type value should be equal to `U`
if (record.type.value != make_const_Span(uri_record_type_value) ||
record.payload.empty()
) {
record.payload.empty()
) {
return false;
}

View File

@ -25,7 +25,7 @@ namespace common {
Span<const uint8_t> span_from_cstr(const char *cstr)
{
return Span<const uint8_t>((const uint8_t*)cstr, strlen(cstr));
return Span<const uint8_t>((const uint8_t *)cstr, strlen(cstr));
}
/**