diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-02-28 16:11:51 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-02-28 16:19:50 +0200 |
commit | 43b3c92c5dae2d851f45fbe04f1c9ac6d9a933f4 (patch) | |
tree | bcd68c89b1c539e02a4f40eda003b821b806f1df | |
parent | b377248ed27badc979e1fa02433baac0407557c7 (diff) |
Add support for object pointers with two template parameters
Such as C++11 std::unique_ptr.
-rw-r--r-- | odb/database.hxx | 32 | ||||
-rw-r--r-- | odb/database.ixx | 83 | ||||
-rw-r--r-- | odb/traits.hxx | 12 |
3 files changed, 127 insertions, 0 deletions
diff --git a/odb/database.hxx b/odb/database.hxx index b7e7926..64f9d44 100644 --- a/odb/database.hxx +++ b/odb/database.hxx @@ -47,10 +47,18 @@ namespace odb typename object_traits<T>::id_type persist (const P<T>& obj_ptr); + template <typename T, typename A1, template <typename, typename> class P> + typename object_traits<T>::id_type + persist (const P<T, A1>& obj_ptr); + template <typename T, template <typename> class P> typename object_traits<T>::id_type persist (P<T>& obj_ptr); + template <typename T, typename A1, template <typename, typename> class P> + typename object_traits<T>::id_type + persist (P<T, A1>& obj_ptr); + template <typename T> typename object_traits<T>::id_type persist (const typename object_traits<T>::pointer_type& obj_ptr); @@ -77,10 +85,18 @@ namespace odb void reload (const P<T>& obj_ptr); + template <typename T, typename A1, template <typename, typename> class P> + void + reload (const P<T, A1>& obj_ptr); + template <typename T, template <typename> class P> void reload (P<T>& obj_ptr); + template <typename T, typename A1, template <typename, typename> class P> + void + reload (P<T, A1>& obj_ptr); + template <typename T> void reload (const typename object_traits<T>::pointer_type& obj_ptr); @@ -109,10 +125,18 @@ namespace odb void update (const P<T>& obj_ptr); + template <typename T, typename A1, template <typename, typename> class P> + void + update (const P<T, A1>& obj_ptr); + template <typename T, template <typename> class P> void update (P<T>& obj_ptr); + template <typename T, typename A1, template <typename, typename> class P> + void + update (P<T, A1>& obj_ptr); + template <typename T> void update (const typename object_traits<T>::pointer_type& obj_ptr); @@ -136,10 +160,18 @@ namespace odb void erase (const P<T>& obj_ptr); + template <typename T, typename A1, template <typename, typename> class P> + void + erase (const P<T, A1>& obj_ptr); + template <typename T, template <typename> class P> void erase (P<T>& obj_ptr); + template <typename T, typename A1, template <typename, typename> class P> + void + erase (P<T, A1>& obj_ptr); + template <typename T> void erase (const typename object_traits<T>::pointer_type& obj_ptr); diff --git a/odb/database.ixx b/odb/database.ixx index 36766e2..d4869c1 100644 --- a/odb/database.ixx +++ b/odb/database.ixx @@ -66,6 +66,21 @@ namespace odb return persist_<T> (pobj); } + template <typename T, typename A1, template <typename, typename> class P> + inline typename object_traits<T>::id_type database:: + persist (const P<T, A1>& p) + { + typedef typename object_traits<T>::pointer_type object_pointer; + + // The passed pointer should be the same or implicit-convertible + // to the object pointer. This way we make sure the object pointer + // does not assume ownership of the passed object. + // + const object_pointer& pobj (p); + + return persist_<T> (pobj); + } + template <typename T, template <typename> class P> inline typename object_traits<T>::id_type database:: persist (P<T>& p) @@ -74,6 +89,14 @@ namespace odb return persist<T, P> (cr); } + template <typename T, typename A1, template <typename, typename> class P> + inline typename object_traits<T>::id_type database:: + persist (P<T, A1>& p) + { + const P<T, A1>& cr (p); + return persist<T, A1, P> (cr); + } + template <typename T> inline typename object_traits<T>::id_type database:: persist (const typename object_traits<T>::pointer_type& pobj) @@ -95,6 +118,13 @@ namespace odb reload (odb::pointer_traits< P<T> >::get_ref (p)); } + template <typename T, typename A1, template <typename, typename> class P> + inline void database:: + reload (const P<T, A1>& p) + { + reload (odb::pointer_traits< P<T, A1> >::get_ref (p)); + } + template <typename T, template <typename> class P> inline void database:: reload (P<T>& p) @@ -102,6 +132,13 @@ namespace odb reload (odb::pointer_traits< P<T> >::get_ref (p)); } + template <typename T, typename A1, template <typename, typename> class P> + inline void database:: + reload (P<T, A1>& p) + { + reload (odb::pointer_traits< P<T, A1> >::get_ref (p)); + } + template <typename T> inline void database:: reload (const typename object_traits<T>::pointer_type& pobj) @@ -141,6 +178,21 @@ namespace odb update_<T> (pobj); } + template <typename T, typename A1, template <typename, typename> class P> + inline void database:: + update (const P<T, A1>& p) + { + typedef typename object_traits<T>::pointer_type object_pointer; + + // The passed pointer should be the same or implicit-convertible + // to the object pointer. This way we make sure the object pointer + // does not assume ownership of the passed object. + // + const object_pointer& pobj (p); + + update_<T> (pobj); + } + template <typename T, template <typename> class P> inline void database:: update (P<T>& p) @@ -149,6 +201,14 @@ namespace odb update<T, P> (cr); } + template <typename T, typename A1, template <typename, typename> class P> + inline void database:: + update (P<T, A1>& p) + { + const P<T, A1>& cr (p); + update<T, A1, P> (cr); + } + template <typename T> inline void database:: update (const typename object_traits<T>::pointer_type& pobj) @@ -186,6 +246,21 @@ namespace odb erase_<T> (pobj); } + template <typename T, typename A1, template <typename, typename> class P> + inline void database:: + erase (const P<T, A1>& p) + { + typedef typename object_traits<T>::pointer_type object_pointer; + + // The passed pointer should be the same or implicit-convertible + // to the object pointer. This way we make sure the object pointer + // does not assume ownership of the passed object. + // + const object_pointer& pobj (p); + + erase_<T> (pobj); + } + template <typename T, template <typename> class P> inline void database:: erase (P<T>& p) @@ -194,6 +269,14 @@ namespace odb erase<T, P> (cr); } + template <typename T, typename A1, template <typename, typename> class P> + inline void database:: + erase (P<T, A1>& p) + { + const P<T, A1>& cr (p); + erase<T, A1, P> (cr); + } + template <typename T> inline void database:: erase (const typename object_traits<T>::pointer_type& pobj) diff --git a/odb/traits.hxx b/odb/traits.hxx index 9445c7a..4c71f94 100644 --- a/odb/traits.hxx +++ b/odb/traits.hxx @@ -163,12 +163,24 @@ namespace odb struct id_type {}; }; + template <typename T, typename A1, template <typename, typename> class P> + struct object_traits< P<T, A1> > + { + struct id_type {}; + }; + template <typename T, template <typename> class P> struct object_traits< const P<T> > { struct id_type {}; }; + template <typename T, typename A1, template <typename, typename> class P> + struct object_traits< const P<T, A1> > + { + struct id_type {}; + }; + // // view_traits // |