Row.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/NonnullRefPtr.h>
  8. #include <LibSQL/Forward.h>
  9. #include <LibSQL/Meta.h>
  10. #include <LibSQL/Tuple.h>
  11. #include <LibSQL/Value.h>
  12. namespace SQL {
  13. /**
  14. * A Tuple is an element of a sequential-access persistence data structure
  15. * like a flat table. Like a key it has a definition for all its parts,
  16. * but unlike a key this definition is not optional.
  17. *
  18. * FIXME Tuples should logically belong to a TupleStore object, but right now
  19. * they stand by themselves; they contain a row's worth of data and a pointer
  20. * to the next Tuple.
  21. */
  22. class Row : public Tuple {
  23. public:
  24. explicit Row(NonnullRefPtr<TableDef>, u32 pointer = 0);
  25. virtual ~Row() override = default;
  26. [[nodiscard]] u32 next_pointer() const { return m_next_pointer; }
  27. void set_next_pointer(u32 ptr) { m_next_pointer = ptr; }
  28. TableDef const& table() const { return *m_table; }
  29. TableDef& table() { return *m_table; }
  30. [[nodiscard]] virtual size_t length() const override { return Tuple::length() + sizeof(u32); }
  31. virtual void serialize(Serializer&) const override;
  32. virtual void deserialize(Serializer&) override;
  33. private:
  34. NonnullRefPtr<TableDef> m_table;
  35. u32 m_next_pointer { 0 };
  36. };
  37. }