From 41ad2bdea52771a8f486a0be6098e6e45786bdcd Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Thu, 16 Nov 2017 17:51:16 +0100 Subject: [PATCH] Matrix: added copyToRaw method to allow copying to a pointer because most uORB messages still contain all components of a vector one by one after each other --- matrix/Matrix.hpp | 5 +++++ test/copyto.cpp | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/matrix/Matrix.hpp b/matrix/Matrix.hpp index 559a8d804d..30b7fa929e 100644 --- a/matrix/Matrix.hpp +++ b/matrix/Matrix.hpp @@ -87,6 +87,11 @@ public: memcpy(dst, _data, sizeof(dst)); } + void copyToRaw(Type *dst) const + { + memcpy(dst, _data, sizeof(_data)); + } + void copyToColumnMajor(Type (&dst)[M*N]) const { const Matrix &self = *this; diff --git a/test/copyto.cpp b/test/copyto.cpp index 0a9ccb20f7..fe35cff672 100644 --- a/test/copyto.cpp +++ b/test/copyto.cpp @@ -38,6 +38,13 @@ int main() TEST(fabs(array_A[i] - array_row[i]) < eps); } + // Matrix copyTo with a pointer + A.copyToRaw(static_cast (array_A)); + float array_row_p[6] = {1, 2, 3, 4, 5, 6}; + for (size_t i = 0; i < 6; i++) { + TEST(fabs(array_A[i] - array_row_p[i]) < eps); + } + // Matrix copyToColumnMajor A.copyToColumnMajor(array_A); float array_column[6] = {1, 4, 2, 5, 3, 6};