Row.h 1.3 KB

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