Skip to content

Commit

Permalink
renamings
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Aug 27, 2024
1 parent 5668afc commit aaa7ec3
Showing 1 changed file with 55 additions and 55 deletions.
110 changes: 55 additions & 55 deletions include/flatmemory/details/types/optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ template<IsTriviallyCopyableOrNonTrivialType T>
class Layout<Optional<T>>
{
public:
static constexpr size_t bool_position = 0;
static constexpr size_t data_position = bool_position + sizeof(bool);
static constexpr size_t has_value_position = 0;
static constexpr size_t value_position = has_value_position + sizeof(bool);

constexpr void print() const;
};
Expand Down Expand Up @@ -186,9 +186,9 @@ class Builder<Optional<T>> : public IBuilder<Builder<Optional<T>>>
size_t finish_impl(size_t pos, ByteBuffer& out)
{
/* Write whether the optional has a value. */
out.write(pos + Layout<Optional<T>>::bool_position, m_has_value);
out.write(pos + Layout<Optional<T>>::has_value_position, m_has_value);

size_t data_pos = Layout<Optional<T>>::data_position;
size_t data_pos = Layout<Optional<T>>::value_position;

if (m_has_value)
{
Expand Down Expand Up @@ -319,9 +319,9 @@ class Builder<Optional<T>> : public IBuilder<Builder<Optional<T>>>
size_t finish_impl(size_t pos, ByteBuffer& out)
{
/* Write whether the optional has a value. */
out.write(pos + Layout<Optional<T>>::bool_position, m_has_value);
out.write(pos + Layout<Optional<T>>::has_value_position, m_has_value);

size_t data_pos = Layout<Optional<T>>::data_position;
size_t data_pos = Layout<Optional<T>>::value_position;

if (m_has_value)
{
Expand Down Expand Up @@ -352,27 +352,27 @@ class View<Optional<T>>
* Observers
*/

T operator->() { return read_value<T>(m_buf + Layout<Optional<T>>::data_position); }
T operator->() const { return read_value<T>(m_buf + Layout<Optional<T>>::data_position); }
T operator->() { return read_value<T>(m_buf + Layout<Optional<T>>::value_position); }
T operator->() const { return read_value<T>(m_buf + Layout<Optional<T>>::value_position); }

T operator*() & { return read_value<T>(m_buf + Layout<Optional<T>>::data_position); }
T operator*() const& { return read_value<T>(m_buf + Layout<Optional<T>>::data_position); }
T operator*() & { return read_value<T>(m_buf + Layout<Optional<T>>::value_position); }
T operator*() const& { return read_value<T>(m_buf + Layout<Optional<T>>::value_position); }

T operator*() && { return read_value<T>(m_buf + Layout<Optional<T>>::data_position); }
T operator*() const&& { return read_value<T>(m_buf + Layout<Optional<T>>::data_position); }
T operator*() && { return read_value<T>(m_buf + Layout<Optional<T>>::value_position); }
T operator*() const&& { return read_value<T>(m_buf + Layout<Optional<T>>::value_position); }

explicit operator bool() const { return read_value<bool>(m_buf + Layout<Optional<T>>::bool_position); }
bool has_value() const { return read_value<bool>(m_buf + Layout<Optional<T>>::bool_position); }
explicit operator bool() const { return read_value<bool>(m_buf + Layout<Optional<T>>::has_value_position); }
bool has_value() const { return read_value<bool>(m_buf + Layout<Optional<T>>::has_value_position); }

T value() & { return read_value<T>(m_buf + Layout<Optional<T>>::data_position); }
T value() const& { return read_value<T>(m_buf + Layout<Optional<T>>::data_position); }
T value() & { return read_value<T>(m_buf + Layout<Optional<T>>::value_position); }
T value() const& { return read_value<T>(m_buf + Layout<Optional<T>>::value_position); }

T value() && { return read_value<T>(m_buf + Layout<Optional<T>>::data_position); }
T value() const&& { return read_value<T>(m_buf + Layout<Optional<T>>::data_position); }
T value() && { return read_value<T>(m_buf + Layout<Optional<T>>::value_position); }
T value() const&& { return read_value<T>(m_buf + Layout<Optional<T>>::value_position); }

void mutate(T value) { write_value(m_buf + Layout<Optional<T>>::data_position, value); }
void mutate(const T& value) { write_value(m_buf + Layout<Optional<T>>::data_position, value); }
void mutate(T&& value) { write_value(m_buf + Layout<Optional<T>>::data_position, std::move(value)); }
void mutate(T value) { write_value(m_buf + Layout<Optional<T>>::value_position, value); }
void mutate(const T& value) { write_value(m_buf + Layout<Optional<T>>::value_position, value); }
void mutate(T&& value) { write_value(m_buf + Layout<Optional<T>>::value_position, std::move(value)); }

uint8_t* buffer() { return m_buf; }
const uint8_t* buffer() const { return m_buf; }
Expand All @@ -381,9 +381,9 @@ class View<Optional<T>>
{
if (!has_value())
{
return Layout<Optional<T>>::data_position;
return Layout<Optional<T>>::value_position;
}
return Layout<Optional<T>>::data_position + sizeof(T);
return Layout<Optional<T>>::value_position + sizeof(T);
}

private:
Expand All @@ -409,23 +409,23 @@ class View<Optional<T>>
* Observers
*/

View<T> operator->() { return View<T>(m_buf + Layout<Optional<T>>::data_position); }
ConstView<T> operator->() const { return ConstView<T>(m_buf + Layout<Optional<T>>::data_position); }
View<T> operator->() { return View<T>(m_buf + Layout<Optional<T>>::value_position); }
ConstView<T> operator->() const { return ConstView<T>(m_buf + Layout<Optional<T>>::value_position); }

View<T> operator*() & { return View<T>(m_buf + Layout<Optional<T>>::data_position); }
ConstView<T> operator*() const& { return ConstView<T>(m_buf + Layout<Optional<T>>::data_position); }
View<T> operator*() & { return View<T>(m_buf + Layout<Optional<T>>::value_position); }
ConstView<T> operator*() const& { return ConstView<T>(m_buf + Layout<Optional<T>>::value_position); }

View<T> operator*() && { return View<T>(m_buf + Layout<Optional<T>>::data_position); }
ConstView<T> operator*() const&& { return ConstView<T>(m_buf + Layout<Optional<T>>::data_position); }
View<T> operator*() && { return View<T>(m_buf + Layout<Optional<T>>::value_position); }
ConstView<T> operator*() const&& { return ConstView<T>(m_buf + Layout<Optional<T>>::value_position); }

explicit operator bool() const { return read_value<bool>(m_buf + Layout<Optional<T>>::bool_position); }
bool has_value() const { return read_value<bool>(m_buf + Layout<Optional<T>>::bool_position); }
explicit operator bool() const { return read_value<bool>(m_buf + Layout<Optional<T>>::has_value_position); }
bool has_value() const { return read_value<bool>(m_buf + Layout<Optional<T>>::has_value_position); }

View<T> value() & { return View<T>(m_buf + Layout<Optional<T>>::data_position); }
ConstView<T> value() const& { return ConstView<T>(m_buf + Layout<Optional<T>>::data_position); }
View<T> value() & { return View<T>(m_buf + Layout<Optional<T>>::value_position); }
ConstView<T> value() const& { return ConstView<T>(m_buf + Layout<Optional<T>>::value_position); }

View<T> value() && { return View<T>(m_buf + Layout<Optional<T>>::data_position); }
ConstView<T> value() const&& { return ConstView<T>(m_buf + Layout<Optional<T>>::data_position); }
View<T> value() && { return View<T>(m_buf + Layout<Optional<T>>::value_position); }
ConstView<T> value() const&& { return ConstView<T>(m_buf + Layout<Optional<T>>::value_position); }

uint8_t* buffer() { return m_buf; }
const uint8_t* buffer() const { return m_buf; }
Expand All @@ -434,9 +434,9 @@ class View<Optional<T>>
{
if (!has_value())
{
return Layout<Optional<T>>::data_position;
return Layout<Optional<T>>::value_position;
}
return Layout<Optional<T>>::data_position + sizeof(T);
return Layout<Optional<T>>::value_position + sizeof(T);
}

private:
Expand Down Expand Up @@ -466,28 +466,28 @@ class ConstView<Optional<T>>
* Observers
*/

T operator->() const { return read_value<T>(m_buf + Layout<Optional<T>>::data_position); }
T operator->() const { return read_value<T>(m_buf + Layout<Optional<T>>::value_position); }

T operator*() const& { return read_value<T>(m_buf + Layout<Optional<T>>::data_position); }
T operator*() const& { return read_value<T>(m_buf + Layout<Optional<T>>::value_position); }

T operator*() const&& { return read_value<T>(m_buf + Layout<Optional<T>>::data_position); }
T operator*() const&& { return read_value<T>(m_buf + Layout<Optional<T>>::value_position); }

explicit operator bool() const { return read_value<bool>(m_buf + Layout<Optional<T>>::bool_position); }
bool has_value() const { return read_value<bool>(m_buf + Layout<Optional<T>>::bool_position); }
explicit operator bool() const { return read_value<bool>(m_buf + Layout<Optional<T>>::has_value_position); }
bool has_value() const { return read_value<bool>(m_buf + Layout<Optional<T>>::has_value_position); }

T value() const& { return read_value<T>(m_buf + Layout<Optional<T>>::data_position); }
T value() const& { return read_value<T>(m_buf + Layout<Optional<T>>::value_position); }

T value() const&& { return read_value<T>(m_buf + Layout<Optional<T>>::data_position); }
T value() const&& { return read_value<T>(m_buf + Layout<Optional<T>>::value_position); }

const uint8_t* buffer() const { return m_buf; }

BufferSizeType buffer_size() const
{
if (!has_value())
{
return Layout<Optional<T>>::data_position;
return Layout<Optional<T>>::value_position;
}
return Layout<Optional<T>>::data_position + sizeof(T);
return Layout<Optional<T>>::value_position + sizeof(T);
}

private:
Expand All @@ -513,28 +513,28 @@ class ConstView<Optional<T>>
* Observers
*/

ConstView<T> operator->() const { return ConstView<T>(m_buf + Layout<Optional<T>>::data_position); }
ConstView<T> operator->() const { return ConstView<T>(m_buf + Layout<Optional<T>>::value_position); }

ConstView<T> operator*() const& { return ConstView<T>(m_buf + Layout<Optional<T>>::data_position); }
ConstView<T> operator*() const& { return ConstView<T>(m_buf + Layout<Optional<T>>::value_position); }

ConstView<T> operator*() const&& { return ConstView<T>(m_buf + Layout<Optional<T>>::data_position); }
ConstView<T> operator*() const&& { return ConstView<T>(m_buf + Layout<Optional<T>>::value_position); }

explicit operator bool() const { return read_value<bool>(m_buf + Layout<Optional<T>>::bool_position); }
bool has_value() const { return read_value<bool>(m_buf + Layout<Optional<T>>::bool_position); }
explicit operator bool() const { return read_value<bool>(m_buf + Layout<Optional<T>>::has_value_position); }
bool has_value() const { return read_value<bool>(m_buf + Layout<Optional<T>>::has_value_position); }

ConstView<T> value() const& { return ConstView<T>(m_buf + Layout<Optional<T>>::data_position); }
ConstView<T> value() const& { return ConstView<T>(m_buf + Layout<Optional<T>>::value_position); }

ConstView<T> value() const&& { return ConstView<T>(m_buf + Layout<Optional<T>>::data_position); }
ConstView<T> value() const&& { return ConstView<T>(m_buf + Layout<Optional<T>>::value_position); }

const uint8_t* buffer() const { return m_buf; }

BufferSizeType buffer_size() const
{
if (!has_value())
{
return Layout<Optional<T>>::data_position;
return Layout<Optional<T>>::value_position;
}
return Layout<Optional<T>>::data_position + sizeof(T);
return Layout<Optional<T>>::value_position + sizeof(T);
}

private:
Expand Down

0 comments on commit aaa7ec3

Please sign in to comment.