EHM DAL 0.2.5
Data abstraction layer for Eastside Hockey Manager
Loading...
Searching...
No Matches
pointer.h
1#pragma once
2
3// Application headers
4#include "include/database/pointer/pointer_flags.h"
5#include "include/database/pointer/private/abstract_pointer.h"
6#include "include/tables/abstract_table.h"
7#include "include/tables/table_index.h"
8
9// Qt headers
10class QDataStream;
11#include <memory>
12
13namespace ehm_dal::data_types {
14
15// --- Database/AbstractIdTableItem record pointer --- //
20 AbstractPointer<qint32, ehm_dal::tables::TableIndex, ehm_dal::tables::AbstractTable>
21{
22public:
23 Pointer();
25 const qint32 record_id = PointerFlags::NULL_POINTER);
26 virtual ~Pointer();
27
28 // File i/o
33 virtual void readFromShort(QDataStream &in);
38 virtual void writeToShort(QDataStream &out) const;
39
40 // Get data - pointer
42 QVariant data(const qint32 column, qint32 role) const override;
43 qint32 id() const override;
44 QString text() const override;
45 std::weak_ptr<ehm_dal::schema::AbstractIdTableItem> weakPointer() { return ptr_; }
46
47 // Get data - table
48 std::shared_ptr<ehm_dal::tables::AbstractTable> constTable() const override;
49 std::shared_ptr<ehm_dal::tables::AbstractTable> table() override;
50
51 // Initialisation
56 virtual void init();
62 void init(const ehm_dal::tables::TableIndex table_id);
63
64 // Set data
65 void setData(const QVariant &value, const qint32 role) override;
66
67protected:
68 std::weak_ptr<ehm_dal::schema::AbstractIdTableItem> ptr_;
69
70private:
71 // File i/o
72 friend QDataStream &operator>>(QDataStream &in, Pointer &data);
73 friend QDataStream &operator<<(QDataStream &out, const Pointer &data);
74
75 // Initialisation
76 virtual void initPointer();
77};
78
79// File i/o
80QDataStream &operator>>(QDataStream &in, Pointer &data);
81QDataStream &operator<<(QDataStream &out, const Pointer &data);
82
83} // namespace ehm_dal::data_types
84
85
The AbstractPointer class represents a pointer to a table item.
Definition: abstract_pointer.h:22
QVariant data(const qint32 role) const
Returns the data stored under the given role. Qt::DisplayRole returns the item's display text and Qt:...
Definition: abstract_pointer.h:197
The Pointer class represents a pointer to a table item based on ID.
Definition: pointer.h:21
virtual void writeToShort(QDataStream &out) const
Writes the Pointer value as a qint16.
virtual void init()
Initialise/connect the Pointer to the item to be pointed to. This need only be done once.
virtual void readFromShort(QDataStream &in)
Reads a qint16 as the Pointer value.
void init(const ehm_dal::tables::TableIndex table_id)
Set the table to table_id and initialise/connect the Pointer to the item to be pointed to....
namespace ehm_dal::data_types
Definition: attribute.h:6
@ NULL_POINTER
Definition: pointer_flags.h:9
TableIndex
The TableIndex enum represents the id number of each table within the database.
Definition: table_index.h:14