// file : odb/lazy-ptr-impl.hxx // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file #ifndef ODB_LAZY_PTR_IMPL_HXX #define ODB_LAZY_PTR_IMPL_HXX #include #include // std::move #include // odb::database #include #include // ODB_CXX11 #include namespace odb { struct LIBODB_EXPORT lazy_ptr_impl_ref { void* id_; database* db_; void* loader_; void (*free_) (void*); void* (*copy_) (const void*); }; class LIBODB_EXPORT lazy_ptr_base { public: typedef odb::database database_type; ~lazy_ptr_base (); lazy_ptr_base (); lazy_ptr_base (const lazy_ptr_base&); lazy_ptr_base (const lazy_ptr_impl_ref&); lazy_ptr_base& operator= (const lazy_ptr_base&); lazy_ptr_base& operator= (const lazy_ptr_impl_ref&); // C++11 support. // public: #ifdef ODB_CXX11 lazy_ptr_base (lazy_ptr_base&&); lazy_ptr_base& operator= (lazy_ptr_base&&); #endif public: // Reset both the id and database. // void reset (); // Reset the id. // void reset_id (); void swap (lazy_ptr_base&); database_type* database () const; typedef void* lazy_ptr_base::*unspecified_bool_type; operator unspecified_bool_type () const { return db_ != 0 ? &lazy_ptr_base::id_ : 0; } operator lazy_ptr_impl_ref (); protected: typedef void (*free_func) (void*); typedef void* (*copy_func) (const void*); // Makes a copy of id. // void reset_ (database_type*, void* loader, const void* id, free_func, copy_func); template static void free (void*); template static void* copy (const void*); template static typename object_traits::pointer_type loader (database_type&, const typename object_traits::id_type&); protected: void* id_; database_type* db_; void* loader_; private: free_func free_; copy_func copy_; }; template class lazy_ptr_impl: public lazy_ptr_base { public: lazy_ptr_impl (); template lazy_ptr_impl (DB&, const ID&); lazy_ptr_impl (const lazy_ptr_impl&); template lazy_ptr_impl (const lazy_ptr_impl&); lazy_ptr_impl (const lazy_ptr_impl_ref&); lazy_ptr_impl& operator= (const lazy_ptr_impl&); template lazy_ptr_impl& operator= (const lazy_ptr_impl&); lazy_ptr_impl& operator= (const lazy_ptr_impl_ref&); // C++11 support. // public: #ifdef ODB_CXX11 lazy_ptr_impl (lazy_ptr_impl&&); template lazy_ptr_impl (lazy_ptr_impl&&); lazy_ptr_impl& operator= (lazy_ptr_impl&&); template lazy_ptr_impl& operator= (lazy_ptr_impl&&); #endif public: using lazy_ptr_base::reset; using lazy_ptr_base::reset_id; template void reset (DB&, const ID&); // Reset the id and set the database to the new value. // template void reset_db (DB&); template void reset_id (const ID&); template typename object_traits::pointer_type load (bool reset_id); template typename object_traits::id_type object_id () const; }; } #include #include #include #endif // ODB_LAZY_PTR_IMPL_HXX