From 47e38764ebc759c0884921cfb594a215a88dcb98 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 5 Sep 2012 11:59:27 +0200 Subject: Support for Boost uuid persistence New Boost sub-profile: uuid. New test: boost/common/uuid. Updated the boost example to use uuid as an object id. --- boost/README | 6 +++--- boost/driver.cxx | 5 ++++- boost/employee.hxx | 21 +++++++++++++++++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/boost/README b/boost/README index 848e40a..6a86b28 100644 --- a/boost/README +++ b/boost/README @@ -11,9 +11,9 @@ employee.hxx establish a bidirectional employee-employer relationship. We also use the boost::gregorian::date type to store the employee's date of birth and the boost::unordered_set container to keep track of the employee's - email addresses. Finally, we use boost::optional for the optional middle - name. If the middle name is not present, it will be represented in the - database as a NULL value. + email addresses. The employee's object id is boost::uuids::uuid. Finally, + we use boost::optional for the optional middle name. If the middle name + is not present, it will be represented in the database as a NULL value. employee-odb.hxx employee-odb.ixx diff --git a/boost/driver.cxx b/boost/driver.cxx index d38eb15..5a096f6 100644 --- a/boost/driver.cxx +++ b/boost/driver.cxx @@ -4,6 +4,8 @@ #include // std::auto_ptr #include +#include + #include #include #include @@ -124,7 +126,8 @@ main (int argc, char* argv[]) cout << " email: " << *j << endl; } - cout << endl; + cout << " id: {" << p->id () << '}' << endl + << endl; } t.commit (); diff --git a/boost/employee.hxx b/boost/employee.hxx index 89aec1f..8d6173a 100644 --- a/boost/employee.hxx +++ b/boost/employee.hxx @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include @@ -23,6 +25,7 @@ using boost::weak_ptr; using odb::boost::lazy_shared_ptr; using odb::boost::lazy_weak_ptr; +using boost::uuids::uuid; using boost::gregorian::date; // Forward declarations. @@ -86,7 +89,8 @@ public: const std::string& last, const date& born, shared_ptr employer) - : first_ (first), last_ (last), + : id_ (boost::uuids::random_generator () ()), + first_ (first), last_ (last), born_ (born), employer_ (employer) { @@ -97,12 +101,21 @@ public: const std::string& last, const date& born, shared_ptr employer) - : first_ (first), middle_ (middle), last_ (last), + : id_ (boost::uuids::random_generator () ()), + first_ (first), middle_ (middle), last_ (last), born_ (born), employer_ (employer) { } + // Id. + // + const uuid& + id () const + { + return id_; + } + // Name. // const std::string& @@ -166,8 +179,8 @@ private: employee () {} - #pragma db id auto - unsigned long id_; + #pragma db id + uuid id_; std::string first_; boost::optional middle_; -- cgit v1.1