diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-01-08 17:27:40 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-01-08 17:27:40 +0200 |
commit | 16a4099d36ca1cdc33cf6e2b99edce796595341f (patch) | |
tree | edc43ef5218210f30c8546baaa180087683141c4 /common/composite/test.hxx | |
parent | 7c517014fe1e1b0350b8a1580f6a016fb556c1a6 (diff) |
Add support for defining composite value type as class template instantiations
Diffstat (limited to 'common/composite/test.hxx')
-rw-r--r-- | common/composite/test.hxx | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/common/composite/test.hxx b/common/composite/test.hxx index 120476a..d846c9c 100644 --- a/common/composite/test.hxx +++ b/common/composite/test.hxx @@ -7,6 +7,8 @@ #define TEST_HXX #include <string> +#include <vector> +#include <utility> // std::pair #include <odb/core.hxx> @@ -68,7 +70,7 @@ struct person }; inline bool -operator== (person const& x, person const& y) +operator== (const person& x, const person& y) { return x.id_ == y.id_ && x.name_.first == y.name_.first&& @@ -82,4 +84,62 @@ operator== (person const& x, person const& y) x.age_ == y.age_; } +// Test composite class template instantiation. +// +template <typename I, typename S> +struct comp +{ + I num; + S str; + std::vector<std::pair<I, S> > vec; +}; + +template <typename I, typename S> +inline bool +operator== (const comp<I, S>& x, const comp<I, S>& y) +{ + return x.num == y.num && x.str == y.str && x.vec == y.vec; +} + +typedef std::pair<int, std::string> int_str_pair; +#pragma db value(int_str_pair) + +// Make sure we use the name that was specified in the pragma. +// +#ifdef ODB_COMPILER +typedef comp<int, std::string> int_str_comp1; +#endif + +typedef comp<int, std::string> int_str_comp; +#pragma db value(int_str_comp) + +#pragma db object +struct object +{ + object (unsigned long id) + : id_ (id) + { + } + + object () + { + } + + #pragma db id + unsigned long id_; + + comp<int, std::string> comp_; + std::pair<int, std::string> pair_; + std::vector<int_str_pair> vec_; +}; + +inline bool +operator== (const object& x, const object& y) +{ + return x.id_ == y.id_ && + x.comp_ == y.comp_ && + x.pair_ == y.pair_ && + x.vec_ == y.vec_; +} + #endif // TEST_HXX |