Row.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/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. Row();
  25. explicit Row(TupleDescriptor const&);
  26. explicit Row(RefPtr<TableDef>, u32 pointer = 0);
  27. Row(RefPtr<TableDef>, u32, Serializer&);
  28. Row(Row const&) = default;
  29. virtual ~Row() override = default;
  30. [[nodiscard]] u32 next_pointer() const { return m_next_pointer; }
  31. void next_pointer(u32 ptr) { m_next_pointer = ptr; }
  32. RefPtr<TableDef> table() const { return m_table; }
  33. [[nodiscard]] virtual size_t length() const override { return Tuple::length() + sizeof(u32); }
  34. virtual void serialize(Serializer&) const override;
  35. virtual void deserialize(Serializer&) override;
  36. protected:
  37. void copy_from(Row const&);
  38. private:
  39. RefPtr<TableDef> m_table;
  40. u32 m_next_pointer { 0 };
  41. };
  42. }