aboutsummaryrefslogtreecommitdiff
path: root/qt/employee.hxx
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-04-07 12:47:27 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-04-22 18:45:40 +0200
commit5da0df2986a62e1254d27c8cfbc383ba580555e1 (patch)
tree4f75a607951d1124f3b19062593905d12f027b3a /qt/employee.hxx
parent2534ea4dd7196828ba8446921c7b552087055114 (diff)
Update examples to include qt/basic and qt/date-time usage
Diffstat (limited to 'qt/employee.hxx')
-rw-r--r--qt/employee.hxx157
1 files changed, 157 insertions, 0 deletions
diff --git a/qt/employee.hxx b/qt/employee.hxx
new file mode 100644
index 0000000..1e39993
--- /dev/null
+++ b/qt/employee.hxx
@@ -0,0 +1,157 @@
+// file : qt/employee.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+#ifndef EMPLOYEE_HXX
+#define EMPLOYEE_HXX
+
+#include <vector>
+
+#include <QString>
+#include <QByteArray>
+#include <QDateTime>
+
+#include <odb/core.hxx>
+
+// Include TR1 <memory> header in a compiler-specific fashion. Fall back
+// on the Boost implementation if the compiler does not support TR1.
+//
+#include <odb/tr1/memory.hxx>
+
+#include <odb/tr1/lazy-ptr.hxx>
+
+using std::tr1::shared_ptr;
+
+using odb::tr1::lazy_shared_ptr;
+using odb::tr1::lazy_weak_ptr;
+
+// Forward declarations.
+//
+class employer;
+class employee;
+
+typedef std::vector<lazy_weak_ptr<employee> > employees;
+
+#pragma db object
+class employer
+{
+public:
+ employer (const QString& name)
+ : name_ (name)
+ {
+ }
+
+ const QString&
+ name () const
+ {
+ return name_;
+ }
+
+ // Employees of this employer.
+ //
+ typedef ::employees employees_type;
+
+ const employees_type&
+ employees () const
+ {
+ return employees_;
+ }
+
+ employees_type&
+ employees ()
+ {
+ return employees_;
+ }
+
+private:
+ friend class odb::access;
+
+ employer () {}
+
+ #pragma db id
+ QString name_;
+
+ #pragma db not_null inverse(employer_)
+ employees_type employees_;
+};
+
+#pragma db object
+class employee
+{
+public:
+ typedef ::employer employer_type;
+
+ employee (const QString& first,
+ const QString& last,
+ const QDate& born,
+ const QByteArray& public_key,
+ shared_ptr<employer_type> employer)
+ : first_ (first), last_ (last), born_(born), public_key_(public_key),
+ employer_ (employer)
+ {
+ }
+
+ // Name.
+ //
+ const QString&
+ first () const
+ {
+ return first_;
+ }
+
+ const QString&
+ last () const
+ {
+ return last_;
+ }
+
+ // Date of birth.
+ //
+ const QDate&
+ born () const
+ {
+ return born_;
+ }
+
+ // Public key.
+ //
+ const QByteArray&
+ public_key () const
+ {
+ return public_key_;
+ }
+
+ // Employer.
+ //
+ lazy_shared_ptr<employer_type>
+ employer () const
+ {
+ return employer_;
+ }
+
+ void
+ employer (shared_ptr<employer_type> employer)
+ {
+ employer_ = employer;
+ }
+
+private:
+ friend class odb::access;
+
+ employee () {}
+
+ #pragma db id auto
+ unsigned long id_;
+
+ QString first_;
+ QString last_;
+
+ QDate born_;
+
+ QByteArray public_key_;
+
+ #pragma db not_null
+ lazy_shared_ptr<employer_type> employer_;
+};
+
+#endif // EMPLOYEE_HXX