Commit 607ef3d2 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

core: update message structure

This patch change the size of real array from 3 to 4 doubles. This patch
remove the length attribute. Now the size computed from the no-zero
value.
parent 61274ee0
...@@ -617,46 +617,60 @@ struct message ...@@ -617,46 +617,60 @@ struct message
using size_type = std::size_t; using size_type = std::size_t;
using difference_type = std::ptrdiff_t; using difference_type = std::ptrdiff_t;
double real[3]; double real[4];
i8 length;
constexpr std::size_t size() const noexcept constexpr size_type size() const noexcept
{
return real[3] ? 4u : real[2] ? 3u : real[1] ? 2u : real[0] ? 1u : 0u;
}
constexpr difference_type ssize() const noexcept
{ {
irt_assert(length >= 0); return real[3] ? 4 : real[2] ? 3 : real[1] ? 2 : real[0] ? 1 : 0;
return static_cast<std::size_t>(length);
} }
constexpr message() noexcept constexpr message() noexcept
: real{ 0.0, 0.0, 0.0 } : real{ 0., 0., 0., 0. }
, length{ 0 }
{} {}
constexpr message(const double v) noexcept constexpr message(const double v) noexcept
: real{ v, 0., 0. } : real{ v, 0., 0., 0. }
, length{ 1 }
{} {}
constexpr message(const double v1, const double v2) noexcept constexpr message(const double v1, const double v2) noexcept
: real{ v1, v2, 0. } : real{ v1, v2, 0., 0. }
, length{ 2 }
{} {}
constexpr message(const double v1, constexpr message(const double v1,
const double v2, const double v2,
const double v3) noexcept const double v3) noexcept
: real{ v1, v2, v3 } : real{ v1, v2, v3, 0. }
, length{ 3 } {}
constexpr message(const double v1,
const double v2,
const double v3,
const double v4) noexcept
: real{ v1, v2, v3, v4 }
{} {}
double operator[](const difference_type i) const noexcept constexpr double operator[](const difference_type i) const noexcept
{ {
return real[i]; return real[i];
} }
double& operator[](const difference_type i) noexcept constexpr double& operator[](const difference_type i) noexcept
{ {
return real[i]; return real[i];
} }
constexpr void reset() noexcept
{
real[0] = 0.;
real[1] = 0.;
real[2] = 0.;
real[3] = 0.;
}
}; };
/***************************************************************************** /*****************************************************************************
......
...@@ -544,10 +544,12 @@ main() ...@@ -544,10 +544,12 @@ main()
"message"_test = [] { "message"_test = [] {
{ {
irt::message vdouble; irt::message vdouble;
expect(vdouble.real[0] == 0.0); expect(vdouble[0] == 0.0);
expect(vdouble.real[1] == 0.0); expect(vdouble[1] == 0.0);
expect(vdouble.real[2] == 0.0); expect(vdouble[2] == 0.0);
expect(vdouble[3] == 0.0);
expect(vdouble.size() == 0_ul); expect(vdouble.size() == 0_ul);
expect(vdouble.ssize() == 0);
} }
{ {
...@@ -555,7 +557,9 @@ main() ...@@ -555,7 +557,9 @@ main()
expect(vdouble[0] == 1.0); expect(vdouble[0] == 1.0);
expect(vdouble[1] == 0.0); expect(vdouble[1] == 0.0);
expect(vdouble[2] == 0.0); expect(vdouble[2] == 0.0);
expect(vdouble[3] == 0.0);
expect(vdouble.size() == 1_ul); expect(vdouble.size() == 1_ul);
expect(vdouble.ssize() == 1);
} }
{ {
...@@ -563,15 +567,29 @@ main() ...@@ -563,15 +567,29 @@ main()
expect(vdouble[0] == 0.0); expect(vdouble[0] == 0.0);
expect(vdouble[1] == 1.0); expect(vdouble[1] == 1.0);
expect(vdouble[2] == 0.0); expect(vdouble[2] == 0.0);
expect(vdouble[3] == 0.0);
expect(vdouble.size() == 2_ul); expect(vdouble.size() == 2_ul);
expect(vdouble.ssize() == 2);
} }
{ {
irt::message vdouble(1.0, 2.0, 3.0); irt::message vdouble(0.0, 0.0, 1.0);
expect(vdouble[0] == 1.0); expect(vdouble[0] == 0.0);
expect(vdouble[1] == 2.0); expect(vdouble[1] == 0.0);
expect(vdouble[2] == 3.0); expect(vdouble[2] == 1.0);
expect(vdouble[3] == 0.0);
expect(vdouble.size() == 3_ul); expect(vdouble.size() == 3_ul);
expect(vdouble.ssize() == 3);
}
{
irt::message vdouble(0.0, 0.0, 0.0, 1.0);
expect(vdouble[0] == 0.0);
expect(vdouble[1] == 0.0);
expect(vdouble[2] == 0.0);
expect(vdouble[3] == 1.0);
expect(vdouble.size() == 4_ul);
expect(vdouble.ssize() == 4);
} }
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment