aboutsummaryrefslogtreecommitdiff
path: root/qt/employee.hxx
blob: 31175969461a0faab5adf57e2986a0fdf290e6b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// file      : qt/employee.hxx
// author    : Constantin Michael <constantin@codesynthesis.com>
// copyright : not copyrighted - public domain

#ifndef EMPLOYEE_HXX
#define EMPLOYEE_HXX

#include <QString>
#include <QByteArray>
#include <QDateTime>
#include <QSharedPointer>
#include <QList>
#include <QSet>

#include <odb/core.hxx>

#include <odb/qt/lazy-ptr.hxx>

// Forward declarations.
//
class Employee;

typedef QSet<QString> Emails;
typedef QList<QLazyWeakPointer<Employee> > Employees;

#pragma db object
class Employer
{
public:

  Employer (const QString& name)
      : name_ (name)
  {
  }

  const QString&
  name () const
  {
    return name_;
  }

  const Employees&
  employees () const
  {
    return employees_;
  }

  Employees&
  employees ()
  {
    return employees_;
  }

private:
  friend class odb::access;

  Employer () {}

  #pragma db id
  QString name_;

  #pragma db not_null inverse(employer_)
  Employees employees_;
};

#pragma db object
class Employee
{
public:

  Employee (const QString& first,
            const QString& last,
            const QDate& born,
            const QByteArray& publicKey,
            QSharedPointer<Employer> employer)
      : first_ (first),
        last_ (last),
        born_ (born),
        publicKey_ (publicKey),
        employer_ (employer)
  {
  }

  // Name.
  //
  const QString&
  first () const
  {
    return first_;
  }

  const QString&
  last () const
  {
    return last_;
  }

  // Date of birth.
  //
  const QDate&
  born () const
  {
    return born_;
  }

  const Emails&
  emails () const
  {
    return emails_;
  }

  Emails&
  emails ()
  {
    return emails_;
  }

  // Public key.
  //
  const QByteArray&
  publicKey () const
  {
    return publicKey_;
  }

  // Employer.
  //
  QLazySharedPointer<Employer>
  employer () const
  {
    return employer_;
  }

  void
  employer (QSharedPointer<Employer> employer)
  {
    employer_ = employer;
  }

private:
  friend class odb::access;

  Employee () {}

  #pragma db id auto
  unsigned long id_;

  QString first_;
  QString last_;
  QDate born_;
  Emails emails_;
  QByteArray publicKey_;

  #pragma db not_null
  QLazySharedPointer<Employer> employer_;
};

#endif // EMPLOYEE_HXX