Uncrustify and fix issues reported by cpplint

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2019-08-17 15:18:57 +02:00 committed by eboasson
parent 130d6ea10e
commit 5e137205f2
7 changed files with 2664 additions and 2204 deletions

View file

@ -111,21 +111,27 @@ template<typename MembersType>
class TypeSupport
{
public:
bool serializeROSmessage(const void * ros_message, cycser & ser, std::function<void(cycser&)> prefix = nullptr);
bool deserializeROSmessage(cycdeser & deser, void * ros_message, std::function<void(cycdeser&)> prefix = nullptr);
std::string getName ();
bool serializeROSmessage(
const void * ros_message, cycser & ser,
std::function<void(cycser &)> prefix = nullptr);
bool deserializeROSmessage(
cycdeser & deser, void * ros_message,
std::function<void(cycdeser &)> prefix = nullptr);
std::string getName();
protected:
TypeSupport();
void setName(const std::string& name);
void setName(const std::string & name);
const MembersType * members_;
std::string name;
private:
bool serializeROSmessage(cycser & ser, const MembersType * members, const void * ros_message);
bool deserializeROSmessage(cycdeser & deser, const MembersType * members, void * ros_message, bool call_new);
bool deserializeROSmessage(
cycdeser & deser, const MembersType * members, void * ros_message,
bool call_new);
};
} // namespace rmw_cyclonedds_cpp

View file

