From 24f87489a4d315cc01ca9d49a3f0209522fe6729 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 8 Jan 2012 17:27:40 +0200 Subject: Add support for defining composite value type as class template instantiations --- composite/person.hxx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'composite/person.hxx') diff --git a/composite/person.hxx b/composite/person.hxx index dfc44e6..92da60c 100644 --- a/composite/person.hxx +++ b/composite/person.hxx @@ -123,6 +123,12 @@ private: name_extras extras_; }; +// We can also define a composite value type as a class template +// instantiation. Here we use std::pair to store person's phone +// numbers, in the order of preference. +// +typedef std::pair phone_numbers; +#pragma db value(phone_numbers) #pragma db object class person @@ -130,8 +136,9 @@ class person public: person (const std::string& first, const std::string& last, - const std::string& title) - : name_ (first, last, title) + const std::string& title, + const phone_numbers& phone) + : name_ (first, last, title), phone_ (phone) { } @@ -151,6 +158,14 @@ public: return name_; } + // Phone. + // + const phone_numbers& + phone () const + { + return phone_; + } + private: friend class odb::access; @@ -160,6 +175,7 @@ private: unsigned long id_; name_type name_; + phone_numbers phone_; }; #endif // PERSON_HXX -- cgit v1.1