diff options
Diffstat (limited to 'boost')
-rw-r--r-- | boost/README | 6 | ||||
-rw-r--r-- | boost/driver.cxx | 5 | ||||
-rw-r--r-- | 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 <memory> // std::auto_ptr #include <iostream> +#include <boost/uuid/uuid_io.hpp> + #include <odb/database.hxx> #include <odb/session.hxx> #include <odb/transaction.hxx> @@ -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 <boost/weak_ptr.hpp> #include <boost/optional.hpp> #include <boost/unordered_set.hpp> +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_generators.hpp> #include <boost/date_time/gregorian/gregorian.hpp> #include <odb/core.hxx> @@ -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_type> 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_type> 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<std::string> middle_; |