Row.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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/ByteBuffer.h>
  8. #include <AK/RefPtr.h>
  9. #include <LibSQL/Forward.h>
  10. #include <LibSQL/Meta.h>
  11. #include <LibSQL/Tuple.h>
  12. #include <LibSQL/Value.h>
  13. namespace SQL {
  14. /**
  15. * A Tuple is an element of a sequential-access persistence data structure
  16. * like a flat table. Like a key it has a definition for all its parts,
  17. * but unlike a key this definition is not optional.
  18. *
  19. * FIXME Tuples should logically belong to a TupleStore object, but right now
  20. * they stand by themselves; they contain a row's worth of data and a pointer
  21. * to the next Tuple.
  22. */
  23. class Row : public Tuple {
  24. public:
  25. Row();
  26. explicit Row(TupleDescriptor const&);
  27. explicit Row(RefPtr<TableDef>, u32 pointer = 0);
  28. Row(RefPtr<TableDef>, u32, Serializer&);
  29. Row(Row const&) = default;
  30. virtual ~Row() override = default;
  31. [[nodiscard]] u32 next_pointer() const { return m_next_pointer; }
  32. void set_next_pointer(u32 ptr) { m_next_pointer = ptr; }
  33. RefPtr<TableDef> table() const { return m_table; }
  34. [[nodiscard]] virtual size_t length() const override { return Tuple::length() + sizeof(u32); }
  35. virtual void serialize(Serializer&) const override;
  36. virtual void deserialize(Serializer&) override;
  37. protected:
  38. void copy_from(Row const&);
  39. private:
  40. RefPtr<TableDef> m_table;
  41. u32 m_next_pointer { 0 };
  42. };
  43. }