aboutsummaryrefslogtreecommitdiff
path: root/qt
diff options
context:
space:
mode:
Diffstat (limited to 'qt')
-rw-r--r--qt/README10
-rw-r--r--qt/driver.cxx30
-rw-r--r--qt/employee.hxx26
3 files changed, 50 insertions, 16 deletions
diff --git a/qt/README b/qt/README
index 111a39b..978e8aa 100644
--- a/qt/README
+++ b/qt/README
@@ -8,10 +8,12 @@ employee.hxx
Header file defining the 'employee' and 'employer' persistent classes.
We use QSharedPointer/QWeakPointer smart pointers provided by Qt (as
well as their lazy versions provided by the Qt profile library) to
- establish a bidirectional employee-employer relationship. We also use
- the QDateTime type to store the employee's date of birth and QString
- to store the employee's first and last name. Finally we use QByteArray
- to store the person's public key.
+ establish a bidirectional employee-employer relationship. The QList
+ type is used to store the collection of employees employed by the
+ employer. We also use the QDateTime type to store the employee's date
+ of birth and QString to store the employee's first and last name. A
+ QSet instance keeps track of the employee's email addresses. Finally
+ we use QByteArray to store the person's public key.
employee-odb.hxx
employee-odb.ixx
diff --git a/qt/driver.cxx b/qt/driver.cxx
index 395f0b5..79d4b4a 100644
--- a/qt/driver.cxx
+++ b/qt/driver.cxx
@@ -45,11 +45,16 @@ main (int argc, char* argv[])
QSharedPointer<employee> jane (
new employee ("Jane",
- "Doe",
+ "Smith",
QDate (1983, 1, 18),
QByteArray ("\0xD7\0x00\0x14", 3),
er));
+ john->emails ().insert ("john_d@example.com");
+ john->emails ().insert ("john.doe@simple.com");
+ jane->emails ().insert ("jane_s@example.com");
+ jane->emails ().insert ("jane.smith@simple.com");
+
// Set the inverse side of the employee-employer relationship.
//
er->employees ().push_back (john);
@@ -84,6 +89,11 @@ main (int argc, char* argv[])
QByteArray ("0x00\0x32\0x00\0x01\0x00", 5),
er));
+ john->emails ().insert ("john_d@example.com");
+ john->emails ().insert ("john.doe@complex.com");
+ jane->emails ().insert ("jane_s@example.com");
+ jane->emails ().insert ("jane.smith@complex.com");
+
// Set the inverse side of the employee-employer relationship.
//
er->employees ().push_back (john);
@@ -121,12 +131,18 @@ main (int argc, char* argv[])
QSharedPointer<employer> pe (p->employer ().load ());
cout << p->first () << " " << p->last () << endl
- << " born: " << p->born ().toString () << endl
- << " public key length: " << p->public_key ().size () << endl
- << " employer: "
- << pe->name ().toAscii ().data () << endl;
-
- cout << endl;
+ << " born: " << p->born ().toString () << endl;
+
+ for (emails::const_iterator j (p->emails ().begin ()),
+ e (p->emails ().end ()); j != e; ++j)
+ {
+ cout << " email: " << *j << endl;
+ }
+
+ cout << " public key length: " << p->public_key ().size () << endl
+ << " employer: "
+ << pe->name () << endl
+ << endl;
}
t.commit ();
diff --git a/qt/employee.hxx b/qt/employee.hxx
index f921a97..37ad0c9 100644
--- a/qt/employee.hxx
+++ b/qt/employee.hxx
@@ -5,12 +5,12 @@
#ifndef EMPLOYEE_HXX
#define EMPLOYEE_HXX
-#include <vector>
-
#include <QString>
#include <QByteArray>
#include <QDateTime>
#include <QSharedPointer>
+#include <QList>
+#include <QSet>
#include <odb/core.hxx>
@@ -21,7 +21,8 @@
class employer;
class employee;
-typedef std::vector<QLazyWeakPointer<employee> > employees;
+typedef QSet<QString> emails;
+typedef QList<QLazyWeakPointer<employee> > employees;
#pragma db object
class employer
@@ -107,6 +108,22 @@ public:
return born_;
}
+ // Emails.
+ //
+ typedef ::emails emails_type;
+
+ const emails_type&
+ emails () const
+ {
+ return emails_;
+ }
+
+ emails_type&
+ emails ()
+ {
+ return emails_;
+ }
+
// Public key.
//
const QByteArray&
@@ -139,9 +156,8 @@ private:
QString first_;
QString last_;
-
QDate born_;
-
+ emails_type emails_;
QByteArray public_key_;
#pragma db not_null