// file : odb/traits.hxx // author : Boris Kolpackov // copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file #ifndef ODB_TRAITS_HXX #define ODB_TRAITS_HXX #include // std::auto_ptr #include #include #include namespace odb { enum id_source { ids_assigned /* Assigned by the application. */ }; // Specializations should defined the following members: // // id_type - object id (primary key) type // id_source - object id (primary key) source // id_type id (const T&) - get object id // // void insert (database&, const T&) // void update (database&, const T&) // void erase (database&, const id_type&) // memory_traits::shared_ptr find (database&, const id_type&) // // And inherit from object_memory and object_factory. // // template // class access::object_traits; template class access::object_memory { public: typedef odb::shared_ptr shared_ptr; typedef std::auto_ptr unique_ptr; }; template class access::object_factory { public: static typename object_memory::shared_ptr create () { // By default use shared_ptr-specific construction. // return shared_factory::shared_ptr>::create (); } }; template class access::shared_factory { public: typedef typename shared_ptr_traits

::type object_type; static P create () { void* v (shared_ptr_traits

::allocate (sizeof (object_type))); guard g (v); P p (new (v) object_type); g.release (); return p; } private: struct guard { guard (void* p): p_ (p) {} ~guard () {if (p_) shared_ptr_traits

::free (p_);} void release () {p_ = 0;} void* p_; }; }; template struct object_traits: access::object_traits { typedef shared_ptr_traits::shared_ptr> shared_ops; }; } #endif // ODB_TRAITS_HXX