aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-04-19 09:26:51 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-04-22 18:45:40 +0200
commit25c332e53064af13c9f119df6bcc2c3847d93695 (patch)
tree8bed2caa49b4f0c3c3f02f777983b8ac2c19f49b
parent7ee76c54fca21bed2b94ebf1e71f723670f135fe (diff)
Add qt/smart-ptr usage to Qt example
-rw-r--r--qt/driver.cxx20
-rw-r--r--qt/employee.hxx23
-rw-r--r--qt/makefile2
3 files changed, 18 insertions, 27 deletions
diff --git a/qt/driver.cxx b/qt/driver.cxx
index f41e4d6..395f0b5 100644
--- a/qt/driver.cxx
+++ b/qt/driver.cxx
@@ -34,16 +34,16 @@ main (int argc, char* argv[])
// Simple Tech Ltd.
//
{
- shared_ptr<employer> er (new employer ("Simple Tech Ltd"));
+ QSharedPointer<employer> er (new employer ("Simple Tech Ltd"));
- shared_ptr<employee> john (
+ QSharedPointer<employee> john (
new employee ("John",
"Doe",
QDate (1974, 5, 23),
QByteArray ("\0xF1\0x00\0x34\0x45\0x00\0xDE", 6),
er));
- shared_ptr<employee> jane (
+ QSharedPointer<employee> jane (
new employee ("Jane",
"Doe",
QDate (1983, 1, 18),
@@ -68,16 +68,16 @@ main (int argc, char* argv[])
// Complex Systems Inc.
//
{
- shared_ptr<employer> er (new employer ("Complex Systems Inc"));
+ QSharedPointer<employer> er (new employer ("Complex Systems Inc"));
- shared_ptr<employee> john (
+ QSharedPointer<employee> john (
new employee ("John",
"Smith",
QDate (1954, 8, 1),
QByteArray ("\0x23\0xFD\0x8F\0x00", 4),
er));
- shared_ptr<employee> jane (
+ QSharedPointer<employee> jane (
new employee ("Jane",
"Smith",
QDate (1976, 12, 31),
@@ -107,18 +107,18 @@ main (int argc, char* argv[])
session s;
transaction t (db->begin ());
- shared_ptr<employer> stl (db->load<employer> ("Simple Tech Ltd"));
+ QSharedPointer<employer> stl (db->load<employer> ("Simple Tech Ltd"));
employees& es (stl->employees ());
for (employees::iterator i (es.begin ()); i != es.end (); ++i)
{
- lazy_weak_ptr<employee>& lwp (*i);
+ QLazyWeakPointer<employee>& lwp (*i);
// Load and lock the employee and his employer.
//
- shared_ptr<employee> p (lwp.load ());
- shared_ptr<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
diff --git a/qt/employee.hxx b/qt/employee.hxx
index 60c6980..f921a97 100644
--- a/qt/employee.hxx
+++ b/qt/employee.hxx
@@ -10,27 +10,18 @@
#include <QString>
#include <QByteArray>
#include <QDateTime>
+#include <QSharedPointer>
#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;
+#include <odb/qt/lazy-ptr.hxx>
// Forward declarations.
//
class employer;
class employee;
-typedef std::vector<lazy_weak_ptr<employee> > employees;
+typedef std::vector<QLazyWeakPointer<employee> > employees;
#pragma db object
class employer
@@ -85,7 +76,7 @@ public:
const QString& last,
const QDate& born,
const QByteArray& public_key,
- shared_ptr<employer_type> employer)
+ QSharedPointer<employer_type> employer)
: first_ (first),
last_ (last),
born_ (born),
@@ -126,14 +117,14 @@ public:
// Employer.
//
- lazy_shared_ptr<employer_type>
+ QLazySharedPointer<employer_type>
employer () const
{
return employer_;
}
void
- employer (shared_ptr<employer_type> employer)
+ employer (QSharedPointer<employer_type> employer)
{
employer_ = employer;
}
@@ -154,7 +145,7 @@ private:
QByteArray public_key_;
#pragma db not_null
- lazy_shared_ptr<employer_type> employer_;
+ QLazySharedPointer<employer_type> employer_;
};
#endif // EMPLOYEE_HXX
diff --git a/qt/makefile b/qt/makefile
index 22af2d1..1b7f0ae 100644
--- a/qt/makefile
+++ b/qt/makefile
@@ -56,7 +56,7 @@ gen := $(addprefix $(out_base)/,$(genf))
$(gen): $(odb)
$(gen): odb := $(odb)
$(gen) $(dist): export odb_options += --database $(db_id) --profile qt \
---generate-query --generate-schema --default-pointer std::tr1::shared_ptr
+--generate-query --generate-schema
$(gen): cpp_options := -I$(src_base)
$(gen): $(odb.l.cpp-options) $(odb_qt.l.cpp-options) $(qt_core.l.cpp-options)