From 1896d36996ab48ed7271e855d7e32b4e61f64896 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 23 Apr 2012 16:48:00 +0200 Subject: Polymorphic inheritance support --- odb/database.ixx | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) (limited to 'odb/database.ixx') diff --git a/odb/database.ixx b/odb/database.ixx index d4869c1..4a00a74 100644 --- a/odb/database.ixx +++ b/odb/database.ixx @@ -2,7 +2,7 @@ // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file -#include // std::string +#include // std::strlen() namespace odb { @@ -105,6 +105,28 @@ namespace odb } template + inline typename object_traits::pointer_type database:: + find (const typename object_traits::id_type& id) + { + // T is always object_type. + // + + // Compiler error pointing here? Perhaps the object doesn't have the + // default constructor? + // + return object_traits::find (*this, id); + } + + template + inline bool database:: + find (const typename object_traits::id_type& id, T& obj) + { + // T is always object_type. + // + return object_traits::find (*this, id, obj); + } + + template inline void database:: reload (T* p) { @@ -218,6 +240,41 @@ namespace odb template inline void database:: + update (T& obj) + { + // T can be const T while object_type will always be T. + // + typedef typename odb::object_traits::object_type object_type; + typedef odb::object_traits object_traits; + + // Compiler error pointing here? Perhaps the object is readonly or + // doesn't have an object id? Such objects cannot be updated. + // + object_traits::update (*this, obj); + } + + template + inline void database:: + update_ (const typename object_traits::pointer_type& pobj) + { + // T can be const T while object_type will always be T. + // + typedef typename odb::object_traits::object_type object_type; + typedef odb::object_traits object_traits; + + typedef typename odb::object_traits::pointer_type pointer_type; + typedef odb::pointer_traits pointer_traits; + + T& obj (pointer_traits::get_ref (pobj)); + + // Compiler error pointing here? Perhaps the object is readonly or + // doesn't have an object id? Such objects cannot be updated. + // + object_traits::update (*this, obj); + } + + template + inline void database:: erase (T* p) { typedef typename object_traits::pointer_type object_pointer; @@ -295,6 +352,26 @@ namespace odb } template + inline void database:: + erase (const typename object_traits::id_type& id) + { + // T is always object_type. + // + object_traits::erase (*this, id); + } + + template + inline void database:: + erase (T& obj) + { + // T can be const T while object_type will always be T. + // + typedef typename object_traits::object_type object_type; + + object_traits::erase (*this, obj); + } + + template inline unsigned long long database:: erase_query () { @@ -322,6 +399,15 @@ namespace odb } template + inline unsigned long long database:: + erase_query (const odb::query& q) + { + // T is always object_type. + // + return object_traits::erase_query (*this, q); + } + + template inline result database:: query (bool cache) { -- cgit v1.1