diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-03-25 16:50:19 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-03-25 16:53:36 +0200 |
commit | 6f70eeec9401f385c8122445eedb53602a002830 (patch) | |
tree | 18f0304a133d9a1d3a3c701aefd1e459711c9e0e | |
parent | 58a02e9c923fbc9b8f59c5b52ec7c8c55adffa31 (diff) |
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.
-rw-r--r-- | odb/details/shared-ptr-fwd.hxx | 26 | ||||
-rw-r--r-- | odb/details/shared-ptr.hxx | 1 | ||||
-rw-r--r-- | odb/details/shared-ptr/base.hxx | 5 | ||||
-rw-r--r-- | odb/details/shared-ptr/base.txx | 2 | ||||
-rw-r--r-- | odb/details/shared-ptr/counter-type.hxx | 25 | ||||
-rw-r--r-- | odb/forward.hxx | 8 |
6 files changed, 58 insertions, 9 deletions
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 <boris@codesynthesis.com> +// 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 <odb/pre.hxx> + +#include <odb/details/shared-ptr/counter-type.hxx> + +namespace odb +{ + namespace details + { + template <typename X> + class shared_ptr; + + class shared_base; + } +} + +#include <odb/post.hxx> + +#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 <odb/pre.hxx> +#include <odb/details/shared-ptr-fwd.hxx> #include <odb/details/shared-ptr/base.hxx> 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 <cstddef> // std::size_t #include <odb/exception.hxx> - #include <odb/details/export.hxx> +#include <odb/details/shared-ptr/counter-type.hxx> 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 <typename X> struct counter_type<X, sizeof (meta::no)> { - typedef X r; + typedef typename details::counter_type<X>::counter r; }; template <typename X> 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 <boris@codesynthesis.com> +// 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 <odb/pre.hxx> + +namespace odb +{ + namespace details + { + template <typename X> + struct counter_type + { + typedef X counter; + }; + } +} + +#include <odb/post.hxx> + +#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 <odb/pre.hxx> +#include <odb/details/shared-ptr-fwd.hxx> + namespace odb { class database; @@ -45,12 +47,6 @@ namespace odb template <typename T> struct object_traits; - - namespace details - { - template <typename X> - class shared_ptr; - } } #include <odb/post.hxx> |