@ -109,13 +109,13 @@ rosidl_generator_c__void__Sequence__fini(rosidl_generator_c__void__Sequence * se
template<typename MembersType>
TypeSupport<MembersType>::TypeSupport()
{
name = "";
name = "";
}
template<typename MembersType>
void TypeSupport<MembersType>::setName(const std::string& name)
void TypeSupport<MembersType>::setName(const std::string & name)
{
this->name = std::string(name);
this->name = std::string(name);
}
static inline void *
@ -502,7 +502,9 @@ inline void deserialize_field<std::string>(
deser >> cpp_string_vector;
auto & string_array_field = *reinterpret_cast<rosidl_generator_c__String__Sequence *>(field);
if (!rosidl_generator_c__String__Sequence__init(&string_array_field, cpp_string_vector.size())) {
if (!rosidl_generator_c__String__Sequence__init(&string_array_field,
cpp_string_vector.size()))
{
throw std::runtime_error("unable to initialize rosidl_generator_c__String array");
}
@ -649,7 +651,7 @@ bool TypeSupport<MembersType>::deserializeROSmessage(
template<typename MembersType>
bool TypeSupport<MembersType>::serializeROSmessage(
const void * ros_message, cycser & ser,
std::function<void(cycser&)> prefix)
std::function<void(cycser &)> prefix)
{
assert(ros_message);
@ -669,7 +671,7 @@ bool TypeSupport<MembersType>::serializeROSmessage(
template<typename MembersType>
bool TypeSupport<MembersType>::deserializeROSmessage(
cycdeser & deser, void * ros_message,
std::function<void(cycdeser&)> prefix)
std::function<void(cycdeser &)> prefix)
{
assert(ros_message);
@ -689,7 +691,7 @@ bool TypeSupport<MembersType>::deserializeROSmessage(
}
template<typename MembersType>
std::string TypeSupport<MembersType>::getName ()
std::string TypeSupport<MembersType>::getName()
{
return name;
}

View file

@ -11,47 +11,65 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SERDATA_HPP
#define SERDATA_HPP
#ifndef RMW_CYCLONEDDS_CPP__SERDATA_HPP_
#define RMW_CYCLONEDDS_CPP__SERDATA_HPP_
#include <string>
#include <vector>
#include "dds/ddsi/ddsi_sertopic.h"
#include "dds/ddsi/ddsi_serdata.h"
struct CddsTypeSupport {
void *type_support_;
const char *typesupport_identifier_;
struct CddsTypeSupport
{
void * type_support_;
const char * typesupport_identifier_;
};
struct sertopic_rmw : ddsi_sertopic {
CddsTypeSupport type_support;
bool is_request_header;
std::string cpp_name;
std::string cpp_type_name;
std::string cpp_name_type_name;
struct sertopic_rmw : ddsi_sertopic
{
CddsTypeSupport type_support;
bool is_request_header;
std::string cpp_name;
std::string cpp_type_name;
std::string cpp_name_type_name;
};
struct serdata_rmw : ddsi_serdata {
/* first two bytes of data is CDR encoding
second two bytes are encoding options */
std::vector<unsigned char> data;
struct serdata_rmw : ddsi_serdata
{
/* first two bytes of data is CDR encoding
second two bytes are encoding options */
std::vector<unsigned char> data;
};
typedef struct cdds_request_header {
uint64_t guid;
int64_t seq;
typedef struct cdds_request_header
{
uint64_t guid;
int64_t seq;
} cdds_request_header_t;
typedef struct cdds_request_wrapper {
cdds_request_header_t header;
void *data;
typedef struct cdds_request_wrapper
{
cdds_request_header_t header;
void * data;
} cdds_request_wrapper_t;
void *create_message_type_support (const void *untyped_members, const char *typesupport_identifier);
void *create_request_type_support (const void *untyped_members, const char *typesupport_identifier);
void *create_response_type_support (const void *untyped_members, const char *typesupport_identifier);
void * create_message_type_support(
const void * untyped_members,
const char * typesupport_identifier);
void * create_request_type_support(
const void * untyped_members,
const char * typesupport_identifier);
void * create_response_type_support(
const void * untyped_members,
const char * typesupport_identifier);
struct sertopic_rmw *create_sertopic (const char *topicname, const char *type_support_identifier, void *type_support, bool is_request_header);
struct sertopic_rmw * create_sertopic(
const char * topicname, const char * type_support_identifier,
void * type_support, bool is_request_header);
struct ddsi_serdata *serdata_rmw_from_serialized_message (const struct ddsi_sertopic *topiccmn, const void *raw, size_t size);
struct ddsi_serdata * serdata_rmw_from_serialized_message(
const struct ddsi_sertopic * topiccmn,
const void * raw, size_t size);
#endif
#endif // RMW_CYCLONEDDS_CPP__SERDATA_HPP_

View file

@ -1,4 +1,4 @@
// Copyright 2018 ADLINK Technology
// Copyright 2018 to 2019 ADLINK Technology
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -12,238 +12,263 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SERDES_HPP
#define SERDES_HPP
#ifndef RMW_CYCLONEDDS_CPP__SERDES_HPP_
#define RMW_CYCLONEDDS_CPP__SERDES_HPP_
#include <string.h>
#include <array>
#include <string>
#include <vector>
#include <string.h>
#include <type_traits>
class cycser {
class cycser
{
public:
cycser (std::vector<unsigned char>& dst_);
cycser () = delete;
explicit cycser(std::vector<unsigned char> & dst_);
cycser() = delete;
inline cycser& operator<< (bool x) { serialize (x); return *this; }
inline cycser& operator<< (char x) { serialize (x); return *this; }
inline cycser& operator<< (int8_t x) { serialize (x); return *this; }
inline cycser& operator<< (uint8_t x) { serialize (x); return *this; }
inline cycser& operator<< (int16_t x) { serialize (x); return *this; }
inline cycser& operator<< (uint16_t x) { serialize (x); return *this; }
inline cycser& operator<< (int32_t x) { serialize (x); return *this; }
inline cycser& operator<< (uint32_t x) { serialize (x); return *this; }
inline cycser& operator<< (int64_t x) { serialize (x); return *this; }
inline cycser& operator<< (uint64_t x) { serialize (x); return *this; }
inline cycser& operator<< (float x) { serialize (x); return *this; }
inline cycser& operator<< (double x) { serialize (x); return *this; }
inline cycser& operator<< (const char *x) { serialize (x); return *this; }
inline cycser& operator<< (const std::string& x) { serialize (x); return *this; }
template<class T> inline cycser& operator<< (const std::vector<T>& x) { serialize (x); return *this; }
template<class T, size_t S> inline cycser& operator<< (const std::array<T, S>& x) { serialize (x); return *this; }
inline cycser & operator<<(bool x) {serialize(x); return *this;}
inline cycser & operator<<(char x) {serialize(x); return *this;}
inline cycser & operator<<(int8_t x) {serialize(x); return *this;}
inline cycser & operator<<(uint8_t x) {serialize(x); return *this;}
inline cycser & operator<<(int16_t x) {serialize(x); return *this;}
inline cycser & operator<<(uint16_t x) {serialize(x); return *this;}
inline cycser & operator<<(int32_t x) {serialize(x); return *this;}
inline cycser & operator<<(uint32_t x) {serialize(x); return *this;}
inline cycser & operator<<(int64_t x) {serialize(x); return *this;}
inline cycser & operator<<(uint64_t x) {serialize(x); return *this;}
inline cycser & operator<<(float x) {serialize(x); return *this;}
inline cycser & operator<<(double x) {serialize(x); return *this;}
inline cycser & operator<<(const char * x) {serialize(x); return *this;}
inline cycser & operator<<(const std::string & x) {serialize(x); return *this;}
template<class T>
inline cycser & operator<<(const std::vector<T> & x) {serialize(x); return *this;}
template<class T, size_t S>
inline cycser & operator<<(const std::array<T, S> & x) {serialize(x); return *this;}
#define SIMPLE(T) inline void serialize (T x) { \
if ((off % sizeof (T)) != 0) { \
off += sizeof (T) - (off % sizeof (T)); \
} \
resize (off + sizeof (T)); \
*(T *) (data () + off) = x; \
off += sizeof (T); \
}
SIMPLE (char);
SIMPLE (int8_t);
SIMPLE (uint8_t);
SIMPLE (int16_t);
SIMPLE (uint16_t);
SIMPLE (int32_t);
SIMPLE (uint32_t);
SIMPLE (int64_t);
SIMPLE (uint64_t);
SIMPLE (float);
SIMPLE (double);
#define SIMPLE(T) inline void serialize(T x) { \
if ((off % sizeof(T)) != 0) { \
off += sizeof(T) - (off % sizeof(T)); \
} \
resize(off + sizeof(T)); \
*(reinterpret_cast<T *>(data() + off)) = x; \
off += sizeof(T); \
}
SIMPLE(char);
SIMPLE(int8_t);
SIMPLE(uint8_t);
SIMPLE(int16_t);
SIMPLE(uint16_t);
SIMPLE(int32_t);
SIMPLE(uint32_t);
SIMPLE(int64_t);
SIMPLE(uint64_t);
SIMPLE(float);
SIMPLE(double);
#undef SIMPLE
inline void serialize (bool x) {
serialize (static_cast<unsigned char> (x));
}
inline void serialize (const char *x)
{
size_t sz = strlen (x) + 1;
serialize (static_cast<uint32_t> (sz));
resize (off + sz);
memcpy (data () + off, x, sz);
off += sz;
}
inline void serialize (const std::string& x)
{
size_t sz = x.size () + 1;
serialize (static_cast<uint32_t> (sz));
resize (off + sz);
memcpy (data () + off, x.c_str (), sz);
off += sz;
}
inline void serialize(bool x)
{
serialize(static_cast<unsigned char>(x));
}
inline void serialize(const char * x)
{
size_t sz = strlen(x) + 1;
serialize(static_cast<uint32_t>(sz));
resize(off + sz);
memcpy(data() + off, x, sz);
off += sz;
}
inline void serialize(const std::string & x)
{
size_t sz = x.size() + 1;
serialize(static_cast<uint32_t>(sz));
resize(off + sz);
memcpy(data() + off, x.c_str(), sz);
off += sz;
}
#define SIMPLEA(T) inline void serializeA (const T *x, size_t cnt) { \
if (cnt > 0) { \
if ((off % sizeof (T)) != 0) { \
off += sizeof (T) - (off % sizeof (T)); \
} \
resize (off + cnt * sizeof (T)); \
memcpy (data () + off, (void *) x, cnt * sizeof (T)); \
off += cnt * sizeof (T); \
} \
}
SIMPLEA (char);
SIMPLEA (int8_t);
SIMPLEA (uint8_t);
SIMPLEA (int16_t);
SIMPLEA (uint16_t);
SIMPLEA (int32_t);
SIMPLEA (uint32_t);
SIMPLEA (int64_t);
SIMPLEA (uint64_t);
SIMPLEA (float);
SIMPLEA (double);
#define SIMPLEA(T) inline void serializeA(const T * x, size_t cnt) { \
if (cnt > 0) { \
if ((off % sizeof(T)) != 0) { \
off += sizeof(T) - (off % sizeof(T)); \
} \
resize(off + cnt * sizeof(T)); \
memcpy(data() + off, reinterpret_cast<const void *>(x), cnt * sizeof(T)); \
off += cnt * sizeof(T); \
} \
}
SIMPLEA(char);
SIMPLEA(int8_t);
SIMPLEA(uint8_t);
SIMPLEA(int16_t);
SIMPLEA(uint16_t);
SIMPLEA(int32_t);
SIMPLEA(uint32_t);
SIMPLEA(int64_t);
SIMPLEA(uint64_t);
SIMPLEA(float);
SIMPLEA(double);
#undef SIMPLEA
template<class T> inline void serializeA (const T *x, size_t cnt) {
for (size_t i = 0; i < cnt; i++) serialize (x[i]);
}
template<class T>
inline void serializeA(const T * x, size_t cnt)
{
for (size_t i = 0; i < cnt; i++) {serialize(x[i]);}
}
template<class T> inline void serialize (const std::vector<T>& x)
{
serialize (static_cast<uint32_t> (x.size ()));
serializeA (x.data (), x.size ());
}
inline void serialize (const std::vector<bool>& x) {
serialize (static_cast<uint32_t> (x.size ()));
for (auto&& i : x) serialize (i);
}
template<class T>
inline void serialize(const std::vector<T> & x)
{
serialize(static_cast<uint32_t>(x.size()));
serializeA(x.data(), x.size());
}
inline void serialize(const std::vector<bool> & x)
{
serialize(static_cast<uint32_t>(x.size()));
for (auto && i : x) {serialize(i);}
}
template<class T> inline void serializeS (const T *x, size_t cnt)
{
serialize (static_cast<uint32_t> (cnt));
serializeA (x, cnt);
}
template<class T>
inline void serializeS(const T * x, size_t cnt)
{
serialize(static_cast<uint32_t>(cnt));
serializeA(x, cnt);
}
private:
inline void resize (size_t n) { dst.resize (n + 4); }
inline unsigned char *data () { return dst.data () + 4; }
inline void resize(size_t n) {dst.resize(n + 4);}
inline unsigned char * data() {return dst.data() + 4;}
std::vector<unsigned char>& dst;
size_t off;
std::vector<unsigned char> & dst;
size_t off;
};
class cycdeser {
class cycdeser
{
public:
// FIXME: byteswapping
cycdeser (const void *data, size_t size);
cycdeser () = delete;
// FIXME: byteswapping
cycdeser(const void * data, size_t size);
cycdeser() = delete;
inline cycdeser& operator>> (bool& x) { deserialize (x); return *this; }
inline cycdeser& operator>> (char& x) { deserialize (x); return *this; }
inline cycdeser& operator>> (int8_t& x) { deserialize (x); return *this; }
inline cycdeser& operator>> (uint8_t& x) { deserialize (x); return *this; }
inline cycdeser& operator>> (int16_t& x) { deserialize (x); return *this; }
inline cycdeser& operator>> (uint16_t& x) { deserialize (x); return *this; }
inline cycdeser& operator>> (int32_t& x) { deserialize (x); return *this; }
inline cycdeser& operator>> (uint32_t& x) { deserialize (x); return *this; }
inline cycdeser& operator>> (int64_t& x) { deserialize (x); return *this; }
inline cycdeser& operator>> (uint64_t& x) { deserialize (x); return *this; }
inline cycdeser& operator>> (float& x) { deserialize (x); return *this; }
inline cycdeser& operator>> (double& x) { deserialize (x); return *this; }
inline cycdeser& operator>> (char *& x) { deserialize (x); return *this; }
inline cycdeser& operator>> (std::string& x) { deserialize (x); return *this; }
template<class T> inline cycdeser& operator>> (std::vector<T>& x) { deserialize (x); return *this; }
template<class T, size_t S> inline cycdeser& operator>> (std::array<T, S>& x) { deserialize (x); return *this; }
inline cycdeser & operator>>(bool & x) {deserialize(x); return *this;}
inline cycdeser & operator>>(char & x) {deserialize(x); return *this;}
inline cycdeser & operator>>(int8_t & x) {deserialize(x); return *this;}
inline cycdeser & operator>>(uint8_t & x) {deserialize(x); return *this;}
inline cycdeser & operator>>(int16_t & x) {deserialize(x); return *this;}
inline cycdeser & operator>>(uint16_t & x) {deserialize(x); return *this;}
inline cycdeser & operator>>(int32_t & x) {deserialize(x); return *this;}
inline cycdeser & operator>>(uint32_t & x) {deserialize(x); return *this;}
inline cycdeser & operator>>(int64_t & x) {deserialize(x); return *this;}
inline cycdeser & operator>>(uint64_t & x) {deserialize(x); return *this;}
inline cycdeser & operator>>(float & x) {deserialize(x); return *this;}
inline cycdeser & operator>>(double & x) {deserialize(x); return *this;}
inline cycdeser & operator>>(char * & x) {deserialize(x); return *this;}
inline cycdeser & operator>>(std::string & x) {deserialize(x); return *this;}
template<class T>
inline cycdeser & operator>>(std::vector<T> & x) {deserialize(x); return *this;}
template<class T, size_t S>
inline cycdeser & operator>>(std::array<T, S> & x) {deserialize(x); return *this;}
#define SIMPLE(T) inline void deserialize (T& x) { \
align (sizeof (x)); \
x = *reinterpret_cast<const T *> (data + pos); \
pos += sizeof (x); \
}
SIMPLE (char);
SIMPLE (int8_t);
SIMPLE (uint8_t);
SIMPLE (int16_t);
SIMPLE (uint16_t);
SIMPLE (int32_t);
SIMPLE (uint32_t);
SIMPLE (int64_t);
SIMPLE (uint64_t);
SIMPLE (float);
SIMPLE (double);
#define SIMPLE(T) inline void deserialize(T & x) { \
align(sizeof(x)); \
x = *reinterpret_cast<const T *>(data + pos); \
pos += sizeof(x); \
}
SIMPLE(char);
SIMPLE(int8_t);
SIMPLE(uint8_t);
SIMPLE(int16_t);
SIMPLE(uint16_t);
SIMPLE(int32_t);
SIMPLE(uint32_t);
SIMPLE(int64_t);
SIMPLE(uint64_t);
SIMPLE(float);
SIMPLE(double);
#undef SIMPLE
inline void deserialize (bool& x) {
unsigned char z; deserialize (z); x = (z != 0);
}
inline uint32_t deserialize32 () {
uint32_t sz; deserialize (sz); return sz;
}
inline void deserialize (char *& x) {
const uint32_t sz = deserialize32 ();
x = (char *) malloc (sz);
memcpy (x, data + pos, sz);
pos += sz;
}
inline void deserialize (std::string& x) {
const uint32_t sz = deserialize32 ();
x = std::string (data + pos, sz-1);
pos += sz;
}
inline void deserialize(bool & x)
{
unsigned char z; deserialize(z); x = (z != 0);
}
inline uint32_t deserialize32()
{
uint32_t sz; deserialize(sz); return sz;
}
inline void deserialize(char * & x)
{
const uint32_t sz = deserialize32();
x = reinterpret_cast<char *>(malloc(sz));
memcpy(x, data + pos, sz);
pos += sz;
}
inline void deserialize(std::string & x)
{
const uint32_t sz = deserialize32();
x = std::string(data + pos, sz - 1);
pos += sz;
}
#define SIMPLEA(T) inline void deserializeA (T *x, size_t cnt) { \
if (cnt > 0) { \
align (sizeof (T)); \
memcpy ((void *) x, (void *) (data + pos), (cnt) * sizeof (T)); \
pos += (cnt) * sizeof (T); \
} \
}
SIMPLEA (char);
SIMPLEA (int8_t);
SIMPLEA (uint8_t);
SIMPLEA (int16_t);
SIMPLEA (uint16_t);
SIMPLEA (int32_t);
SIMPLEA (uint32_t);
SIMPLEA (int64_t);
SIMPLEA (uint64_t);
SIMPLEA (float);
SIMPLEA (double);
#define SIMPLEA(T) inline void deserializeA(T * x, size_t cnt) { \
if (cnt > 0) { \
align(sizeof(T)); \
memcpy(reinterpret_cast<void *>(x), reinterpret_cast<const void *>(data + pos), \
(cnt) * sizeof(T)); \
pos += (cnt) * sizeof(T); \
} \
}
SIMPLEA(char);
SIMPLEA(int8_t);
SIMPLEA(uint8_t);
SIMPLEA(int16_t);
SIMPLEA(uint16_t);
SIMPLEA(int32_t);
SIMPLEA(uint32_t);
SIMPLEA(int64_t);
SIMPLEA(uint64_t);
SIMPLEA(float);
SIMPLEA(double);
#undef SIMPLEA
template<class T> inline void deserializeA (T *x, size_t cnt) {
for (size_t i = 0; i < cnt; i++) deserialize (x[i]);
}
template<class T>
inline void deserializeA(T * x, size_t cnt)
{
for (size_t i = 0; i < cnt; i++) {deserialize(x[i]);}
}
template<class T> inline void deserialize (std::vector<T>& x) {
const uint32_t sz = deserialize32 ();
x.resize (sz);
deserializeA (x.data (), sz);
}
inline void deserialize (std::vector<bool>& x) {
const uint32_t sz = deserialize32 ();
x.resize (sz);
for (size_t i = 0; i < sz; i++) {
x[i] = ((data + pos)[i] != 0);
}
pos += sz;
}
template<class T, size_t S> inline void deserialize (std::array<T, S>& x) {
deserializeA (x.data (), x.size ());
template<class T>
inline void deserialize(std::vector<T> & x)
{
const uint32_t sz = deserialize32();
x.resize(sz);
deserializeA(x.data(), sz);
}
inline void deserialize(std::vector<bool> & x)
{
const uint32_t sz = deserialize32();
x.resize(sz);
for (size_t i = 0; i < sz; i++) {
x[i] = ((data + pos)[i] != 0);
}
pos += sz;
}
template<class T, size_t S>
inline void deserialize(std::array<T, S> & x)
{
deserializeA(x.data(), x.size());
}
private:
inline void align (size_t a)
{
if ((pos % a) != 0) {
pos += a - (pos % a);
}
inline void align(size_t a)
{
if ((pos % a) != 0) {
pos += a - (pos % a);
}
}
const char *data;
size_t pos;
size_t lim; // ignored for now ... better provide correct input
const char * data;
size_t pos;
size_t lim; // ignored for now ... better provide correct input
};
#endif
#endif // RMW_CYCLONEDDS_CPP__SERDES_HPP_