aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-04-21 16:50:50 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-04-22 18:45:40 +0200
commitac3cd9c34d260c6bbf615ed6e0413d0989f5a6e2 (patch)
tree0253c38de5317e14b96a6638db976d48f8f14fd1
parent32dafbe8a2aaf2230b55dfd0840f70ff7909b5e1 (diff)
Rewrite Qt example using Qt style
-rw-r--r--boost/driver.cxx4
-rw-r--r--qt/database.hxx2
-rw-r--r--qt/driver.cxx62
-rw-r--r--qt/employee.hxx59
4 files changed, 59 insertions, 68 deletions
diff --git a/boost/driver.cxx b/boost/driver.cxx
index 99ce69a..2ccaf87 100644
--- a/boost/driver.cxx
+++ b/boost/driver.cxx
@@ -43,8 +43,8 @@ main (int argc, char* argv[])
john->emails ().insert ("john_d@example.com");
john->emails ().insert ("john.doe@example.com");
- jane->emails ().insert ("jane_s@example.com");
- jane->emails ().insert ("jane.smith@example.com");
+ jane->emails ().insert ("jane_d@example.com");
+ jane->emails ().insert ("jane.doe@example.com");
// Set the inverse side of the employee-employer relationship.
//
diff --git a/qt/database.hxx b/qt/database.hxx
index 5b96ae9..f4060d3 100644
--- a/qt/database.hxx
+++ b/qt/database.hxx
@@ -25,7 +25,7 @@
#endif
inline std::auto_ptr<odb::database>
-create_database (int& argc, char* argv[])
+createDatabase (int& argc, char* argv[])
{
using namespace std;
using namespace odb::core;
diff --git a/qt/driver.cxx b/qt/driver.cxx
index 79d4b4a..8889b96 100644
--- a/qt/driver.cxx
+++ b/qt/driver.cxx
@@ -8,7 +8,7 @@
#include <odb/session.hxx>
#include <odb/transaction.hxx>
-#include "database.hxx" // create_database
+#include "database.hxx" // createDatabase
#include "employee.hxx"
#include "employee-odb.hxx"
@@ -16,7 +16,8 @@
using namespace std;
using namespace odb::core;
-ostream& operator << (ostream& os, const QString& s)
+ostream&
+operator<< (ostream& os, const QString& s)
{
return os << s.toStdString ();
}
@@ -26,7 +27,7 @@ main (int argc, char* argv[])
{
try
{
- auto_ptr<database> db (create_database (argc, argv));
+ auto_ptr<database> db (createDatabase (argc, argv));
// Create a few persistent objects.
//
@@ -34,26 +35,26 @@ main (int argc, char* argv[])
// Simple Tech Ltd.
//
{
- QSharedPointer<employer> er (new employer ("Simple Tech Ltd"));
+ QSharedPointer<Employer> er (new Employer ("Simple Tech Ltd"));
- QSharedPointer<employee> john (
- new employee ("John",
+ QSharedPointer<Employee> john (
+ new Employee ("John",
"Doe",
QDate (1974, 5, 23),
QByteArray ("\0xF1\0x00\0x34\0x45\0x00\0xDE", 6),
er));
- QSharedPointer<employee> jane (
- new employee ("Jane",
- "Smith",
+ QSharedPointer<Employee> jane (
+ new Employee ("Jane",
+ "Doe",
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");
+ jane->emails ().insert ("jane_d@example.com");
+ jane->emails ().insert ("jane.doe@simple.com");
// Set the inverse side of the employee-employer relationship.
//
@@ -73,24 +74,24 @@ main (int argc, char* argv[])
// Complex Systems Inc.
//
{
- QSharedPointer<employer> er (new employer ("Complex Systems Inc"));
+ QSharedPointer<Employer> er (new Employer ("Complex Systems Inc"));
- QSharedPointer<employee> john (
- new employee ("John",
+ QSharedPointer<Employee> john (
+ new Employee ("John",
"Smith",
QDate (1954, 8, 1),
QByteArray ("\0x23\0xFD\0x8F\0x00", 4),
er));
- QSharedPointer<employee> jane (
- new employee ("Jane",
+ QSharedPointer<Employee> jane (
+ new Employee ("Jane",
"Smith",
QDate (1976, 12, 31),
QByteArray ("0x00\0x32\0x00\0x01\0x00", 5),
er));
- john->emails ().insert ("john_d@example.com");
- john->emails ().insert ("john.doe@complex.com");
+ john->emails ().insert ("john_s@example.com");
+ john->emails ().insert ("john.smith@complex.com");
jane->emails ().insert ("jane_s@example.com");
jane->emails ().insert ("jane.smith@complex.com");
@@ -117,31 +118,30 @@ main (int argc, char* argv[])
session s;
transaction t (db->begin ());
- QSharedPointer<employer> stl (db->load<employer> ("Simple Tech Ltd"));
+ QSharedPointer<Employer> stl (db->load<Employer> ("Simple Tech Ltd"));
- employees& es (stl->employees ());
+ Employees& es (stl->employees ());
- for (employees::iterator i (es.begin ()); i != es.end (); ++i)
+ for (Employees::iterator i (es.begin ()); i != es.end (); ++i)
{
- QLazyWeakPointer<employee>& lwp (*i);
+ QLazyWeakPointer<Employee>& lwp (*i);
// Load and lock the employee and his employer.
//
- QSharedPointer<employee> p (lwp.load ());
- QSharedPointer<employer> pe (p->employer ().load ());
+ QSharedPointer<Employee> p (lwp.load ());
+ QSharedPointer<Employer> pe (p->employer ().load ());
cout << p->first () << " " << p->last () << endl
<< " born: " << p->born ().toString () << endl;
- for (emails::const_iterator j (p->emails ().begin ()),
+ 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
+ cout << " public key length: " << p->publicKey ().size () << endl
+ << " employer: " << pe->name () << endl
<< endl;
}
@@ -151,13 +151,13 @@ main (int argc, char* argv[])
// Search for Complex Systems Inc employees.
//
{
- typedef odb::query<employee> query;
- typedef odb::result<employee> result;
+ typedef odb::query<Employee> query;
+ typedef odb::result<Employee> result;
session s;
transaction t (db->begin ());
- result r (db->query<employee> (
+ result r (db->query<Employee> (
query::employer::name == "Complex Systems Inc"));
for (result::iterator i (r.begin ()); i != r.end (); ++i)
diff --git a/qt/employee.hxx b/qt/employee.hxx
index 37ad0c9..3117596 100644
--- a/qt/employee.hxx
+++ b/qt/employee.hxx
@@ -18,17 +18,17 @@
// Forward declarations.
//
-class employer;
-class employee;
+class Employee;
-typedef QSet<QString> emails;
-typedef QList<QLazyWeakPointer<employee> > employees;
+typedef QSet<QString> Emails;
+typedef QList<QLazyWeakPointer<Employee> > Employees;
#pragma db object
-class employer
+class Employer
{
public:
- employer (const QString& name)
+
+ Employer (const QString& name)
: name_ (name)
{
}
@@ -39,17 +39,13 @@ public:
return name_;
}
- // Employees of this employer.
- //
- typedef ::employees employees_type;
-
- const employees_type&
+ const Employees&
employees () const
{
return employees_;
}
- employees_type&
+ Employees&
employees ()
{
return employees_;
@@ -58,30 +54,29 @@ public:
private:
friend class odb::access;
- employer () {}
+ Employer () {}
#pragma db id
QString name_;
#pragma db not_null inverse(employer_)
- employees_type employees_;
+ Employees employees_;
};
#pragma db object
-class employee
+class Employee
{
public:
- typedef ::employer employer_type;
- employee (const QString& first,
+ Employee (const QString& first,
const QString& last,
const QDate& born,
- const QByteArray& public_key,
- QSharedPointer<employer_type> employer)
+ const QByteArray& publicKey,
+ QSharedPointer<Employer> employer)
: first_ (first),
last_ (last),
born_ (born),
- public_key_ (public_key),
+ publicKey_ (publicKey),
employer_ (employer)
{
}
@@ -108,17 +103,13 @@ public:
return born_;
}
- // Emails.
- //
- typedef ::emails emails_type;
-
- const emails_type&
+ const Emails&
emails () const
{
return emails_;
}
- emails_type&
+ Emails&
emails ()
{
return emails_;
@@ -127,21 +118,21 @@ public:
// Public key.
//
const QByteArray&
- public_key () const
+ publicKey () const
{
- return public_key_;
+ return publicKey_;
}
// Employer.
//
- QLazySharedPointer<employer_type>
+ QLazySharedPointer<Employer>
employer () const
{
return employer_;
}
void
- employer (QSharedPointer<employer_type> employer)
+ employer (QSharedPointer<Employer> employer)
{
employer_ = employer;
}
@@ -149,7 +140,7 @@ public:
private:
friend class odb::access;
- employee () {}
+ Employee () {}
#pragma db id auto
unsigned long id_;
@@ -157,11 +148,11 @@ private:
QString first_;
QString last_;
QDate born_;
- emails_type emails_;
- QByteArray public_key_;
+ Emails emails_;
+ QByteArray publicKey_;
#pragma db not_null
- QLazySharedPointer<employer_type> employer_;
+ QLazySharedPointer<Employer> employer_;
};
#endif // EMPLOYEE_HXX