From 6f70eeec9401f385c8122445eedb53602a002830 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 25 Mar 2011 16:50:19 +0200 Subject: Add support for forward-declaring shared_base-based types The forward declaration must specialize the counter_type template to explicitly specify shared_base as the counter type. --- odb/details/shared-ptr-fwd.hxx | 26 ++++++++++++++++++++++++++ odb/details/shared-ptr.hxx | 1 + odb/details/shared-ptr/base.hxx | 5 +++-- odb/details/shared-ptr/base.txx | 2 +- odb/details/shared-ptr/counter-type.hxx | 25 +++++++++++++++++++++++++ odb/forward.hxx | 8 ++------ 6 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 odb/details/shared-ptr-fwd.hxx create mode 100644 odb/details/shared-ptr/counter-type.hxx diff --git a/odb/details/shared-ptr-fwd.hxx b/odb/details/shared-ptr-fwd.hxx new file mode 100644 index 0000000..4483b90 --- /dev/null +++ b/odb/details/shared-ptr-fwd.hxx @@ -0,0 +1,26 @@ +// file : odb/details/shared-ptr-fwd.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_DETAILS_SHARED_PTR_FWD_HXX +#define ODB_DETAILS_SHARED_PTR_FWD_HXX + +#include + +#include + +namespace odb +{ + namespace details + { + template + class shared_ptr; + + class shared_base; + } +} + +#include + +#endif // ODB_DETAILS_SHARED_PTR_FWD_HXX diff --git a/odb/details/shared-ptr.hxx b/odb/details/shared-ptr.hxx index bfe48cf..c795318 100644 --- a/odb/details/shared-ptr.hxx +++ b/odb/details/shared-ptr.hxx @@ -8,6 +8,7 @@ #include +#include #include namespace odb diff --git a/odb/details/shared-ptr/base.hxx b/odb/details/shared-ptr/base.hxx index 7cf44da..3bc2df1 100644 --- a/odb/details/shared-ptr/base.hxx +++ b/odb/details/shared-ptr/base.hxx @@ -12,8 +12,8 @@ #include // std::size_t #include - #include +#include namespace odb { @@ -52,8 +52,9 @@ namespace odb what () const throw (); }; - struct LIBODB_EXPORT shared_base + class LIBODB_EXPORT shared_base { + public: shared_base (); shared_base (const shared_base&); shared_base& diff --git a/odb/details/shared-ptr/base.txx b/odb/details/shared-ptr/base.txx index a836974..a57ce91 100644 --- a/odb/details/shared-ptr/base.txx +++ b/odb/details/shared-ptr/base.txx @@ -68,7 +68,7 @@ namespace odb template struct counter_type { - typedef X r; + typedef typename details::counter_type::counter r; }; template diff --git a/odb/details/shared-ptr/counter-type.hxx b/odb/details/shared-ptr/counter-type.hxx new file mode 100644 index 0000000..f208a4f --- /dev/null +++ b/odb/details/shared-ptr/counter-type.hxx @@ -0,0 +1,25 @@ +// file : odb/details/shared-ptr/counter-type.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_DETAILS_SHARED_PTR_COUNTER_TYPE_HXX +#define ODB_DETAILS_SHARED_PTR_COUNTER_TYPE_HXX + +#include + +namespace odb +{ + namespace details + { + template + struct counter_type + { + typedef X counter; + }; + } +} + +#include + +#endif // ODB_DETAILS_SHARED_PTR_COUNTER_TYPE_HXX diff --git a/odb/forward.hxx b/odb/forward.hxx index ec502d2..c387fb4 100644 --- a/odb/forward.hxx +++ b/odb/forward.hxx @@ -8,6 +8,8 @@ #include +#include + namespace odb { class database; @@ -45,12 +47,6 @@ namespace odb template struct object_traits; - - namespace details - { - template - class shared_ptr; - } } #include -- cgit v1.1