| cache-traits.hxx | | cache-traits.hxx | |
| // file : odb/cache-traits.hxx | | // file : odb/cache-traits.hxx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_CACHE_TRAITS_HXX | | #ifndef ODB_CACHE_TRAITS_HXX | |
| #define ODB_CACHE_TRAITS_HXX | | #define ODB_CACHE_TRAITS_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
| #include <odb/traits.hxx> | | #include <odb/traits.hxx> | |
| #include <odb/forward.hxx> | | #include <odb/forward.hxx> | |
| #include <odb/session.hxx> | | #include <odb/session.hxx> | |
| #include <odb/pointer-traits.hxx> | | #include <odb/pointer-traits.hxx> | |
| #include <odb/no-op-cache-traits.hxx> | | #include <odb/no-op-cache-traits.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| // pointer_cache_traits | | // pointer_cache_traits | |
| // | | // | |
| // Caching traits for objects passed by pointer. P should be the canonica
l | | // Caching traits for objects passed by pointer. P should be the canonica
l | |
| // pointer (non-const). | | // pointer (non-const). | |
| // | | // | |
|
| template <typename P, pointer_kind pk> | | template <typename P, typename S, pointer_kind pk> | |
| struct pointer_cache_traits_impl | | struct pointer_cache_traits_impl | |
| { | | { | |
| typedef P pointer_type; | | typedef P pointer_type; | |
|
| | | typedef S session_type; | |
| typedef odb::pointer_traits<pointer_type> pointer_traits; | | typedef odb::pointer_traits<pointer_type> pointer_traits; | |
| typedef typename pointer_traits::element_type object_type; | | typedef typename pointer_traits::element_type object_type; | |
| typedef typename object_traits<object_type>::id_type id_type; | | typedef typename object_traits<object_type>::id_type id_type; | |
|
| typedef session::object_position<object_type> position_type; | | typedef typename session_type::template cache_position<object_type> | |
| | | position_type; | |
| | | | |
| struct insert_guard | | struct insert_guard | |
| { | | { | |
| insert_guard () {} | | insert_guard () {} | |
| insert_guard (const position_type& pos): pos_ (pos) {} | | insert_guard (const position_type& pos): pos_ (pos) {} | |
|
| ~insert_guard () {erase (pos_);} | | ~insert_guard () {session_type::_cache_erase (pos_);} | |
| | | | |
|
| position_type | | const position_type& | |
| position () const {return pos_;} | | position () const {return pos_;} | |
| | | | |
| void | | void | |
|
| release () {pos_.map_ = 0;} | | release () {pos_ = position_type ();} | |
| | | | |
|
| // Note: doesn't call erase() on the old position (assumes not set). | | // Note: doesn't call erase() on the old position (assumes empty). | |
| // | | // | |
| void | | void | |
| reset (const position_type& pos) {pos_ = pos;} | | reset (const position_type& pos) {pos_ = pos;} | |
| | | | |
| private: | | private: | |
| position_type pos_; | | position_type pos_; | |
| }; | | }; | |
| | | | |
|
| | | // Cache management. | |
| | | // | |
| // We need the insert() overload with explicit id to handle self- | | // We need the insert() overload with explicit id to handle self- | |
| // references. In such cases the object is not yet loaded and the | | // references. In such cases the object is not yet loaded and the | |
| // id member does not contain the correct id. | | // id member does not contain the correct id. | |
| // | | // | |
| // Qualify the database type to resolve a phony ambiguity in VC 10. | | // Qualify the database type to resolve a phony ambiguity in VC 10. | |
| // | | // | |
| static position_type | | static position_type | |
| insert (odb::database& db, const id_type& id, const pointer_type& p) | | insert (odb::database& db, const id_type& id, const pointer_type& p) | |
| { | | { | |
|
| if (session::has_current ()) | | return session_type::template _cache_insert<object_type> (db, id, p); | |
| return session::current ().insert<object_type> (db, id, p); | | | |
| else | | | |
| return position_type (); | | | |
| } | | } | |
| | | | |
| static position_type | | static position_type | |
| insert (odb::database& db, const pointer_type& p) | | insert (odb::database& db, const pointer_type& p) | |
| { | | { | |
| const id_type& id ( | | const id_type& id ( | |
| object_traits<object_type>::id ( | | object_traits<object_type>::id ( | |
| pointer_traits::get_ref (p))); | | pointer_traits::get_ref (p))); | |
| | | | |
|
| return insert (db, id, p); | | return session_type::template _cache_insert<object_type> (db, id, p); | |
| } | | } | |
| | | | |
| static pointer_type | | static pointer_type | |
| find (odb::database& db, const id_type& id) | | find (odb::database& db, const id_type& id) | |
| { | | { | |
|
| if (session::has_current ()) | | return session_type::template _cache_find<object_type> (db, id); | |
| return session::current ().find<object_type> (db, id); | | | |
| else | | | |
| return pointer_type (); | | | |
| } | | } | |
| | | | |
| static void | | static void | |
|
| erase (odb::database& db, const id_type& id) | | erase (const position_type& p) | |
| { | | { | |
|
| if (session::has_current ()) | | session_type::template _cache_erase<object_type> (p); | |
| session::current ().erase<object_type> (db, id); | | | |
| } | | } | |
| | | | |
|
| | | // Notifications. | |
| | | // | |
| static void | | static void | |
|
| erase (const position_type& p) | | persist (const position_type& p) | |
| | | { | |
| | | session_type::template _cache_persist<object_type> (p); | |
| | | } | |
| | | | |
| | | static void | |
| | | load (const position_type& p) | |
| | | { | |
| | | session_type::template _cache_load<object_type> (p); | |
| | | } | |
| | | | |
| | | static void | |
| | | update (odb::database& db, const object_type& obj) | |
| { | | { | |
|
| if (p.map_ != 0) | | session_type::template _cache_update<object_type> (db, obj); | |
| session::current ().erase<object_type> (p); | | } | |
| | | | |
| | | static void | |
| | | erase (odb::database& db, const id_type& id) | |
| | | { | |
| | | session_type::template _cache_erase<object_type> (db, id); | |
| } | | } | |
| }; | | }; | |
| | | | |
| // Unique pointers don't work with the object cache. | | // Unique pointers don't work with the object cache. | |
| // | | // | |
|
| template <typename P> | | template <typename P, typename S> | |
| struct pointer_cache_traits_impl<P, pk_unique>: | | struct pointer_cache_traits_impl<P, S, pk_unique>: | |
| no_op_pointer_cache_traits<P> {}; | | no_op_pointer_cache_traits<P> {}; | |
| | | | |
|
| template <typename P> | | template <typename P, typename S> | |
| struct pointer_cache_traits: | | struct pointer_cache_traits: | |
|
| pointer_cache_traits_impl<P, pointer_traits<P>::kind> {}; | | pointer_cache_traits_impl<P, S, pointer_traits<P>::kind> {}; | |
| | | | |
| // reference_cache_traits | | // reference_cache_traits | |
| // | | // | |
| // Caching traits for objects passed by reference. T should be the | | // Caching traits for objects passed by reference. T should be the | |
| // canonical object type (non-const). Only if the object pointer | | // canonical object type (non-const). Only if the object pointer | |
| // kind is raw do we add the object to the session. | | // kind is raw do we add the object to the session. | |
| // | | // | |
|
| template <typename T, pointer_kind pk> | | template <typename T, typename S, pointer_kind pk> | |
| struct reference_cache_traits_impl: no_op_reference_cache_traits<T> {}; | | struct reference_cache_traits_impl: no_op_reference_cache_traits<T> {}; | |
| | | | |
|
| template <typename T> | | template <typename T, typename S> | |
| struct reference_cache_traits_impl<T, pk_raw> | | struct reference_cache_traits_impl<T, S, pk_raw> | |
| { | | { | |
| typedef T object_type; | | typedef T object_type; | |
| typedef typename object_traits<object_type>::pointer_type pointer_type; | | typedef typename object_traits<object_type>::pointer_type pointer_type; | |
| typedef typename object_traits<object_type>::id_type id_type; | | typedef typename object_traits<object_type>::id_type id_type; | |
| | | | |
|
| typedef pointer_cache_traits<pointer_type> pointer_traits; | | typedef pointer_cache_traits<pointer_type, S> pointer_traits; | |
| typedef typename pointer_traits::position_type position_type; | | typedef typename pointer_traits::position_type position_type; | |
| typedef typename pointer_traits::insert_guard insert_guard; | | typedef typename pointer_traits::insert_guard insert_guard; | |
| | | | |
| static position_type | | static position_type | |
| insert (odb::database& db, const id_type& id, object_type& obj) | | insert (odb::database& db, const id_type& id, object_type& obj) | |
| { | | { | |
| pointer_type p (&obj); | | pointer_type p (&obj); | |
| return pointer_traits::insert (db, id, p); | | return pointer_traits::insert (db, id, p); | |
| } | | } | |
| | | | |
| static position_type | | static position_type | |
| insert (odb::database& db, object_type& obj) | | insert (odb::database& db, object_type& obj) | |
| { | | { | |
| pointer_type p (&obj); | | pointer_type p (&obj); | |
| return pointer_traits::insert (db, p); | | return pointer_traits::insert (db, p); | |
| } | | } | |
|
| | | | |
| | | static void | |
| | | persist (const position_type& p) | |
| | | { | |
| | | pointer_traits::persist (p); | |
| | | } | |
| | | | |
| | | static void | |
| | | load (const position_type& p) | |
| | | { | |
| | | pointer_traits::load (p); | |
| | | } | |
| }; | | }; | |
| | | | |
|
| template <typename T> | | template <typename T, typename S> | |
| struct reference_cache_traits: | | struct reference_cache_traits: | |
| reference_cache_traits_impl< | | reference_cache_traits_impl< | |
|
| T, pointer_traits<typename object_traits<T>::pointer_type>::kind> {}; | | T, S, pointer_traits<typename object_traits<T>::pointer_type>::kind>
{}; | |
| } | | } | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| #endif // ODB_CACHE_TRAITS_HXX | | #endif // ODB_CACHE_TRAITS_HXX | |
| | | | |
End of changes. 26 change blocks. |
| 32 lines changed or deleted | | 60 lines changed or added | |
|
| connection.hxx | | connection.hxx | |
| // file : odb/connection.hxx | | // file : odb/connection.hxx | |
|
| // copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_CONNECTION_HXX | | #ifndef ODB_CONNECTION_HXX | |
| #define ODB_CONNECTION_HXX | | #define ODB_CONNECTION_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
|
| | | #include <map> | |
| #include <string> | | #include <string> | |
|
| #include <cstddef> // std::size_t | | #include <memory> // std::auto_ptr, std::unique_ptr | |
| | | #include <cstddef> // std::size_t | |
| | | #include <typeinfo> | |
| | | | |
| #include <odb/forward.hxx> | | #include <odb/forward.hxx> | |
|
| | | #include <odb/traits.hxx> | |
| | | #include <odb/query.hxx> | |
| | | #include <odb/prepared-query.hxx> | |
| | | | |
|
| | | #include <odb/details/config.hxx> // ODB_CXX11 | |
| #include <odb/details/export.hxx> | | #include <odb/details/export.hxx> | |
|
| | | #include <odb/details/c-string.hxx> | |
| #include <odb/details/shared-ptr.hxx> | | #include <odb/details/shared-ptr.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| class transaction_impl; | | class transaction_impl; | |
| | | | |
| class connection; | | class connection; | |
| typedef details::shared_ptr<connection> connection_ptr; | | typedef details::shared_ptr<connection> connection_ptr; | |
| | | | |
| class LIBODB_EXPORT connection: public details::shared_base | | class LIBODB_EXPORT connection: public details::shared_base | |
| | | | |
| skipping to change at line 53 | | skipping to change at line 61 | |
| public: | | public: | |
| unsigned long long | | unsigned long long | |
| execute (const char* statement); | | execute (const char* statement); | |
| | | | |
| unsigned long long | | unsigned long long | |
| execute (const std::string& statement); | | execute (const std::string& statement); | |
| | | | |
| virtual unsigned long long | | virtual unsigned long long | |
| execute (const char* statement, std::size_t length) = 0; | | execute (const char* statement, std::size_t length) = 0; | |
| | | | |
|
| | | // Query preparation. | |
| | | // | |
| | | public: | |
| | | template <typename T> | |
| | | prepared_query<T> | |
| | | prepare_query (const char* name, const char*); | |
| | | | |
| | | template <typename T> | |
| | | prepared_query<T> | |
| | | prepare_query (const char* name, const std::string&); | |
| | | | |
| | | template <typename T> | |
| | | prepared_query<T> | |
| | | prepare_query (const char* name, const query<T>&); | |
| | | | |
| | | template <typename T> | |
| | | void | |
| | | cache_query (const prepared_query<T>&); | |
| | | | |
| | | template <typename T, typename P> | |
| | | void | |
| | | cache_query (const prepared_query<T>&, std::auto_ptr<P> params); | |
| | | | |
| | | #ifdef ODB_CXX11 | |
| | | template <typename T, typename P> | |
| | | void | |
| | | cache_query (const prepared_query<T>&, std::unique_ptr<P> params); | |
| | | #endif | |
| | | | |
| | | template <typename T> | |
| | | prepared_query<T> | |
| | | lookup_query (const char* name) const; | |
| | | | |
| | | template <typename T, typename P> | |
| | | prepared_query<T> | |
| | | lookup_query (const char* name, P*& params) const; | |
| | | | |
| // SQL statement tracing. | | // SQL statement tracing. | |
| // | | // | |
| public: | | public: | |
| typedef odb::tracer tracer_type; | | typedef odb::tracer tracer_type; | |
| | | | |
| void | | void | |
| tracer (tracer_type&); | | tracer (tracer_type&); | |
| | | | |
| void | | void | |
| tracer (tracer_type*); | | tracer (tracer_type*); | |
| | | | |
| skipping to change at line 81 | | skipping to change at line 126 | |
| // the current() API. But that requires a TLS lookup, which can be | | // the current() API. But that requires a TLS lookup, which can be | |
| // slow. | | // slow. | |
| // | | // | |
| tracer_type* | | tracer_type* | |
| transaction_tracer () const; | | transaction_tracer () const; | |
| | | | |
| public: | | public: | |
| virtual | | virtual | |
| ~connection (); | | ~connection (); | |
| | | | |
|
| | | // Recycle the connection to be used by another thread. This call | |
| | | // invalidates uncached prepared queries. | |
| | | // | |
| | | void | |
| | | recycle (); | |
| | | | |
| protected: | | protected: | |
| connection (database_type&); | | connection (database_type&); | |
| | | | |
|
| | | template <typename T, | |
| | | database_id DB, | |
| | | class_kind kind = class_traits<T>::kind> | |
| | | struct query_; | |
| | | | |
| | | virtual void | |
| | | cache_query_ (prepared_query_impl* pq, | |
| | | const std::type_info& ti, | |
| | | void* params, | |
| | | const std::type_info* params_info, | |
| | | void (*params_deleter) (void*)); | |
| | | | |
| | | prepared_query_impl* | |
| | | lookup_query_ (const char* name, | |
| | | const std::type_info& ti, | |
| | | void** params, // out | |
| | | const std::type_info* params_info) const; | |
| | | | |
| | | template <typename P> | |
| | | static void | |
| | | params_deleter (void*); | |
| | | | |
| private: | | private: | |
| connection (const connection&); | | connection (const connection&); | |
| connection& operator= (const connection&); | | connection& operator= (const connection&); | |
| | | | |
|
| | | // Prepared query cache. | |
| | | // | |
| | | protected: | |
| | | struct prepared_entry_type | |
| | | { | |
| | | details::shared_ptr<prepared_query_impl> prep_query; | |
| | | const std::type_info* type_info; | |
| | | void* params; | |
| | | const std::type_info* params_info; | |
| | | void (*params_deleter) (void*); | |
| | | }; | |
| | | | |
| | | typedef | |
| | | std::map<const char*, prepared_entry_type, details::c_string_comparator | |
| | | > | |
| | | prepared_map_type; | |
| | | | |
| | | prepared_map_type prepared_map_; | |
| | | | |
| | | void | |
| | | clear_prepared_map (); | |
| | | | |
| protected: | | protected: | |
| database_type& database_; | | database_type& database_; | |
| tracer_type* tracer_; | | tracer_type* tracer_; | |
| | | | |
|
| | | // Active query result list. | |
| | | // | |
| | | protected: | |
| | | friend class result_impl; | |
| | | result_impl* results_; | |
| | | | |
| | | void | |
| | | invalidate_results (); | |
| | | | |
| | | // Prepared but uncached query list (cached ones are stored in | |
| | | // prepared_map_). | |
| | | // | |
| | | protected: | |
| | | friend class prepared_query_impl; | |
| | | prepared_query_impl* prepared_queries_; | |
| | | | |
| protected: | | protected: | |
| friend class transaction; | | friend class transaction; | |
| tracer_type* transaction_tracer_; | | tracer_type* transaction_tracer_; | |
| }; | | }; | |
| } | | } | |
| | | | |
| #include <odb/connection.ixx> | | #include <odb/connection.ixx> | |
|
| | | #include <odb/connection.txx> | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| #endif // ODB_MYSQL_CONNECTION_HXX | | #endif // ODB_MYSQL_CONNECTION_HXX | |
| | | | |
End of changes. 12 change blocks. |
| 2 lines changed or deleted | | 114 lines changed or added | |
|
| container-traits.hxx | | container-traits.hxx | |
| // file : odb/container-traits.hxx | | // file : odb/container-traits.hxx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_CONTAINER_TRAITS_HXX | | #ifndef ODB_CONTAINER_TRAITS_HXX | |
| #define ODB_CONTAINER_TRAITS_HXX | | #define ODB_CONTAINER_TRAITS_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
| #include <odb/forward.hxx> | | #include <odb/forward.hxx> | |
| #include <odb/details/config.hxx> // ODB_CXX11 | | #include <odb/details/config.hxx> // ODB_CXX11 | |
| | | | |
| | | | |
| skipping to change at line 49 | | skipping to change at line 49 | |
| // order is not preserved, then the index argument in the functions | | // order is not preserved, then the index argument in the functions | |
| // below is not used. | | // below is not used. | |
| // | | // | |
| bool | | bool | |
| ordered () const | | ordered () const | |
| { | | { | |
| return ordered_; | | return ordered_; | |
| } | | } | |
| | | | |
| void | | void | |
|
| insert_one (I index, const V& value) const | | insert (I index, const V& value) const | |
| { | | { | |
|
| insert_one_ (index, value, data_); | | insert_ (index, value, data_); | |
| } | | } | |
| | | | |
| bool | | bool | |
|
| load_all (I& next_index, V& next_value) const | | select (I& next_index, V& next_value) const | |
| { | | { | |
|
| return load_all_ (next_index, next_value, data_); | | return select_ (next_index, next_value, data_); | |
| } | | } | |
| | | | |
| void | | void | |
|
| delete_all () const | | delete_ () const | |
| { | | { | |
|
| delete_all_ (data_); | | delete__ (data_); | |
| } | | } | |
| | | | |
| // Implementation details. | | // Implementation details. | |
| // | | // | |
| public: | | public: | |
|
| typedef void (*insert_one_type) (I, const V&, void*); | | ordered_functions (void* data): data_ (data) {} | |
| typedef bool (*load_all_type) (I&, V&, void*); | | | |
| typedef void (*delete_all_type) (void*); | | | |
| | | | |
|
| ordered_functions (void* data, | | public: | |
| insert_one_type io, | | void* data_; | |
| load_all_type la, | | bool ordered_; | |
| delete_all_type da) | | | |
| : data_ (data), insert_one_ (io), load_all_ (la), delete_all_ (da) | | void (*insert_) (I, const V&, void*); | |
| | | bool (*select_) (I&, V&, void*); | |
| | | void (*delete__) (void*); | |
| | | }; | |
| | | | |
| | | template <typename I, typename V> | |
| | | struct smart_ordered_functions | |
| | | { | |
| | | typedef I index_type; | |
| | | typedef V value_type; | |
| | | | |
| | | void | |
| | | insert (I index, const V& value) const | |
| | | { | |
| | | insert_ (index, value, data_); | |
| | | } | |
| | | | |
| | | bool | |
| | | select (I& next_index, V& next_value) const | |
| | | { | |
| | | return select_ (next_index, next_value, data_); | |
| | | } | |
| | | | |
| | | void | |
| | | update (I index, const V& value) const | |
| { | | { | |
|
| | | update_ (index, value, data_); | |
| } | | } | |
| | | | |
|
| | | // Delete all the elements starting with the specified index. To | |
| | | // delete everything, pass 0. | |
| | | // | |
| void | | void | |
|
| ordered (bool v) | | delete_ (I start_index) const | |
| { | | { | |
|
| ordered_ = v; | | delete__ (start_index, data_); | |
| } | | } | |
| | | | |
|
| private: | | // Implementation details. | |
| | | // | |
| | | public: | |
| | | smart_ordered_functions (void* data) : data_ (data) {} | |
| | | | |
| | | public: | |
| void* data_; | | void* data_; | |
|
| bool ordered_; | | | |
| insert_one_type insert_one_; | | void (*insert_) (I, const V&, void*); | |
| load_all_type load_all_; | | bool (*select_) (I&, V&, void*); | |
| delete_all_type delete_all_; | | void (*update_) (I, const V&, void*); | |
| | | void (*delete__) (I, void*); | |
| }; | | }; | |
| | | | |
| // Set/multiset containers. | | // Set/multiset containers. | |
| // | | // | |
| template <typename V> | | template <typename V> | |
| struct set_functions | | struct set_functions | |
| { | | { | |
| typedef V value_type; | | typedef V value_type; | |
| | | | |
| void | | void | |
|
| insert_one (const V& value) const | | insert (const V& value) const | |
| { | | { | |
|
| insert_one_ (value, data_); | | insert_ (value, data_); | |
| } | | } | |
| | | | |
| bool | | bool | |
|
| load_all (V& next_value) const | | select (V& next_value) const | |
| { | | { | |
|
| return load_all_ (next_value, data_); | | return select_ (next_value, data_); | |
| } | | } | |
| | | | |
| void | | void | |
|
| delete_all () const | | delete_ () const | |
| { | | { | |
|
| delete_all_ (data_); | | delete__ (data_); | |
| } | | } | |
| | | | |
| // Implementation details. | | // Implementation details. | |
| // | | // | |
| public: | | public: | |
|
| typedef void (*insert_one_type) (const V&, void*); | | set_functions (void* data): data_ (data) {} | |
| typedef bool (*load_all_type) (V&, void*); | | | |
| typedef void (*delete_all_type) (void*); | | | |
| | | | |
|
| set_functions (void* data, | | public: | |
| insert_one_type io, | | | |
| load_all_type la, | | | |
| delete_all_type da) | | | |
| : data_ (data), insert_one_ (io), load_all_ (la), delete_all_ (da) | | | |
| { | | | |
| } | | | |
| | | | |
| private: | | | |
| void* data_; | | void* data_; | |
|
| insert_one_type insert_one_; | | | |
| load_all_type load_all_; | | void (*insert_) (const V&, void*); | |
| delete_all_type delete_all_; | | bool (*select_) (V&, void*); | |
| | | void (*delete__) (void*); | |
| }; | | }; | |
| | | | |
| // Map/multimap containers. | | // Map/multimap containers. | |
| // | | // | |
| template <typename K, typename V> | | template <typename K, typename V> | |
| struct map_functions | | struct map_functions | |
| { | | { | |
| typedef K key_type; | | typedef K key_type; | |
| typedef V value_type; | | typedef V value_type; | |
| | | | |
| void | | void | |
|
| insert_one (const K& key, const V& value) const | | insert (const K& key, const V& value) const | |
| { | | { | |
|
| insert_one_ (key, value, data_); | | insert_ (key, value, data_); | |
| } | | } | |
| | | | |
| bool | | bool | |
|
| load_all (K& next_key, V& next_value) const | | select (K& next_key, V& next_value) const | |
| { | | { | |
|
| return load_all_ (next_key, next_value, data_); | | return select_ (next_key, next_value, data_); | |
| } | | } | |
| | | | |
| void | | void | |
|
| delete_all () const | | delete_ () const | |
| { | | { | |
|
| delete_all_ (data_); | | delete__ (data_); | |
| } | | } | |
| | | | |
| // Implementation details. | | // Implementation details. | |
| // | | // | |
| public: | | public: | |
|
| typedef void (*insert_one_type) (const K&, const V&, void*); | | map_functions (void* data): data_ (data) {} | |
| typedef bool (*load_all_type) (K&, V&, void*); | | | |
| typedef void (*delete_all_type) (void*); | | | |
| | | | |
|
| map_functions (void* data, | | public: | |
| insert_one_type io, | | | |
| load_all_type la, | | | |
| delete_all_type da) | | | |
| : data_ (data), insert_one_ (io), load_all_ (la), delete_all_ (da) | | | |
| { | | | |
| } | | | |
| | | | |
| private: | | | |
| void* data_; | | void* data_; | |
|
| insert_one_type insert_one_; | | | |
| load_all_type load_all_; | | void (*insert_) (const K&, const V&, void*); | |
| delete_all_type delete_all_; | | bool (*select_) (K&, V&, void*); | |
| | | void (*delete__) (void*); | |
| }; | | }; | |
| } | | } | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| #include <odb/std-map-traits.hxx> | | #include <odb/std-map-traits.hxx> | |
| #include <odb/std-set-traits.hxx> | | #include <odb/std-set-traits.hxx> | |
| #include <odb/std-list-traits.hxx> | | #include <odb/std-list-traits.hxx> | |
| #include <odb/std-vector-traits.hxx> | | #include <odb/std-vector-traits.hxx> | |
| | | | |
| | | | |
End of changes. 33 change blocks. |
| 64 lines changed or deleted | | 78 lines changed or added | |
|
| database.hxx | | database.hxx | |
| // file : odb/database.hxx | | // file : odb/database.hxx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_DATABASE_HXX | | #ifndef ODB_DATABASE_HXX | |
| #define ODB_DATABASE_HXX | | #define ODB_DATABASE_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
|
| | | #include <odb/details/config.hxx> // ODB_CXX11 | |
| | | | |
| | | #include <map> | |
| #include <string> | | #include <string> | |
|
| | | #include <memory> // std::auto_ptr, std::unique_ptr | |
| #include <cstddef> // std::size_t | | #include <cstddef> // std::size_t | |
| | | | |
|
| | | #ifdef ODB_CXX11 | |
| | | # include <functional> // std::function | |
| | | #endif | |
| | | | |
| #include <odb/traits.hxx> | | #include <odb/traits.hxx> | |
| #include <odb/forward.hxx> | | #include <odb/forward.hxx> | |
| #include <odb/query.hxx> | | #include <odb/query.hxx> | |
|
| | | #include <odb/prepared-query.hxx> | |
| #include <odb/result.hxx> | | #include <odb/result.hxx> | |
| #include <odb/connection.hxx> | | #include <odb/connection.hxx> | |
| #include <odb/exceptions.hxx> | | #include <odb/exceptions.hxx> | |
| | | | |
| #include <odb/details/export.hxx> | | #include <odb/details/export.hxx> | |
|
| | | #include <odb/details/c-string.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| class transaction_impl; | | class transaction_impl; | |
| | | | |
| class LIBODB_EXPORT database | | class LIBODB_EXPORT database | |
| { | | { | |
| public: | | public: | |
| virtual | | virtual | |
| ~database (); | | ~database (); | |
| | | | |
| skipping to change at line 66 | | skipping to change at line 76 | |
| persist (P<T>& obj_ptr); | | persist (P<T>& obj_ptr); | |
| | | | |
| template <typename T, typename A1, template <typename, typename> class
P> | | template <typename T, typename A1, template <typename, typename> class
P> | |
| typename object_traits<T>::id_type | | typename object_traits<T>::id_type | |
| persist (P<T, A1>& obj_ptr); | | persist (P<T, A1>& obj_ptr); | |
| | | | |
| template <typename T> | | template <typename T> | |
| typename object_traits<T>::id_type | | typename object_traits<T>::id_type | |
| persist (const typename object_traits<T>::pointer_type& obj_ptr); | | persist (const typename object_traits<T>::pointer_type& obj_ptr); | |
| | | | |
|
| // Throw object_not_persistent if not found. | | // Load an object. Throw object_not_persistent if not found. | |
| // | | // | |
| template <typename T> | | template <typename T> | |
| typename object_traits<T>::pointer_type | | typename object_traits<T>::pointer_type | |
| load (const typename object_traits<T>::id_type& id); | | load (const typename object_traits<T>::id_type& id); | |
| | | | |
| template <typename T> | | template <typename T> | |
| void | | void | |
| load (const typename object_traits<T>::id_type& id, T& object); | | load (const typename object_traits<T>::id_type& id, T& object); | |
| | | | |
|
| | | // Reload an object. | |
| | | // | |
| template <typename T> | | template <typename T> | |
| void | | void | |
| reload (T& object); | | reload (T& object); | |
| | | | |
| template <typename T> | | template <typename T> | |
| void | | void | |
| reload (T* obj_ptr); | | reload (T* obj_ptr); | |
| | | | |
| template <typename T, template <typename> class P> | | template <typename T, template <typename> class P> | |
| void | | void | |
| | | | |
| skipping to change at line 104 | | skipping to change at line 116 | |
| reload (P<T>& obj_ptr); | | reload (P<T>& obj_ptr); | |
| | | | |
| template <typename T, typename A1, template <typename, typename> class
P> | | template <typename T, typename A1, template <typename, typename> class
P> | |
| void | | void | |
| reload (P<T, A1>& obj_ptr); | | reload (P<T, A1>& obj_ptr); | |
| | | | |
| template <typename T> | | template <typename T> | |
| void | | void | |
| reload (const typename object_traits<T>::pointer_type& obj_ptr); | | reload (const typename object_traits<T>::pointer_type& obj_ptr); | |
| | | | |
|
| // Return NULL/false if not found. | | // Loan an object if found. Return NULL/false if not found. | |
| // | | // | |
| template <typename T> | | template <typename T> | |
| typename object_traits<T>::pointer_type | | typename object_traits<T>::pointer_type | |
| find (const typename object_traits<T>::id_type& id); | | find (const typename object_traits<T>::id_type& id); | |
| | | | |
| template <typename T> | | template <typename T> | |
| bool | | bool | |
| find (const typename object_traits<T>::id_type& id, T& object); | | find (const typename object_traits<T>::id_type& id, T& object); | |
| | | | |
| // Update the state of a modified objects. | | // Update the state of a modified objects. | |
| | | | |
| skipping to change at line 215 | | skipping to change at line 227 | |
| query (const char*, bool cache = true); | | query (const char*, bool cache = true); | |
| | | | |
| template <typename T> | | template <typename T> | |
| result<T> | | result<T> | |
| query (const std::string&, bool cache = true); | | query (const std::string&, bool cache = true); | |
| | | | |
| template <typename T> | | template <typename T> | |
| result<T> | | result<T> | |
| query (const odb::query<T>&, bool cache = true); | | query (const odb::query<T>&, bool cache = true); | |
| | | | |
|
| | | // Query preparation. | |
| | | // | |
| | | template <typename T> | |
| | | prepared_query<T> | |
| | | prepare_query (const char* name, const char*); | |
| | | | |
| | | template <typename T> | |
| | | prepared_query<T> | |
| | | prepare_query (const char* name, const std::string&); | |
| | | | |
| | | template <typename T> | |
| | | prepared_query<T> | |
| | | prepare_query (const char* name, const odb::query<T>&); | |
| | | | |
| | | template <typename T> | |
| | | void | |
| | | cache_query (const prepared_query<T>&); | |
| | | | |
| | | template <typename T, typename P> | |
| | | void | |
| | | cache_query (const prepared_query<T>&, std::auto_ptr<P> params); | |
| | | | |
| | | #ifdef ODB_CXX11 | |
| | | template <typename T, typename P> | |
| | | void | |
| | | cache_query (const prepared_query<T>&, std::unique_ptr<P> params); | |
| | | #endif | |
| | | | |
| | | template <typename T> | |
| | | prepared_query<T> | |
| | | lookup_query (const char* name) const; | |
| | | | |
| | | template <typename T, typename P> | |
| | | prepared_query<T> | |
| | | lookup_query (const char* name, P*& params) const; | |
| | | | |
| | | // Prepared query factory. | |
| | | // | |
| | | public: | |
| | | typedef odb::connection connection_type; | |
| | | | |
| | | #ifdef ODB_CXX11 | |
| | | typedef | |
| | | std::function<void (const char*, connection_type&)> | |
| | | query_factory_type; | |
| | | #else | |
| | | typedef void (*query_factory_type) (const char*, connection_type&); | |
| | | #endif | |
| | | | |
| | | void | |
| | | query_factory (const char* name, query_factory_type); | |
| | | | |
| | | query_factory_type | |
| | | lookup_query_factory (const char* name) const; | |
| | | | |
| // Native database statement execution. | | // Native database statement execution. | |
| // | | // | |
| public: | | public: | |
| unsigned long long | | unsigned long long | |
| execute (const char* statement); | | execute (const char* statement); | |
| | | | |
| unsigned long long | | unsigned long long | |
| execute (const std::string& statement); | | execute (const std::string& statement); | |
| | | | |
| unsigned long long | | unsigned long long | |
| | | | |
| skipping to change at line 253 | | skipping to change at line 320 | |
| | | | |
| void | | void | |
| tracer (tracer_type&); | | tracer (tracer_type&); | |
| | | | |
| void | | void | |
| tracer (tracer_type*); | | tracer (tracer_type*); | |
| | | | |
| tracer_type* | | tracer_type* | |
| tracer () const; | | tracer () const; | |
| | | | |
|
| | | // Database id. | |
| | | // | |
| | | public: | |
| | | database_id | |
| | | id () const; | |
| | | | |
| protected: | | protected: | |
|
| database (); | | database (database_id); | |
| | | | |
| private: | | private: | |
| database (const database&); | | database (const database&); | |
| database& operator= (const database&); | | database& operator= (const database&); | |
| | | | |
| protected: | | protected: | |
|
| typedef odb::connection connection_type; | | | |
| | | | |
| virtual connection_type* | | virtual connection_type* | |
| connection_ () = 0; | | connection_ () = 0; | |
| | | | |
| protected: | | protected: | |
|
| template <typename T> | | template <typename T, database_id DB> | |
| | | typename object_traits<T>::id_type | |
| | | persist_ (T&); | |
| | | | |
| | | template <typename T, database_id DB> | |
| typename object_traits<T>::id_type | | typename object_traits<T>::id_type | |
| persist_ (const typename object_traits<T>::pointer_type&); | | persist_ (const typename object_traits<T>::pointer_type&); | |
| | | | |
|
| template <typename T> | | template <typename T, database_id DB> | |
| | | typename object_traits<T>::pointer_type | |
| | | load_ (const typename object_traits<T>::id_type&); | |
| | | | |
| | | template <typename T, database_id DB> | |
| | | void | |
| | | load_ (const typename object_traits<T>::id_type&, T&); | |
| | | | |
| | | template <typename T, database_id DB> | |
| | | void | |
| | | reload_ (T&); | |
| | | | |
| | | template <typename T, database_id DB> | |
| | | typename object_traits<T>::pointer_type | |
| | | find_ (const typename object_traits<T>::id_type&); | |
| | | | |
| | | template <typename T, database_id DB> | |
| | | bool | |
| | | find_ (const typename object_traits<T>::id_type&, T&); | |
| | | | |
| | | template <typename T, database_id DB> | |
| | | void | |
| | | update_ (T&); | |
| | | | |
| | | template <typename T, database_id DB> | |
| void | | void | |
| update_ (const typename object_traits<T>::pointer_type&); | | update_ (const typename object_traits<T>::pointer_type&); | |
| | | | |
|
| template <typename T> | | template <typename T, database_id DB> | |
| | | void | |
| | | erase_ (const typename object_traits<T>::id_type&); | |
| | | | |
| | | template <typename T, database_id DB> | |
| | | void | |
| | | erase_ (T&); | |
| | | | |
| | | template <typename T, database_id DB> | |
| void | | void | |
| erase_ (const typename object_traits<T>::pointer_type&); | | erase_ (const typename object_traits<T>::pointer_type&); | |
| | | | |
|
| template <typename T, class_kind kind> | | template <typename T, | |
| | | database_id DB, | |
| | | class_kind kind = class_traits<T>::kind> | |
| struct query_; | | struct query_; | |
| | | | |
| protected: | | protected: | |
|
| | | typedef | |
| | | std::map<const char*, query_factory_type, details::c_string_comparator> | |
| | | query_factory_map; | |
| | | | |
| | | database_id id_; | |
| tracer_type* tracer_; | | tracer_type* tracer_; | |
|
| | | query_factory_map query_factory_map_; | |
| }; | | }; | |
| } | | } | |
| | | | |
| #include <odb/database.ixx> | | #include <odb/database.ixx> | |
| #include <odb/database.txx> | | #include <odb/database.txx> | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| #endif // ODB_DATABASE_HXX | | #endif // ODB_DATABASE_HXX | |
| | | | |
End of changes. 19 change blocks. |
| 10 lines changed or deleted | | 125 lines changed or added | |
|
| database.ixx | | database.ixx | |
| // file : odb/database.ixx | | // file : odb/database.ixx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #include <cstring> // std::strlen() | | #include <cstring> // std::strlen() | |
|
| | | #include <utility> // std::move | |
| | | | |
| | | #include <odb/transaction.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| inline database:: | | inline database:: | |
|
| database () | | database (database_id id) | |
| : tracer_ (0) | | : id_ (id), tracer_ (0) | |
| | | { | |
| | | } | |
| | | | |
| | | inline database_id database:: | |
| | | id () const | |
| { | | { | |
|
| | | return id_; | |
| } | | } | |
| | | | |
| inline connection_ptr database:: | | inline connection_ptr database:: | |
| connection () | | connection () | |
| { | | { | |
| return connection_ptr (connection_ ()); | | return connection_ptr (connection_ ()); | |
| } | | } | |
| | | | |
| inline void database:: | | inline void database:: | |
|
| | | query_factory (const char* name, query_factory_type f) | |
| | | { | |
| | | if (f) | |
| | | #ifdef ODB_CXX11 | |
| | | query_factory_map_[name] = std::move (f); | |
| | | #else | |
| | | query_factory_map_[name] = f; | |
| | | #endif | |
| | | else | |
| | | query_factory_map_.erase (name); | |
| | | } | |
| | | | |
| | | inline database::query_factory_type database:: | |
| | | lookup_query_factory (const char* name) const | |
| | | { | |
| | | query_factory_map::const_iterator i (query_factory_map_.find (name)); | |
| | | | |
| | | if (i == query_factory_map_.end ()) | |
| | | i = query_factory_map_.find (""); // Wildcard factory. | |
| | | | |
| | | return i != query_factory_map_.end () | |
| | | ? i->second | |
| | | : database::query_factory_type (); | |
| | | } | |
| | | | |
| | | inline void database:: | |
| tracer (tracer_type& t) | | tracer (tracer_type& t) | |
| { | | { | |
| tracer_ = &t; | | tracer_ = &t; | |
| } | | } | |
| | | | |
| inline void database:: | | inline void database:: | |
| tracer (tracer_type* t) | | tracer (tracer_type* t) | |
| { | | { | |
| tracer_ = t; | | tracer_ = t; | |
| } | | } | |
| | | | |
| inline database::tracer_type* database:: | | inline database::tracer_type* database:: | |
| tracer () const | | tracer () const | |
| { | | { | |
| return tracer_; | | return tracer_; | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline typename object_traits<T>::id_type database:: | | inline typename object_traits<T>::id_type database:: | |
|
| | | persist (T& obj) | |
| | | { | |
| | | return persist_<T, id_common> (obj); | |
| | | } | |
| | | | |
| | | template <typename T> | |
| | | inline typename object_traits<T>::id_type database:: | |
| persist (T* p) | | persist (T* p) | |
| { | | { | |
| typedef typename object_traits<T>::pointer_type object_pointer; | | typedef typename object_traits<T>::pointer_type object_pointer; | |
| | | | |
| // The passed pointer should be the same or implicit-convertible | | // The passed pointer should be the same or implicit-convertible | |
| // to the object pointer. This way we make sure the object pointer | | // to the object pointer. This way we make sure the object pointer | |
| // does not assume ownership of the passed object. | | // does not assume ownership of the passed object. | |
| // | | // | |
| const object_pointer& pobj (p); | | const object_pointer& pobj (p); | |
| | | | |
|
| return persist_<T> (pobj); | | return persist_<T, id_common> (pobj); | |
| } | | } | |
| | | | |
| template <typename T, template <typename> class P> | | template <typename T, template <typename> class P> | |
| inline typename object_traits<T>::id_type database:: | | inline typename object_traits<T>::id_type database:: | |
| persist (const P<T>& p) | | persist (const P<T>& p) | |
| { | | { | |
| typedef typename object_traits<T>::pointer_type object_pointer; | | typedef typename object_traits<T>::pointer_type object_pointer; | |
| | | | |
| // The passed pointer should be the same or implicit-convertible | | // The passed pointer should be the same or implicit-convertible | |
| // to the object pointer. This way we make sure the object pointer | | // to the object pointer. This way we make sure the object pointer | |
| // does not assume ownership of the passed object. | | // does not assume ownership of the passed object. | |
| // | | // | |
| const object_pointer& pobj (p); | | const object_pointer& pobj (p); | |
| | | | |
|
| return persist_<T> (pobj); | | return persist_<T, id_common> (pobj); | |
| } | | } | |
| | | | |
| template <typename T, typename A1, template <typename, typename> class P> | | template <typename T, typename A1, template <typename, typename> class P> | |
| inline typename object_traits<T>::id_type database:: | | inline typename object_traits<T>::id_type database:: | |
| persist (const P<T, A1>& p) | | persist (const P<T, A1>& p) | |
| { | | { | |
| typedef typename object_traits<T>::pointer_type object_pointer; | | typedef typename object_traits<T>::pointer_type object_pointer; | |
| | | | |
| // The passed pointer should be the same or implicit-convertible | | // The passed pointer should be the same or implicit-convertible | |
| // to the object pointer. This way we make sure the object pointer | | // to the object pointer. This way we make sure the object pointer | |
| // does not assume ownership of the passed object. | | // does not assume ownership of the passed object. | |
| // | | // | |
| const object_pointer& pobj (p); | | const object_pointer& pobj (p); | |
| | | | |
|
| return persist_<T> (pobj); | | return persist_<T, id_common> (pobj); | |
| } | | } | |
| | | | |
| template <typename T, template <typename> class P> | | template <typename T, template <typename> class P> | |
| inline typename object_traits<T>::id_type database:: | | inline typename object_traits<T>::id_type database:: | |
| persist (P<T>& p) | | persist (P<T>& p) | |
| { | | { | |
| const P<T>& cr (p); | | const P<T>& cr (p); | |
| return persist<T, P> (cr); | | return persist<T, P> (cr); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 104 | | skipping to change at line 146 | |
| persist (P<T, A1>& p) | | persist (P<T, A1>& p) | |
| { | | { | |
| const P<T, A1>& cr (p); | | const P<T, A1>& cr (p); | |
| return persist<T, A1, P> (cr); | | return persist<T, A1, P> (cr); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline typename object_traits<T>::id_type database:: | | inline typename object_traits<T>::id_type database:: | |
| persist (const typename object_traits<T>::pointer_type& pobj) | | persist (const typename object_traits<T>::pointer_type& pobj) | |
| { | | { | |
|
| return persist_<T> (pobj); | | return persist_<T, id_common> (pobj); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline typename object_traits<T>::pointer_type database:: | | inline typename object_traits<T>::pointer_type database:: | |
|
| find (const typename object_traits<T>::id_type& id) | | load (const typename object_traits<T>::id_type& id) | |
| { | | { | |
|
| // T is always object_type. | | return load_<T, id_common> (id); | |
| // | | } | |
| | | | |
|
| // Compiler error pointing here? Perhaps the object doesn't have the | | template <typename T> | |
| // default constructor? | | inline void database:: | |
| // | | load (const typename object_traits<T>::id_type& id, T& obj) | |
| return object_traits<T>::find (*this, id); | | { | |
| | | return load_<T, id_common> (id, obj); | |
| | | } | |
| | | | |
| | | template <typename T> | |
| | | inline typename object_traits<T>::pointer_type database:: | |
| | | find (const typename object_traits<T>::id_type& id) | |
| | | { | |
| | | return find_<T, id_common> (id); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline bool database:: | | inline bool database:: | |
| find (const typename object_traits<T>::id_type& id, T& obj) | | find (const typename object_traits<T>::id_type& id, T& obj) | |
| { | | { | |
|
| // T is always object_type. | | return find_<T, id_common> (id, obj); | |
| // | | } | |
| return object_traits<T>::find (*this, id, obj); | | | |
| | | template <typename T> | |
| | | inline void database:: | |
| | | reload (T& obj) | |
| | | { | |
| | | reload_<T, id_common> (obj); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline void database:: | | inline void database:: | |
| reload (T* p) | | reload (T* p) | |
| { | | { | |
| reload<T> (*p); | | reload<T> (*p); | |
| } | | } | |
| | | | |
| template <typename T, template <typename> class P> | | template <typename T, template <typename> class P> | |
| | | | |
| skipping to change at line 175 | | skipping to change at line 230 | |
| inline void database:: | | inline void database:: | |
| reload (const typename object_traits<T>::pointer_type& pobj) | | reload (const typename object_traits<T>::pointer_type& pobj) | |
| { | | { | |
| typedef typename object_traits<T>::pointer_type pointer_type; | | typedef typename object_traits<T>::pointer_type pointer_type; | |
| | | | |
| reload (odb::pointer_traits<pointer_type>::get_ref (pobj)); | | reload (odb::pointer_traits<pointer_type>::get_ref (pobj)); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline void database:: | | inline void database:: | |
|
| | | update (T& obj) | |
| | | { | |
| | | update_<T, id_common> (obj); | |
| | | } | |
| | | | |
| | | template <typename T> | |
| | | inline void database:: | |
| update (T* p) | | update (T* p) | |
| { | | { | |
| typedef typename object_traits<T>::pointer_type object_pointer; | | typedef typename object_traits<T>::pointer_type object_pointer; | |
| | | | |
| // The passed pointer should be the same or implicit-convertible | | // The passed pointer should be the same or implicit-convertible | |
| // to the object pointer. This way we make sure the object pointer | | // to the object pointer. This way we make sure the object pointer | |
| // does not assume ownership of the passed object. | | // does not assume ownership of the passed object. | |
| // | | // | |
| const object_pointer& pobj (p); | | const object_pointer& pobj (p); | |
| | | | |
|
| update_<T> (pobj); | | update_<T, id_common> (pobj); | |
| } | | } | |
| | | | |
| template <typename T, template <typename> class P> | | template <typename T, template <typename> class P> | |
| inline void database:: | | inline void database:: | |
| update (const P<T>& p) | | update (const P<T>& p) | |
| { | | { | |
| typedef typename object_traits<T>::pointer_type object_pointer; | | typedef typename object_traits<T>::pointer_type object_pointer; | |
| | | | |
| // The passed pointer should be the same or implicit-convertible | | // The passed pointer should be the same or implicit-convertible | |
| // to the object pointer. This way we make sure the object pointer | | // to the object pointer. This way we make sure the object pointer | |
| // does not assume ownership of the passed object. | | // does not assume ownership of the passed object. | |
| // | | // | |
| const object_pointer& pobj (p); | | const object_pointer& pobj (p); | |
| | | | |
|
| update_<T> (pobj); | | update_<T, id_common> (pobj); | |
| } | | } | |
| | | | |
| template <typename T, typename A1, template <typename, typename> class P> | | template <typename T, typename A1, template <typename, typename> class P> | |
| inline void database:: | | inline void database:: | |
| update (const P<T, A1>& p) | | update (const P<T, A1>& p) | |
| { | | { | |
| typedef typename object_traits<T>::pointer_type object_pointer; | | typedef typename object_traits<T>::pointer_type object_pointer; | |
| | | | |
| // The passed pointer should be the same or implicit-convertible | | // The passed pointer should be the same or implicit-convertible | |
| // to the object pointer. This way we make sure the object pointer | | // to the object pointer. This way we make sure the object pointer | |
| // does not assume ownership of the passed object. | | // does not assume ownership of the passed object. | |
| // | | // | |
| const object_pointer& pobj (p); | | const object_pointer& pobj (p); | |
| | | | |
|
| update_<T> (pobj); | | update_<T, id_common> (pobj); | |
| } | | } | |
| | | | |
| template <typename T, template <typename> class P> | | template <typename T, template <typename> class P> | |
| inline void database:: | | inline void database:: | |
| update (P<T>& p) | | update (P<T>& p) | |
| { | | { | |
| const P<T>& cr (p); | | const P<T>& cr (p); | |
| update<T, P> (cr); | | update<T, P> (cr); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 238 | | skipping to change at line 300 | |
| update (P<T, A1>& p) | | update (P<T, A1>& p) | |
| { | | { | |
| const P<T, A1>& cr (p); | | const P<T, A1>& cr (p); | |
| update<T, A1, P> (cr); | | update<T, A1, P> (cr); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline void database:: | | inline void database:: | |
| update (const typename object_traits<T>::pointer_type& pobj) | | update (const typename object_traits<T>::pointer_type& pobj) | |
| { | | { | |
|
| update_<T> (pobj); | | update_<T, id_common> (pobj); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline void database:: | | inline void database:: | |
|
| update (T& obj) | | erase (const typename object_traits<T>::id_type& id) | |
| { | | { | |
|
| // T can be const T while object_type will always be T. | | return erase_<T, id_common> (id); | |
| // | | | |
| typedef typename odb::object_traits<T>::object_type object_type; | | | |
| typedef odb::object_traits<object_type> 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 <typename T> | | template <typename T> | |
| inline void database:: | | inline void database:: | |
|
| update_ (const typename object_traits<T>::pointer_type& pobj) | | erase (T& obj) | |
| { | | { | |
|
| // T can be const T while object_type will always be T. | | return erase_<T, id_common> (obj); | |
| // | | | |
| typedef typename odb::object_traits<T>::object_type object_type; | | | |
| typedef odb::object_traits<object_type> object_traits; | | | |
| | | | |
| typedef typename odb::object_traits<T>::pointer_type pointer_type; | | | |
| typedef odb::pointer_traits<pointer_type> 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 <typename T> | | template <typename T> | |
| inline void database:: | | inline void database:: | |
| erase (T* p) | | erase (T* p) | |
| { | | { | |
| typedef typename object_traits<T>::pointer_type object_pointer; | | typedef typename object_traits<T>::pointer_type object_pointer; | |
| | | | |
| // The passed pointer should be the same or implicit-convertible | | // The passed pointer should be the same or implicit-convertible | |
| // to the object pointer. This way we make sure the object pointer | | // to the object pointer. This way we make sure the object pointer | |
| // does not assume ownership of the passed object. | | // does not assume ownership of the passed object. | |
| // | | // | |
| const object_pointer& pobj (p); | | const object_pointer& pobj (p); | |
| | | | |
|
| erase_<T> (pobj); | | erase_<T, id_common> (pobj); | |
| } | | } | |
| | | | |
| template <typename T, template <typename> class P> | | template <typename T, template <typename> class P> | |
| inline void database:: | | inline void database:: | |
| erase (const P<T>& p) | | erase (const P<T>& p) | |
| { | | { | |
| typedef typename object_traits<T>::pointer_type object_pointer; | | typedef typename object_traits<T>::pointer_type object_pointer; | |
| | | | |
| // The passed pointer should be the same or implicit-convertible | | // The passed pointer should be the same or implicit-convertible | |
| // to the object pointer. This way we make sure the object pointer | | // to the object pointer. This way we make sure the object pointer | |
| // does not assume ownership of the passed object. | | // does not assume ownership of the passed object. | |
| // | | // | |
| const object_pointer& pobj (p); | | const object_pointer& pobj (p); | |
| | | | |
|
| erase_<T> (pobj); | | erase_<T, id_common> (pobj); | |
| } | | } | |
| | | | |
| template <typename T, typename A1, template <typename, typename> class P> | | template <typename T, typename A1, template <typename, typename> class P> | |
| inline void database:: | | inline void database:: | |
| erase (const P<T, A1>& p) | | erase (const P<T, A1>& p) | |
| { | | { | |
| typedef typename object_traits<T>::pointer_type object_pointer; | | typedef typename object_traits<T>::pointer_type object_pointer; | |
| | | | |
| // The passed pointer should be the same or implicit-convertible | | // The passed pointer should be the same or implicit-convertible | |
| // to the object pointer. This way we make sure the object pointer | | // to the object pointer. This way we make sure the object pointer | |
| // does not assume ownership of the passed object. | | // does not assume ownership of the passed object. | |
| // | | // | |
| const object_pointer& pobj (p); | | const object_pointer& pobj (p); | |
| | | | |
|
| erase_<T> (pobj); | | erase_<T, id_common> (pobj); | |
| } | | } | |
| | | | |
| template <typename T, template <typename> class P> | | template <typename T, template <typename> class P> | |
| inline void database:: | | inline void database:: | |
| erase (P<T>& p) | | erase (P<T>& p) | |
| { | | { | |
| const P<T>& cr (p); | | const P<T>& cr (p); | |
| erase<T, P> (cr); | | erase<T, P> (cr); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 341 | | skipping to change at line 382 | |
| erase (P<T, A1>& p) | | erase (P<T, A1>& p) | |
| { | | { | |
| const P<T, A1>& cr (p); | | const P<T, A1>& cr (p); | |
| erase<T, A1, P> (cr); | | erase<T, A1, P> (cr); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline void database:: | | inline void database:: | |
| erase (const typename object_traits<T>::pointer_type& pobj) | | erase (const typename object_traits<T>::pointer_type& pobj) | |
| { | | { | |
|
| erase_<T> (pobj); | | erase_<T, id_common> (pobj); | |
| } | | | |
| | | | |
| template <typename T> | | | |
| inline void database:: | | | |
| erase_ (const typename object_traits<T>::pointer_type& pobj) | | | |
| { | | | |
| typedef typename object_traits<T>::pointer_type pointer_type; | | | |
| typedef pointer_traits<pointer_type> pointer_traits; | | | |
| | | | |
| erase<T> (pointer_traits::get_ref (pobj)); | | | |
| } | | | |
| | | | |
| template <typename T> | | | |
| inline void database:: | | | |
| erase (const typename object_traits<T>::id_type& id) | | | |
| { | | | |
| // T is always object_type. | | | |
| // | | | |
| object_traits<T>::erase (*this, id); | | | |
| } | | | |
| | | | |
| template <typename T> | | | |
| inline void database:: | | | |
| erase (T& obj) | | | |
| { | | | |
| // T can be const T while object_type will always be T. | | | |
| // | | | |
| typedef typename object_traits<T>::object_type object_type; | | | |
| | | | |
| object_traits<object_type>::erase (*this, obj); | | | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline unsigned long long database:: | | inline unsigned long long database:: | |
| erase_query () | | erase_query () | |
| { | | { | |
| // T is always object_type. | | // T is always object_type. | |
| // | | // | |
| return erase_query<T> (odb::query<T> ()); | | return erase_query<T> (odb::query<T> ()); | |
| } | | } | |
| | | | |
| skipping to change at line 407 | | skipping to change at line 418 | |
| // | | // | |
| return erase_query<T> (odb::query<T> (q)); | | return erase_query<T> (odb::query<T> (q)); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline unsigned long long database:: | | inline unsigned long long database:: | |
| erase_query (const odb::query<T>& q) | | erase_query (const odb::query<T>& q) | |
| { | | { | |
| // T is always object_type. | | // T is always object_type. | |
| // | | // | |
|
| return object_traits<T>::erase_query (*this, q); | | return object_traits_impl<T, id_common>::erase_query (*this, q); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline result<T> database:: | | inline result<T> database:: | |
| query (bool cache) | | query (bool cache) | |
| { | | { | |
| return query<T> (odb::query<T> (), cache); | | return query<T> (odb::query<T> (), cache); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| | | | |
| skipping to change at line 431 | | skipping to change at line 442 | |
| return query<T> (odb::query<T> (q), cache); | | return query<T> (odb::query<T> (q), cache); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline result<T> database:: | | inline result<T> database:: | |
| query (const std::string& q, bool cache) | | query (const std::string& q, bool cache) | |
| { | | { | |
| return query<T> (odb::query<T> (q), cache); | | return query<T> (odb::query<T> (q), cache); | |
| } | | } | |
| | | | |
|
| | | template <typename T> | |
| | | inline prepared_query<T> database:: | |
| | | prepare_query (const char* n, const char* q) | |
| | | { | |
| | | return prepare_query<T> (n, odb::query<T> (q)); | |
| | | } | |
| | | | |
| | | template <typename T> | |
| | | inline prepared_query<T> database:: | |
| | | prepare_query (const char* n, const std::string& q) | |
| | | { | |
| | | return prepare_query<T> (n, odb::query<T> (q)); | |
| | | } | |
| | | | |
| | | template <typename T> | |
| | | inline prepared_query<T> database:: | |
| | | prepare_query (const char* n, const odb::query<T>& q) | |
| | | { | |
| | | connection_type& c (transaction::current ().connection ()); | |
| | | return c.prepare_query (n, q); | |
| | | } | |
| | | | |
| | | template <typename T> | |
| | | inline void database:: | |
| | | cache_query (const prepared_query<T>& pq) | |
| | | { | |
| | | connection_type& c (transaction::current ().connection ()); | |
| | | c.cache_query (pq); | |
| | | } | |
| | | | |
| | | template <typename T, typename P> | |
| | | inline void database:: | |
| | | cache_query (const prepared_query<T>& pq, std::auto_ptr<P> params) | |
| | | { | |
| | | connection_type& c (transaction::current ().connection ()); | |
| | | c.cache_query (pq, params); | |
| | | } | |
| | | | |
| | | #ifdef ODB_CXX11 | |
| | | template <typename T, typename P> | |
| | | inline void database:: | |
| | | cache_query (const prepared_query<T>& pq, std::unique_ptr<P> params) | |
| | | { | |
| | | connection_type& c (transaction::current ().connection ()); | |
| | | c.cache_query (pq, std::move (params)); | |
| | | } | |
| | | #endif | |
| | | | |
| | | template <typename T> | |
| | | inline prepared_query<T> database:: | |
| | | lookup_query (const char* name) const | |
| | | { | |
| | | connection_type& c (transaction::current ().connection ()); | |
| | | return c.lookup_query<T> (name); | |
| | | } | |
| | | | |
| | | template <typename T, typename P> | |
| | | inline prepared_query<T> database:: | |
| | | lookup_query (const char* name, P*& params) const | |
| | | { | |
| | | connection_type& c (transaction::current ().connection ()); | |
| | | return c.lookup_query<T, P> (name, params); | |
| | | } | |
| | | | |
| | | // Implementations (i.e., the *_() functions). | |
| | | // | |
| | | template <typename T, database_id DB> | |
| | | inline typename object_traits<T>::pointer_type database:: | |
| | | find_ (const typename object_traits<T>::id_type& id) | |
| | | { | |
| | | // T is always object_type. | |
| | | // | |
| | | | |
| | | // Compiler error pointing here? Perhaps the object doesn't have the | |
| | | // default constructor? | |
| | | // | |
| | | return object_traits_impl<T, DB>::find (*this, id); | |
| | | } | |
| | | | |
| | | template <typename T, database_id DB> | |
| | | inline bool database:: | |
| | | find_ (const typename object_traits<T>::id_type& id, T& obj) | |
| | | { | |
| | | // T is always object_type. | |
| | | // | |
| | | return object_traits_impl<T, DB>::find (*this, id, obj); | |
| | | } | |
| | | | |
| | | template <typename T, database_id DB> | |
| | | inline void database:: | |
| | | update_ (T& obj) | |
| | | { | |
| | | // T can be const T while object_type will always be T. | |
| | | // | |
| | | typedef typename object_traits<T>::object_type object_type; | |
| | | | |
| | | // Compiler error pointing here? Perhaps the object is readonly or | |
| | | // doesn't have an object id? Such objects cannot be updated. | |
| | | // | |
| | | object_traits_impl<object_type, DB>::update (*this, obj); | |
| | | } | |
| | | | |
| | | template <typename T, database_id DB> | |
| | | inline void database:: | |
| | | update_ (const typename object_traits<T>::pointer_type& pobj) | |
| | | { | |
| | | // T can be const T while object_type will always be T. | |
| | | // | |
| | | typedef typename object_traits<T>::object_type object_type; | |
| | | typedef typename object_traits<T>::pointer_type pointer_type; | |
| | | | |
| | | T& obj (pointer_traits<pointer_type>::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_impl<object_type, DB>::update (*this, obj); | |
| | | } | |
| | | | |
| | | template <typename T, database_id DB> | |
| | | inline void database:: | |
| | | erase_ (const typename object_traits<T>::id_type& id) | |
| | | { | |
| | | // T is always object_type. | |
| | | // | |
| | | object_traits_impl<T, DB>::erase (*this, id); | |
| | | } | |
| | | | |
| | | template <typename T, database_id DB> | |
| | | inline void database:: | |
| | | erase_ (T& obj) | |
| | | { | |
| | | // T can be const T while object_type will always be T. | |
| | | // | |
| | | typedef typename object_traits<T>::object_type object_type; | |
| | | | |
| | | object_traits_impl<object_type, DB>::erase (*this, obj); | |
| | | } | |
| | | | |
| | | template <typename T, database_id DB> | |
| | | inline void database:: | |
| | | erase_ (const typename object_traits<T>::pointer_type& pobj) | |
| | | { | |
| | | typedef typename object_traits<T>::pointer_type pointer_type; | |
| | | | |
| | | erase_<T, DB> (pointer_traits<pointer_type>::get_ref (pobj)); | |
| | | } | |
| | | | |
| | | // execute() | |
| | | // | |
| inline unsigned long long database:: | | inline unsigned long long database:: | |
| execute (const char* statement) | | execute (const char* statement) | |
| { | | { | |
| return execute (statement, std::strlen (statement)); | | return execute (statement, std::strlen (statement)); | |
| } | | } | |
| | | | |
| inline unsigned long long database:: | | inline unsigned long long database:: | |
| execute (const std::string& statement) | | execute (const std::string& statement) | |
| { | | { | |
| return execute (statement.c_str (), statement.size ()); | | return execute (statement.c_str (), statement.size ()); | |
| | | | |
End of changes. 29 change blocks. |
| 81 lines changed or deleted | | 242 lines changed or added | |
|
| database.txx | | database.txx | |
| // file : odb/database.txx | | // file : odb/database.txx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #include <odb/exceptions.hxx> | | #include <odb/exceptions.hxx> | |
|
| #include <odb/transaction.hxx> | | | |
| #include <odb/no-op-cache-traits.hxx> | | #include <odb/no-op-cache-traits.hxx> | |
| #include <odb/pointer-traits.hxx> | | #include <odb/pointer-traits.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| template <typename T> | | template <typename T> | |
|
| | | result<T> database:: | |
| | | query (const odb::query<T>& q, bool cache) | |
| | | { | |
| | | // T is always object_type. We also don't need to check for transaction | |
| | | // here; object_traits::query () does this. | |
| | | // | |
| | | result<T> r (query_<T, id_common>::call (*this, q)); | |
| | | | |
| | | if (cache) | |
| | | r.cache (); | |
| | | | |
| | | return r; | |
| | | } | |
| | | | |
| | | // Implementations (i.e., the *_() functions). | |
| | | // | |
| | | template <typename T, database_id DB> | |
| typename object_traits<T>::id_type database:: | | typename object_traits<T>::id_type database:: | |
|
| persist (T& obj) | | persist_ (T& obj) | |
| { | | { | |
| // T can be const T while object_type will always be T. | | // T can be const T while object_type will always be T. | |
| // | | // | |
|
| typedef typename odb::object_traits<T>::object_type object_type; | | typedef typename object_traits<T>::object_type object_type; | |
| typedef odb::object_traits<object_type> object_traits; | | typedef object_traits_impl<object_type, DB> object_traits; | |
| | | | |
| object_traits::persist (*this, obj); | | object_traits::persist (*this, obj); | |
| | | | |
|
| object_traits::reference_cache_traits::insert ( | | typename object_traits::reference_cache_traits::position_type p ( | |
| *this, reference_cache_type<T>::convert (obj)); | | object_traits::reference_cache_traits::insert ( | |
| | | *this, reference_cache_type<T>::convert (obj))); | |
| | | | |
| | | object_traits::reference_cache_traits::persist (p); | |
| | | | |
| return object_traits::id (obj); | | return object_traits::id (obj); | |
| } | | } | |
| | | | |
|
| template <typename T> | | template <typename T, database_id DB> | |
| typename object_traits<T>::id_type database:: | | typename object_traits<T>::id_type database:: | |
| persist_ (const typename object_traits<T>::pointer_type& pobj) | | persist_ (const typename object_traits<T>::pointer_type& pobj) | |
| { | | { | |
| // T can be const T while object_type will always be T. | | // T can be const T while object_type will always be T. | |
| // | | // | |
|
| typedef typename odb::object_traits<T>::object_type object_type; | | typedef typename object_traits<T>::object_type object_type; | |
| typedef odb::object_traits<object_type> object_traits; | | typedef typename object_traits<T>::pointer_type pointer_type; | |
| | | | |
|
| typedef typename odb::object_traits<T>::pointer_type pointer_type; | | typedef object_traits_impl<object_type, DB> object_traits; | |
| typedef odb::pointer_traits<pointer_type> pointer_traits; | | | |
| | | | |
|
| T& obj (pointer_traits::get_ref (pobj)); | | T& obj (pointer_traits<pointer_type>::get_ref (pobj)); | |
| object_traits::persist (*this, obj); | | object_traits::persist (*this, obj); | |
| | | | |
| // Get the canonical object pointer and insert it into object cache. | | // Get the canonical object pointer and insert it into object cache. | |
| // | | // | |
|
| object_traits::pointer_cache_traits::insert ( | | typename object_traits::pointer_cache_traits::position_type p ( | |
| *this, pointer_cache_type<pointer_type>::convert (pobj)); | | object_traits::pointer_cache_traits::insert ( | |
| | | *this, pointer_cache_type<pointer_type>::convert (pobj))); | |
| | | | |
| | | object_traits::pointer_cache_traits::persist (p); | |
| | | | |
| return object_traits::id (obj); | | return object_traits::id (obj); | |
| } | | } | |
| | | | |
|
| template <typename T> | | template <typename T, database_id DB> | |
| typename object_traits<T>::pointer_type database:: | | typename object_traits<T>::pointer_type database:: | |
|
| load (const typename object_traits<T>::id_type& id) | | load_ (const typename object_traits<T>::id_type& id) | |
| { | | { | |
| // T is always object_type. | | // T is always object_type. | |
| // | | // | |
| typedef typename object_traits<T>::pointer_type pointer_type; | | typedef typename object_traits<T>::pointer_type pointer_type; | |
|
| typedef odb::pointer_traits<pointer_type> pointer_traits; | | | |
| | | | |
|
| pointer_type r (find<T> (id)); | | pointer_type r (find_<T, DB> (id)); | |
| | | | |
|
| if (pointer_traits::null_ptr (r)) | | if (pointer_traits<pointer_type>::null_ptr (r)) | |
| throw object_not_persistent (); | | throw object_not_persistent (); | |
| | | | |
| return r; | | return r; | |
| } | | } | |
| | | | |
|
| template <typename T> | | template <typename T, database_id DB> | |
| void database:: | | void database:: | |
|
| load (const typename object_traits<T>::id_type& id, T& obj) | | load_ (const typename object_traits<T>::id_type& id, T& obj) | |
| { | | { | |
|
| if (!find<T> (id, obj)) | | if (!find_<T, DB> (id, obj)) | |
| throw object_not_persistent (); | | throw object_not_persistent (); | |
| } | | } | |
| | | | |
|
| template <typename T> | | template <typename T, database_id DB> | |
| void database:: | | void database:: | |
|
| reload (T& obj) | | reload_ (T& obj) | |
| { | | { | |
|
| // T should be object_type (cannot be const). | | // T should be object_type (cannot be const). We also don't need to | |
| | | // check for transaction here; object_traits::reload () does this. | |
| // | | // | |
|
| typedef odb::object_traits<T> object_traits; | | if (!object_traits_impl<T, DB>::reload (*this, obj)) | |
| | | | |
| // We don't need to check for transaction here; | | | |
| // object_traits::reload () does this. | | | |
| | | | |
| if (!object_traits::reload (*this, obj)) | | | |
| throw object_not_persistent (); | | throw object_not_persistent (); | |
| } | | } | |
| | | | |
|
| template <typename T> | | template <typename T, database_id DB> | |
| struct database::query_<T, class_object> | | struct database::query_<T, DB, class_object> | |
| { | | { | |
|
| | | template <typename Q> | |
| static result<T> | | static result<T> | |
|
| call (database& db, const odb::query<T>& q) | | call (database& db, const Q& q) | |
| { | | { | |
|
| return object_traits<T>::query (db, q); | | return object_traits_impl<T, DB>::query (db, q); | |
| } | | } | |
| }; | | }; | |
| | | | |
|
| template <typename T> | | template <typename T, database_id DB> | |
| struct database::query_<T, class_view> | | struct database::query_<T, DB, class_view> | |
| { | | { | |
|
| | | template <typename Q> | |
| static result<T> | | static result<T> | |
|
| call (database& db, const odb::query<T>& q) | | call (database& db, const Q& q) | |
| { | | { | |
|
| return view_traits<T>::query (db, q); | | return view_traits_impl<T, DB>::query (db, q); | |
| } | | } | |
| }; | | }; | |
|
| | | | |
| template <typename T> | | | |
| result<T> database:: | | | |
| query (const odb::query<T>& q, bool cache) | | | |
| { | | | |
| // T is always object_type. | | | |
| // | | | |
| | | | |
| // We don't need to check for transaction here; | | | |
| // object_traits::query () does this. | | | |
| | | | |
| result<T> r (query_<T, class_traits<T>::kind>::call (*this, q)); | | | |
| | | | |
| if (cache) | | | |
| r.cache (); | | | |
| | | | |
| return r; | | | |
| } | | | |
| } | | } | |
| | | | |
End of changes. 32 change blocks. |
| 58 lines changed or deleted | | 58 lines changed or added | |
|
| lazy-ptr-impl.ixx | | lazy-ptr-impl.ixx | |
| // file : odb/lazy-ptr-impl.ixx | | // file : odb/lazy-ptr-impl.ixx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| // | | // | |
| // lazy_ptr_base | | // lazy_ptr_base | |
| // | | // | |
| | | | |
| inline lazy_ptr_base:: | | inline lazy_ptr_base:: | |
| lazy_ptr_base () | | lazy_ptr_base () | |
|
| : id_ (0), db_ (0) | | : id_ (0), db_ (0), loader_ (0) | |
| { | | { | |
| } | | } | |
| | | | |
| inline lazy_ptr_base:: | | inline lazy_ptr_base:: | |
| lazy_ptr_base (const lazy_ptr_base& r) | | lazy_ptr_base (const lazy_ptr_base& r) | |
|
| : id_ (0), db_ (r.db_), free_ (r.free_), copy_ (r.copy_) | | : id_ (0), db_ (r.db_), loader_ (r.loader_), | |
| | | free_ (r.free_), copy_ (r.copy_) | |
| { | | { | |
| if (r.id_) | | if (r.id_) | |
| id_ = copy_ (r.id_); | | id_ = copy_ (r.id_); | |
| } | | } | |
| | | | |
| inline lazy_ptr_base:: | | inline lazy_ptr_base:: | |
| lazy_ptr_base (const lazy_ptr_impl_ref& r) | | lazy_ptr_base (const lazy_ptr_impl_ref& r) | |
|
| : id_ (r.id_), db_ (r.db_), free_ (r.free_), copy_ (r.copy_) | | : id_ (r.id_), db_ (r.db_), loader_ (r.loader_), | |
| | | free_ (r.free_), copy_ (r.copy_) | |
| { | | { | |
| } | | } | |
| | | | |
| #ifdef ODB_CXX11 | | #ifdef ODB_CXX11 | |
| inline lazy_ptr_base:: | | inline lazy_ptr_base:: | |
| lazy_ptr_base (lazy_ptr_base&& r) | | lazy_ptr_base (lazy_ptr_base&& r) | |
|
| : id_ (r.id_), db_ (r.db_), free_ (r.free_), copy_ (r.copy_) | | : id_ (r.id_), db_ (r.db_), loader_ (r.loader_), | |
| | | free_ (r.free_), copy_ (r.copy_) | |
| { | | { | |
| r.id_ = 0; | | r.id_ = 0; | |
| } | | } | |
| | | | |
| inline lazy_ptr_base& lazy_ptr_base:: | | inline lazy_ptr_base& lazy_ptr_base:: | |
| operator= (lazy_ptr_base&& r) | | operator= (lazy_ptr_base&& r) | |
| { | | { | |
| if (id_ != r.id_) | | if (id_ != r.id_) | |
| { | | { | |
| reset_id (); | | reset_id (); | |
| id_ = r.id_; | | id_ = r.id_; | |
| db_ = r.db_; | | db_ = r.db_; | |
|
| | | loader_ = r.loader_; | |
| free_ = r.free_; | | free_ = r.free_; | |
| copy_ = r.copy_; | | copy_ = r.copy_; | |
| | | | |
| r.id_ = 0; | | r.id_ = 0; | |
| } | | } | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| #endif | | #endif | |
| | | | |
| inline void lazy_ptr_base:: | | inline void lazy_ptr_base:: | |
|
| reset_id () | | reset_ (database_type* db, | |
| { | | void* loader, | |
| if (id_) | | const void* id, | |
| free_ (id_); | | free_func free, | |
| | | copy_func copy) | |
| id_ = 0; | | | |
| } | | | |
| | | | |
| inline void lazy_ptr_base:: | | | |
| reset_ (database_type* db, const void* id, free_func free, copy_func copy | | | |
| ) | | | |
| { | | { | |
| void* idc (id ? copy (id) : 0); | | void* idc (id ? copy (id) : 0); | |
| | | | |
| if (id_) | | if (id_) | |
| free_ (id_); | | free_ (id_); | |
| | | | |
| free_ = free; | | free_ = free; | |
| copy_ = copy; | | copy_ = copy; | |
| | | | |
| id_ = idc; | | id_ = idc; | |
| db_ = db; | | db_ = db; | |
|
| | | loader_ = loader; | |
| } | | } | |
| | | | |
| inline void lazy_ptr_base:: | | inline void lazy_ptr_base:: | |
| reset () | | reset () | |
| { | | { | |
| reset_id (); | | reset_id (); | |
| db_ = 0; | | db_ = 0; | |
|
| | | loader_ = 0; | |
| } | | } | |
| | | | |
| inline void lazy_ptr_base:: | | inline void lazy_ptr_base:: | |
|
| reset (database_type& db) | | reset_id () | |
| { | | { | |
|
| reset_id (); | | if (id_) | |
| db_ = &db; | | free_ (id_); | |
| | | | |
| | | id_ = 0; | |
| } | | } | |
| | | | |
| inline lazy_ptr_base& lazy_ptr_base:: | | inline lazy_ptr_base& lazy_ptr_base:: | |
| operator= (const lazy_ptr_base& r) | | operator= (const lazy_ptr_base& r) | |
| { | | { | |
| if (id_ != r.id_) | | if (id_ != r.id_) | |
|
| reset_ (r.db_, r.id_, r.free_, r.copy_); | | reset_ (r.db_, r.loader_, r.id_, r.free_, r.copy_); | |
| else | | else | |
|
| | | { | |
| db_ = r.db_; | | db_ = r.db_; | |
|
| | | loader_ = r.loader_; | |
| | | } | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| inline lazy_ptr_base& lazy_ptr_base:: | | inline lazy_ptr_base& lazy_ptr_base:: | |
| operator= (const lazy_ptr_impl_ref& r) | | operator= (const lazy_ptr_impl_ref& r) | |
| { | | { | |
| if (id_ != r.id_) | | if (id_ != r.id_) | |
| { | | { | |
| reset_id (); | | reset_id (); | |
| id_ = r.id_; | | id_ = r.id_; | |
| free_ = r.free_; | | free_ = r.free_; | |
| copy_ = r.copy_; | | copy_ = r.copy_; | |
| } | | } | |
| | | | |
| db_ = r.db_; | | db_ = r.db_; | |
|
| | | loader_ = r.loader_; | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| inline lazy_ptr_base:: | | inline lazy_ptr_base:: | |
| ~lazy_ptr_base () | | ~lazy_ptr_base () | |
| { | | { | |
| if (id_) | | if (id_) | |
| free_ (id_); | | free_ (id_); | |
| } | | } | |
| | | | |
| inline void lazy_ptr_base:: | | inline void lazy_ptr_base:: | |
| swap (lazy_ptr_base& r) | | swap (lazy_ptr_base& r) | |
| { | | { | |
| void* id (id_); | | void* id (id_); | |
| database_type* db (db_); | | database_type* db (db_); | |
|
| | | void* l (loader_); | |
| free_func f (free_); | | free_func f (free_); | |
| copy_func c (copy_); | | copy_func c (copy_); | |
| | | | |
| id_ = r.id_; | | id_ = r.id_; | |
| db_ = r.db_; | | db_ = r.db_; | |
|
| | | loader_ = r.loader_; | |
| free_ = r.free_; | | free_ = r.free_; | |
| copy_ = r.copy_; | | copy_ = r.copy_; | |
| | | | |
| r.id_ = id; | | r.id_ = id; | |
| r.db_ = db; | | r.db_ = db; | |
|
| | | r.loader_ = l; | |
| r.free_ = f; | | r.free_ = f; | |
| r.copy_ = c; | | r.copy_ = c; | |
| } | | } | |
| | | | |
| inline lazy_ptr_base::database_type* lazy_ptr_base:: | | inline lazy_ptr_base::database_type* lazy_ptr_base:: | |
| database () const | | database () const | |
| { | | { | |
| return db_; | | return db_; | |
| } | | } | |
| | | | |
| inline lazy_ptr_base:: | | inline lazy_ptr_base:: | |
| operator lazy_ptr_impl_ref () | | operator lazy_ptr_impl_ref () | |
| { | | { | |
| lazy_ptr_impl_ref r; | | lazy_ptr_impl_ref r; | |
| r.id_ = id_; | | r.id_ = id_; | |
| r.db_ = db_; | | r.db_ = db_; | |
|
| | | r.loader_ = loader_; | |
| r.free_ = free_; | | r.free_ = free_; | |
| r.copy_ = copy_; | | r.copy_ = copy_; | |
| id_ = 0; | | id_ = 0; | |
| db_ = 0; | | db_ = 0; | |
|
| | | loader_ = 0; | |
| return r; | | return r; | |
| } | | } | |
| | | | |
| // | | // | |
| // lazy_ptr_impl | | // lazy_ptr_impl | |
| // | | // | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline lazy_ptr_impl<T>:: | | inline lazy_ptr_impl<T>:: | |
| lazy_ptr_impl () | | lazy_ptr_impl () | |
| { | | { | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
|
| template <typename ID> | | template <typename DB, typename ID> | |
| inline lazy_ptr_impl<T>:: | | inline lazy_ptr_impl<T>:: | |
|
| lazy_ptr_impl (database_type& db, const ID& id) | | lazy_ptr_impl (DB& db, const ID& id) | |
| { | | { | |
| typedef typename object_traits<T>::id_type id_type; | | typedef typename object_traits<T>::id_type id_type; | |
|
| | | typedef typename object_traits<T>::pointer_type pointer_type; | |
| | | typedef pointer_type (*loader_type) (database_type&, const id_type&); | |
| | | | |
| // Make sure that ID and T's object id types are the same | | // Make sure that ID and T's object id types are the same | |
| // (or implicit-convertible). If you get a compile error | | // (or implicit-convertible). If you get a compile error | |
| // pointing here, then you most likely used a wrong object | | // pointing here, then you most likely used a wrong object | |
| // id argument in the constructor call. | | // id argument in the constructor call. | |
| // | | // | |
| const id_type& r (id); | | const id_type& r (id); | |
| | | | |
|
| reset_ (&db, &r, &free<id_type>, ©<id_type>); | | // Compiler error pointing here? Perhaps db is not an | |
| | | // odb::<database>::database instance? | |
| | | // | |
| | | database_type& bdb (db); | |
| | | | |
| | | // For some reason GCC needs this statically-typed pointer in | |
| | | // order to instantiate the functions. | |
| | | // | |
| | | loader_type ldr (&loader<T, DB>); | |
| | | | |
| | | reset_ (&bdb, | |
| | | reinterpret_cast<void*> (ldr), | |
| | | &r, | |
| | | &free<id_type>, | |
| | | ©<id_type>); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline lazy_ptr_impl<T>:: | | inline lazy_ptr_impl<T>:: | |
| lazy_ptr_impl (const lazy_ptr_impl& r) | | lazy_ptr_impl (const lazy_ptr_impl& r) | |
| : lazy_ptr_base (r) | | : lazy_ptr_base (r) | |
| { | | { | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| | | | |
| skipping to change at line 280 | | skipping to change at line 308 | |
| inline lazy_ptr_impl<T>& lazy_ptr_impl<T>:: | | inline lazy_ptr_impl<T>& lazy_ptr_impl<T>:: | |
| operator= (lazy_ptr_impl<Y>&& r) | | operator= (lazy_ptr_impl<Y>&& r) | |
| { | | { | |
| lazy_ptr_base& b (*this); | | lazy_ptr_base& b (*this); | |
| b = std::move (r); | | b = std::move (r); | |
| return *this; | | return *this; | |
| } | | } | |
| #endif | | #endif | |
| | | | |
| template <typename T> | | template <typename T> | |
|
| template <typename ID> | | template <typename DB, typename ID> | |
| inline void lazy_ptr_impl<T>:: | | inline void lazy_ptr_impl<T>:: | |
|
| reset (database_type& db, const ID& id) | | reset (DB& db, const ID& id) | |
| { | | { | |
| typedef typename object_traits<T>::id_type id_type; | | typedef typename object_traits<T>::id_type id_type; | |
|
| | | typedef typename object_traits<T>::pointer_type pointer_type; | |
| | | typedef pointer_type (*loader_type) (database_type&, const id_type&); | |
| | | | |
| // Make sure that ID and T's object id types are the same | | // Make sure that ID and T's object id types are the same | |
| // (or implicit-convertible). If you get a compile error | | // (or implicit-convertible). If you get a compile error | |
| // pointing here, then you most likely used a wrong object | | // pointing here, then you most likely used a wrong object | |
| // id argument in the constructor call. | | // id argument in the constructor call. | |
| // | | // | |
| const id_type& r (id); | | const id_type& r (id); | |
| | | | |
|
| reset_ (&db, &r, &free<id_type>, ©<id_type>); | | // Compiler error pointing here? Perhaps db is not an | |
| | | // odb::<database>::database instance? | |
| | | // | |
| | | database_type& bdb (db); | |
| | | | |
| | | // For some reason GCC needs this statically-typed pointer in | |
| | | // order to instantiate the functions. | |
| | | // | |
| | | loader_type ldr (&loader<T, DB>); | |
| | | | |
| | | reset_ (&bdb, | |
| | | reinterpret_cast<void*> (ldr), | |
| | | &r, | |
| | | &free<id_type>, | |
| | | ©<id_type>); | |
| | | } | |
| | | | |
| | | template <typename T> | |
| | | template <typename DB> | |
| | | inline void lazy_ptr_impl<T>:: | |
| | | reset_db (DB& db) | |
| | | { | |
| | | typedef typename object_traits<T>::id_type id_type; | |
| | | typedef typename object_traits<T>::pointer_type pointer_type; | |
| | | typedef pointer_type (*loader_type) (database_type&, const id_type&); | |
| | | | |
| | | reset_id (); | |
| | | | |
| | | // Compiler error pointing here? Perhaps db is not an | |
| | | // odb::<database>::database instance? | |
| | | // | |
| | | db_ = &db; | |
| | | | |
| | | // For some reason GCC needs this statically-typed pointer in | |
| | | // order to instantiate the functions. | |
| | | // | |
| | | loader_type ldr (&loader<T, DB>); | |
| | | loader_ = reinterpret_cast<void*> (ldr); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| template <typename ID> | | template <typename ID> | |
| inline void lazy_ptr_impl<T>:: | | inline void lazy_ptr_impl<T>:: | |
| reset_id (const ID& id) | | reset_id (const ID& id) | |
| { | | { | |
| typedef typename object_traits<T>::id_type id_type; | | typedef typename object_traits<T>::id_type id_type; | |
| | | | |
| // Make sure that ID and T's object id types are the same | | // Make sure that ID and T's object id types are the same | |
| // (or implicit-convertible). If you get a compile error | | // (or implicit-convertible). If you get a compile error | |
| // pointing here, then you most likely used a wrong object | | // pointing here, then you most likely used a wrong object | |
| // id argument in the constructor call. | | // id argument in the constructor call. | |
| // | | // | |
| const id_type& r (id); | | const id_type& r (id); | |
| | | | |
|
| reset_ (db_, &r, &free<id_type>, ©<id_type>); | | reset_ (db_, loader_, &r, &free<id_type>, ©<id_type>); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| template <typename O> | | template <typename O> | |
| inline typename object_traits<O>::id_type lazy_ptr_impl<T>:: | | inline typename object_traits<O>::id_type lazy_ptr_impl<T>:: | |
| object_id () const | | object_id () const | |
| { | | { | |
| typedef typename object_traits<T>::id_type id_type; | | typedef typename object_traits<T>::id_type id_type; | |
| const id_type& id (*static_cast<const id_type*> (id_)); | | const id_type& id (*static_cast<const id_type*> (id_)); | |
| | | | |
| | | | |
End of changes. 29 change blocks. |
| 27 lines changed or deleted | | 93 lines changed or added | |
|
| lazy-ptr.hxx | | lazy-ptr.hxx | |
| // file : odb/lazy-ptr.hxx | | // file : odb/lazy-ptr.hxx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_LAZY_PTR_HXX | | #ifndef ODB_LAZY_PTR_HXX | |
| #define ODB_LAZY_PTR_HXX | | #define ODB_LAZY_PTR_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
| #include <memory> // std::auto_ptr, std::shared_ptr/weak_ptr | | #include <memory> // std::auto_ptr, std::shared_ptr/weak_ptr | |
| #include <utility> // std::move | | #include <utility> // std::move | |
| | | | |
|
| #include <odb/forward.hxx> // odb::database | | #include <odb/forward.hxx> // odb::core, odb::database | |
| #include <odb/traits.hxx> | | #include <odb/traits.hxx> | |
| #include <odb/lazy-ptr-impl.hxx> | | #include <odb/lazy-ptr-impl.hxx> | |
| #include <odb/details/config.hxx> // ODB_CXX11 | | #include <odb/details/config.hxx> // ODB_CXX11 | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| // Raw pointer lazy version. | | // Raw pointer lazy version. | |
| // | | // | |
| template <class T> | | template <class T> | |
| class lazy_ptr | | class lazy_ptr | |
| | | | |
| skipping to change at line 75 | | skipping to change at line 75 | |
| // | | // | |
| bool loaded () const; | | bool loaded () const; | |
| | | | |
| T* load () const; | | T* load () const; | |
| | | | |
| // Unload the pointer. For transient objects this function is | | // Unload the pointer. For transient objects this function is | |
| // equivalent to reset(). | | // equivalent to reset(). | |
| // | | // | |
| void unload () const; | | void unload () const; | |
| | | | |
|
| template <class ID> lazy_ptr (database_type&, const ID&); | | template <class DB, class ID> lazy_ptr (DB&, const ID&); | |
| template <class Y> lazy_ptr (database_type&, Y*); | | template <class DB, class Y> lazy_ptr (DB&, Y*); | |
| | | | |
|
| template <class ID> void reset (database_type&, const ID&); | | template <class DB, class ID> void reset (DB&, const ID&); | |
| template <class Y> void reset (database_type&, Y*); | | template <class DB, class Y> void reset (DB&, Y*); | |
| | | | |
| #ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT | | #ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT | |
| template <class O = T> | | template <class O = T> | |
| #else | | #else | |
| template <class O /* = T */> | | template <class O /* = T */> | |
| #endif | | #endif | |
| typename object_traits<O>::id_type object_id () const; | | typename object_traits<O>::id_type object_id () const; | |
| | | | |
| database_type& database () const; | | database_type& database () const; | |
| | | | |
| | | | |
| skipping to change at line 188 | | skipping to change at line 188 | |
| // | | // | |
| bool loaded () const; | | bool loaded () const; | |
| | | | |
| std::auto_ptr<T>& load () const; | | std::auto_ptr<T>& load () const; | |
| | | | |
| // Unload the pointer. For transient objects this function is | | // Unload the pointer. For transient objects this function is | |
| // equivalent to reset(). | | // equivalent to reset(). | |
| // | | // | |
| void unload () const; | | void unload () const; | |
| | | | |
|
| template <class ID> lazy_auto_ptr (database_type&, const ID&); | | template <class DB, class ID> lazy_auto_ptr (DB&, const ID&); | |
| lazy_auto_ptr (database_type&, T*); | | template <class DB> lazy_auto_ptr (DB&, T*); | |
| template <class Y> lazy_auto_ptr (database_type&, std::auto_ptr<Y>&); | | template <class DB, class Y> lazy_auto_ptr (DB&, std::auto_ptr<Y>&); | |
| | | | |
| template <class ID> void reset (database_type&, const ID&); | | template <class DB, class ID> void reset (DB&, const ID&); | |
| void reset (database_type&, T*); | | template <class DB> void reset (DB&, T*); | |
| template <class Y> void reset (database_type&, std::auto_ptr<Y>&); | | template <class DB, class Y> void reset (DB&, std::auto_ptr<Y>&); | |
| | | | |
| #ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT | | #ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT | |
| template <class O = T> | | template <class O = T> | |
| #else | | #else | |
| template <class O /* = T */> | | template <class O /* = T */> | |
| #endif | | #endif | |
| typename object_traits<O>::id_type object_id () const; | | typename object_traits<O>::id_type object_id () const; | |
| | | | |
| database_type& database () const; | | database_type& database () const; | |
| | | | |
| | | | |
| skipping to change at line 308 | | skipping to change at line 308 | |
| // | | // | |
| bool loaded () const; | | bool loaded () const; | |
| | | | |
| std::unique_ptr<T, D>& load () const; | | std::unique_ptr<T, D>& load () const; | |
| | | | |
| // Unload the pointer. For transient objects this function is | | // Unload the pointer. For transient objects this function is | |
| // equivalent to reset(). | | // equivalent to reset(). | |
| // | | // | |
| void unload () const; | | void unload () const; | |
| | | | |
|
| template <class ID> lazy_unique_ptr (database_type&, const ID&); | | template <class DB, class ID> lazy_unique_ptr (DB&, const ID&); | |
| lazy_unique_ptr (database_type&, pointer); | | template <class DB> lazy_unique_ptr (DB&, pointer); | |
| lazy_unique_ptr (database_type&, pointer, const deleter_type&); | | template <class DB> lazy_unique_ptr (DB&, pointer, const deleter_type&) | |
| lazy_unique_ptr (database_type&, pointer, deleter_type&&); | | ; | |
| template <class T1, class D1> lazy_unique_ptr (database_type&, std::uni | | template <class DB> lazy_unique_ptr (DB&, pointer, deleter_type&&); | |
| que_ptr<T1, D1>&&); | | template <class DB, class T1, class D1> lazy_unique_ptr (DB&, std::uniq | |
| template <class T1> lazy_unique_ptr (database_type&, std::auto_ptr<T1>& | | ue_ptr<T1, D1>&&); | |
| &); | | template <class DB, class T1> lazy_unique_ptr (DB&, std::auto_ptr<T1>&& | |
| | | ); | |
| template <class ID> void reset (database_type&, const ID&); | | | |
| void reset (database_type&, pointer); | | template <class DB, class ID> void reset (DB&, const ID&); | |
| template <class T1, class D1> void reset (database_type&, std::unique_p | | template <class DB> void reset (DB&, pointer); | |
| tr<T1, D1>&&); | | template <class DB, class T1, class D1> void reset (DB&, std::unique_pt | |
| template <class T1> void reset (database_type&, std::auto_ptr<T1>&&); | | r<T1, D1>&&); | |
| | | template <class DB, class T1> void reset (DB&, std::auto_ptr<T1>&&); | |
| | | | |
| #ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT | | #ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT | |
| template <class O = T> | | template <class O = T> | |
| #else | | #else | |
| template <class O /*= T*/> | | template <class O /*= T*/> | |
| #endif | | #endif | |
| typename object_traits<O>::id_type object_id () const; | | typename object_traits<O>::id_type object_id () const; | |
| | | | |
| database_type& database () const; | | database_type& database () const; | |
| | | | |
| | | | |
| skipping to change at line 467 | | skipping to change at line 467 | |
| // | | // | |
| bool loaded () const; | | bool loaded () const; | |
| | | | |
| std::shared_ptr<T> load () const; | | std::shared_ptr<T> load () const; | |
| | | | |
| // Unload the pointer. For transient objects this function is | | // Unload the pointer. For transient objects this function is | |
| // equivalent to reset(). | | // equivalent to reset(). | |
| // | | // | |
| void unload () const; | | void unload () const; | |
| | | | |
|
| template <class ID> lazy_shared_ptr (database_type&, const ID&); | | template <class DB, class ID> lazy_shared_ptr (DB&, const ID&); | |
| template <class Y> lazy_shared_ptr (database_type&, Y*); | | template <class DB, class Y> lazy_shared_ptr (DB&, Y*); | |
| template <class Y, class D> lazy_shared_ptr (database_type&, Y*, D); | | template <class DB, class Y, class D> lazy_shared_ptr (DB&, Y*, D); | |
| template <class Y, class D, class A> lazy_shared_ptr (database_type&, Y | | template <class DB, class Y, class D, class A> lazy_shared_ptr (DB&, Y* | |
| *, D, A); | | , D, A); | |
| template <class Y> lazy_shared_ptr (database_type&, std::auto_ptr<Y>&&) | | template <class DB, class Y> lazy_shared_ptr (DB&, std::auto_ptr<Y>&&); | |
| ; | | template <class DB, class Y> lazy_shared_ptr (DB&, const std::shared_pt | |
| template <class Y> lazy_shared_ptr (database_type&, const std::shared_p | | r<Y>&); | |
| tr<Y>&); | | template <class DB, class Y> lazy_shared_ptr (DB&, std::shared_ptr<Y>&& | |
| template <class Y> lazy_shared_ptr (database_type&, std::shared_ptr<Y>& | | ); | |
| &); | | template <class DB, class Y> lazy_shared_ptr (DB&, const std::weak_ptr< | |
| template <class Y> lazy_shared_ptr (database_type&, const std::weak_ptr | | Y>&); | |
| <Y>&); | | | |
| | | template <class DB, class ID> void reset (DB&, const ID&); | |
| template <class ID> void reset (database_type&, const ID&); | | template <class DB, class Y> void reset (DB&, Y*); | |
| template <class Y> void reset (database_type&, Y*); | | template <class DB, class Y, class D> void reset (DB&, Y*, D); | |
| template <class Y, class D> void reset (database_type&, Y*, D); | | template <class DB, class Y, class D, class A> void reset (DB&, Y*, D, | |
| template <class Y, class D, class A> void reset (database_type&, Y*, D, | | A); | |
| A); | | template <class DB, class Y> void reset (DB&, std::auto_ptr<Y>&&); | |
| template <class Y> void reset (database_type&, std::auto_ptr<Y>&&); | | template <class DB, class Y> void reset (DB&, const std::shared_ptr<Y>& | |
| template <class Y> void reset (database_type&, const std::shared_ptr<Y> | | ); | |
| &); | | template <class DB, class Y> void reset (DB&, std::shared_ptr<Y>&&); | |
| template <class Y> void reset (database_type&, std::shared_ptr<Y>&&); | | | |
| | | | |
| #ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT | | #ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT | |
| template <class O = T> | | template <class O = T> | |
| #else | | #else | |
| template <class O /*= T*/> | | template <class O /*= T*/> | |
| #endif | | #endif | |
| typename object_traits<O>::id_type object_id () const; | | typename object_traits<O>::id_type object_id () const; | |
| | | | |
| database_type& database () const; | | database_type& database () const; | |
| | | | |
| | | | |
| skipping to change at line 596 | | skipping to change at line 596 | |
| | | | |
| // Performs both lock and load. | | // Performs both lock and load. | |
| // | | // | |
| std::shared_ptr<T> load () const; | | std::shared_ptr<T> load () const; | |
| | | | |
| // Unload the pointer. For transient objects this function is | | // Unload the pointer. For transient objects this function is | |
| // equivalent to reset(). | | // equivalent to reset(). | |
| // | | // | |
| void unload () const; | | void unload () const; | |
| | | | |
|
| template <class ID> lazy_weak_ptr (database_type&, const ID&); | | template <class DB, class ID> lazy_weak_ptr (DB&, const ID&); | |
| template <class Y> lazy_weak_ptr (database_type&, const std::shared_ptr | | template <class DB, class Y> lazy_weak_ptr (DB&, const std::shared_ptr< | |
| <Y>&); | | Y>&); | |
| template <class Y> lazy_weak_ptr (database_type&, const std::weak_ptr<Y | | template <class DB, class Y> lazy_weak_ptr (DB&, const std::weak_ptr<Y> | |
| >&); | | &); | |
| | | | |
| template <class ID> void reset (database_type&, const ID&); | | template <class DB, class ID> void reset (DB&, const ID&); | |
| template <class Y> void reset (database_type&, const std::shared_ptr<Y> | | template <class DB, class Y> void reset (DB&, const std::shared_ptr<Y>& | |
| &); | | ); | |
| template <class Y> void reset (database_type&, const std::weak_ptr<Y>&) | | template <class DB, class Y> void reset (DB&, const std::weak_ptr<Y>&); | |
| ; | | | |
| | | | |
| // The object_id() function can only be called when the object is | | // The object_id() function can only be called when the object is | |
| // persistent, or: expired() XOR loaded() (can use != for XOR). | | // persistent, or: expired() XOR loaded() (can use != for XOR). | |
| // | | // | |
| #ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT | | #ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT | |
| template <class O = T> | | template <class O = T> | |
| #else | | #else | |
| template <class O /*= T*/> | | template <class O /*= T*/> | |
| #endif | | #endif | |
| typename object_traits<O>::id_type object_id () const; | | typename object_traits<O>::id_type object_id () const; | |
| | | | |
| skipping to change at line 630 | | skipping to change at line 630 | |
| mutable std::weak_ptr<T> p_; | | mutable std::weak_ptr<T> p_; | |
| mutable lazy_ptr_impl<T> i_; | | mutable lazy_ptr_impl<T> i_; | |
| }; | | }; | |
| | | | |
| // operator< is not provided. | | // operator< is not provided. | |
| // | | // | |
| template <class T> void swap (lazy_weak_ptr<T>&, lazy_weak_ptr<T>&); | | template <class T> void swap (lazy_weak_ptr<T>&, lazy_weak_ptr<T>&); | |
| | | | |
| #endif // ODB_CXX11 | | #endif // ODB_CXX11 | |
| | | | |
|
| namespace core | | namespace common | |
| { | | { | |
| using odb::lazy_ptr; | | using odb::lazy_ptr; | |
| using odb::lazy_auto_ptr; | | using odb::lazy_auto_ptr; | |
| | | | |
| #ifdef ODB_CXX11 | | #ifdef ODB_CXX11 | |
| using odb::lazy_unique_ptr; | | using odb::lazy_unique_ptr; | |
| using odb::lazy_shared_ptr; | | using odb::lazy_shared_ptr; | |
| using odb::lazy_weak_ptr; | | using odb::lazy_weak_ptr; | |
| #endif | | #endif | |
| } | | } | |
| | | | |
End of changes. 9 change blocks. |
| 62 lines changed or deleted | | 61 lines changed or added | |
|
| lazy-ptr.ixx | | lazy-ptr.ixx | |
| // file : odb/lazy-ptr.ixx | | // file : odb/lazy-ptr.ixx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| // | | // | |
| // lazy_ptr | | // lazy_ptr | |
| // | | // | |
| | | | |
| template <class T> | | template <class T> | |
| inline lazy_ptr<T>:: | | inline lazy_ptr<T>:: | |
| | | | |
| skipping to change at line 140 | | skipping to change at line 140 | |
| if (p_) | | if (p_) | |
| { | | { | |
| if (i_.database () != 0) | | if (i_.database () != 0) | |
| i_.reset_id (object_traits<object_type>::id (*p_)); | | i_.reset_id (object_traits<object_type>::id (*p_)); | |
| | | | |
| p_ = 0; | | p_ = 0; | |
| } | | } | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class ID> | | template <class DB, class ID> | |
| inline lazy_ptr<T>:: | | inline lazy_ptr<T>:: | |
|
| lazy_ptr (database_type& db, const ID& id): p_ (0), i_ (db, id) {} | | lazy_ptr (DB& db, const ID& id): p_ (0), i_ (db, id) {} | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y> | | template <class DB, class Y> | |
| inline lazy_ptr<T>:: | | inline lazy_ptr<T>:: | |
|
| lazy_ptr (database_type& db, Y* r) | | lazy_ptr (DB& db, Y* r) | |
| : p_ (r) | | : p_ (r) | |
| { | | { | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class ID> | | template <class DB, class ID> | |
| inline void lazy_ptr<T>:: | | inline void lazy_ptr<T>:: | |
|
| reset (database_type& db, const ID& id) | | reset (DB& db, const ID& id) | |
| { | | { | |
| p_ = 0; | | p_ = 0; | |
| i_.reset (db, id); | | i_.reset (db, id); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y> | | template <class DB, class Y> | |
| inline void lazy_ptr<T>:: | | inline void lazy_ptr<T>:: | |
|
| reset (database_type& db, Y* r) | | reset (DB& db, Y* r) | |
| { | | { | |
| p_ = r; | | p_ = r; | |
| | | | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| else | | else | |
| i_.reset (); | | i_.reset (); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
| template <class O> | | template <class O> | |
| inline typename object_traits<O>::id_type lazy_ptr<T>:: | | inline typename object_traits<O>::id_type lazy_ptr<T>:: | |
| object_id () const | | object_id () const | |
| { | | { | |
| typedef typename object_traits<T>::object_type object_type; | | typedef typename object_traits<T>::object_type object_type; | |
| | | | |
| skipping to change at line 399 | | skipping to change at line 399 | |
| if (p_.get () != 0) | | if (p_.get () != 0) | |
| { | | { | |
| if (i_.database () != 0) | | if (i_.database () != 0) | |
| i_.reset_id (object_traits<object_type>::id (*p_)); | | i_.reset_id (object_traits<object_type>::id (*p_)); | |
| | | | |
| p_.reset (); | | p_.reset (); | |
| } | | } | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class ID> | | template <class DB, class ID> | |
| inline lazy_auto_ptr<T>:: | | inline lazy_auto_ptr<T>:: | |
|
| lazy_auto_ptr (database_type& db, const ID& id): i_ (db, id) {} | | lazy_auto_ptr (DB& db, const ID& id): i_ (db, id) {} | |
| | | | |
| template <class T> | | template <class T> | |
|
| | | template <class DB> | |
| inline lazy_auto_ptr<T>:: | | inline lazy_auto_ptr<T>:: | |
|
| lazy_auto_ptr (database_type& db, T* p) | | lazy_auto_ptr (DB& db, T* p) | |
| : p_ (p) | | : p_ (p) | |
| { | | { | |
| if (p) | | if (p) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y> | | template <class DB, class Y> | |
| inline lazy_auto_ptr<T>:: | | inline lazy_auto_ptr<T>:: | |
|
| lazy_auto_ptr (database_type& db, std::auto_ptr<Y>& p) | | lazy_auto_ptr (DB& db, std::auto_ptr<Y>& p) | |
| : p_ (p) | | : p_ (p) | |
| { | | { | |
| if (p_.get () != 0) | | if (p_.get () != 0) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class ID> | | template <class DB, class ID> | |
| inline void lazy_auto_ptr<T>:: | | inline void lazy_auto_ptr<T>:: | |
|
| reset (database_type& db, const ID& id) | | reset (DB& db, const ID& id) | |
| { | | { | |
| p_.reset (); | | p_.reset (); | |
| i_.reset (db, id); | | i_.reset (db, id); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| | | template <class DB> | |
| inline void lazy_auto_ptr<T>:: | | inline void lazy_auto_ptr<T>:: | |
|
| reset (database_type& db, T* p) | | reset (DB& db, T* p) | |
| { | | { | |
| p_.reset (p); | | p_.reset (p); | |
| | | | |
| if (p) | | if (p) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| else | | else | |
| i_.reset (); | | i_.reset (); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y> | | template <class DB, class Y> | |
| inline void lazy_auto_ptr<T>:: | | inline void lazy_auto_ptr<T>:: | |
|
| reset (database_type& db, std::auto_ptr<Y>& p) | | reset (DB& db, std::auto_ptr<Y>& p) | |
| { | | { | |
| p_ = p; | | p_ = p; | |
| | | | |
| if (p_.get () != 0) | | if (p_.get () != 0) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| else | | else | |
| i_.reset (); | | i_.reset (); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
| template <class O> | | template <class O> | |
| inline typename object_traits<O>::id_type lazy_auto_ptr<T>:: | | inline typename object_traits<O>::id_type lazy_auto_ptr<T>:: | |
| object_id () const | | object_id () const | |
| { | | { | |
| typedef typename object_traits<T>::object_type object_type; | | typedef typename object_traits<T>::object_type object_type; | |
| | | | |
| skipping to change at line 668 | | skipping to change at line 670 | |
| if (p_) | | if (p_) | |
| { | | { | |
| if (i_.database () != 0) | | if (i_.database () != 0) | |
| i_.reset_id (object_traits<object_type>::id (*p_)); | | i_.reset_id (object_traits<object_type>::id (*p_)); | |
| | | | |
| p_.reset (); | | p_.reset (); | |
| } | | } | |
| } | | } | |
| | | | |
| template <class T, class D> | | template <class T, class D> | |
|
| template <class ID> | | template <class DB, class ID> | |
| inline lazy_unique_ptr<T, D>:: | | inline lazy_unique_ptr<T, D>:: | |
|
| lazy_unique_ptr (database_type& db, const ID& id): i_ (db, id) {} | | lazy_unique_ptr (DB& db, const ID& id): i_ (db, id) {} | |
| | | | |
| template <class T, class D> | | template <class T, class D> | |
|
| | | template <class DB> | |
| inline lazy_unique_ptr<T, D>:: | | inline lazy_unique_ptr<T, D>:: | |
|
| lazy_unique_ptr (database_type& db, T* p) | | lazy_unique_ptr (DB& db, T* p) | |
| : p_ (p) | | : p_ (p) | |
| { | | { | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| } | | } | |
| | | | |
| template <class T, class D> | | template <class T, class D> | |
|
| | | template <class DB> | |
| inline lazy_unique_ptr<T, D>:: | | inline lazy_unique_ptr<T, D>:: | |
|
| lazy_unique_ptr (database_type& db, T* p, const deleter_type& d) | | lazy_unique_ptr (DB& db, T* p, const deleter_type& d) | |
| : p_ (p, d) | | : p_ (p, d) | |
| { | | { | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| } | | } | |
| | | | |
| template <class T, class D> | | template <class T, class D> | |
|
| | | template <class DB> | |
| inline lazy_unique_ptr<T, D>:: | | inline lazy_unique_ptr<T, D>:: | |
|
| lazy_unique_ptr (database_type& db, T* p, deleter_type&& d) | | lazy_unique_ptr (DB& db, T* p, deleter_type&& d) | |
| : p_ (p, std::move (d)) | | : p_ (p, std::move (d)) | |
| { | | { | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| } | | } | |
| | | | |
| template <class T, class D> | | template <class T, class D> | |
|
| template <class T1, class D1> | | template <class DB, class T1, class D1> | |
| inline lazy_unique_ptr<T, D>:: | | inline lazy_unique_ptr<T, D>:: | |
|
| lazy_unique_ptr (database_type& db, std::unique_ptr<T1, D1>&& p) | | lazy_unique_ptr (DB& db, std::unique_ptr<T1, D1>&& p) | |
| : p_ (std::move (p)) | | : p_ (std::move (p)) | |
| { | | { | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| } | | } | |
| | | | |
| template <class T, class D> | | template <class T, class D> | |
|
| template <class T1> | | template <class DB, class T1> | |
| inline lazy_unique_ptr<T, D>:: | | inline lazy_unique_ptr<T, D>:: | |
|
| lazy_unique_ptr (database_type& db, std::auto_ptr<T1>&& p) | | lazy_unique_ptr (DB& db, std::auto_ptr<T1>&& p) | |
| : p_ (std::move (p)) | | : p_ (std::move (p)) | |
| { | | { | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| } | | } | |
| | | | |
| template <class T, class D> | | template <class T, class D> | |
|
| template <class ID> | | template <class DB, class ID> | |
| inline void lazy_unique_ptr<T, D>:: | | inline void lazy_unique_ptr<T, D>:: | |
|
| reset (database_type& db, const ID& id) | | reset (DB& db, const ID& id) | |
| { | | { | |
| p_.reset (); | | p_.reset (); | |
| i_.reset (db, id); | | i_.reset (db, id); | |
| } | | } | |
| | | | |
| template <class T, class D> | | template <class T, class D> | |
|
| | | template <class DB> | |
| inline void lazy_unique_ptr<T, D>:: | | inline void lazy_unique_ptr<T, D>:: | |
|
| reset (database_type& db, T* p) | | reset (DB& db, T* p) | |
| { | | { | |
| p_.reset (p); | | p_.reset (p); | |
| | | | |
| if (p) | | if (p) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| else | | else | |
| i_.reset (); | | i_.reset (); | |
| } | | } | |
| | | | |
| template <class T, class D> | | template <class T, class D> | |
|
| template <class T1, class D1> | | template <class DB, class T1, class D1> | |
| inline void lazy_unique_ptr<T, D>:: | | inline void lazy_unique_ptr<T, D>:: | |
|
| reset (database_type& db, std::unique_ptr<T1, D1>&& p) | | reset (DB& db, std::unique_ptr<T1, D1>&& p) | |
| { | | { | |
| p_ = std::move (p); | | p_ = std::move (p); | |
| | | | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| else | | else | |
| i_.reset (); | | i_.reset (); | |
| } | | } | |
| | | | |
| template <class T, class D> | | template <class T, class D> | |
|
| template <class T1> | | template <class DB, class T1> | |
| inline void lazy_unique_ptr<T, D>:: | | inline void lazy_unique_ptr<T, D>:: | |
|
| reset (database_type& db, std::auto_ptr<T1>&& p) | | reset (DB& db, std::auto_ptr<T1>&& p) | |
| { | | { | |
| p_ = std::unique_ptr<T, D> (std::move (p)); | | p_ = std::unique_ptr<T, D> (std::move (p)); | |
| | | | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| else | | else | |
| i_.reset (); | | i_.reset (); | |
| } | | } | |
| | | | |
| template <class T, class D> | | template <class T, class D> | |
| template <class O> | | template <class O> | |
| inline typename object_traits<O>::id_type lazy_unique_ptr<T, D>:: | | inline typename object_traits<O>::id_type lazy_unique_ptr<T, D>:: | |
| object_id () const | | object_id () const | |
| { | | { | |
| typedef typename object_traits<T>::object_type object_type; | | typedef typename object_traits<T>::object_type object_type; | |
| | | | |
| skipping to change at line 1147 | | skipping to change at line 1153 | |
| if (p_) | | if (p_) | |
| { | | { | |
| if (i_.database () != 0) | | if (i_.database () != 0) | |
| i_.reset_id (object_traits<object_type>::id (*p_)); | | i_.reset_id (object_traits<object_type>::id (*p_)); | |
| | | | |
| p_.reset (); | | p_.reset (); | |
| } | | } | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class ID> | | template <class DB, class ID> | |
| inline lazy_shared_ptr<T>:: | | inline lazy_shared_ptr<T>:: | |
|
| lazy_shared_ptr (database_type& db, const ID& id): i_ (db, id) {} | | lazy_shared_ptr (DB& db, const ID& id): i_ (db, id) {} | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y> | | template <class DB, class Y> | |
| inline lazy_shared_ptr<T>:: | | inline lazy_shared_ptr<T>:: | |
|
| lazy_shared_ptr (database_type& db, Y* p) | | lazy_shared_ptr (DB& db, Y* p) | |
| : p_ (p) | | : p_ (p) | |
| { | | { | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y, class D> | | template <class DB, class Y, class D> | |
| inline lazy_shared_ptr<T>:: | | inline lazy_shared_ptr<T>:: | |
|
| lazy_shared_ptr (database_type& db, Y* p, D d) | | lazy_shared_ptr (DB& db, Y* p, D d) | |
| : p_ (p, d) | | : p_ (p, d) | |
| { | | { | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y, class D, class A> | | template <class DB, class Y, class D, class A> | |
| inline lazy_shared_ptr<T>:: | | inline lazy_shared_ptr<T>:: | |
|
| lazy_shared_ptr (database_type& db, Y* p, D d, A a) | | lazy_shared_ptr (DB& db, Y* p, D d, A a) | |
| : p_ (p, d, a) | | : p_ (p, d, a) | |
| { | | { | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y> | | template <class DB, class Y> | |
| inline lazy_shared_ptr<T>:: | | inline lazy_shared_ptr<T>:: | |
|
| lazy_shared_ptr (database_type& db, std::auto_ptr<Y>&& r) | | lazy_shared_ptr (DB& db, std::auto_ptr<Y>&& r) | |
| : p_ (std::move (r)) | | : p_ (std::move (r)) | |
| { | | { | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y> | | template <class DB, class Y> | |
| inline lazy_shared_ptr<T>:: | | inline lazy_shared_ptr<T>:: | |
|
| lazy_shared_ptr (database_type& db, const std::shared_ptr<Y>& r) | | lazy_shared_ptr (DB& db, const std::shared_ptr<Y>& r) | |
| : p_ (r) | | : p_ (r) | |
| { | | { | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y> | | template <class DB, class Y> | |
| inline lazy_shared_ptr<T>:: | | inline lazy_shared_ptr<T>:: | |
|
| lazy_shared_ptr (database_type& db, std::shared_ptr<Y>&& r) | | lazy_shared_ptr (DB& db, std::shared_ptr<Y>&& r) | |
| : p_ (std::move (r)) | | : p_ (std::move (r)) | |
| { | | { | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y> | | template <class DB, class Y> | |
| inline lazy_shared_ptr<T>:: | | inline lazy_shared_ptr<T>:: | |
|
| lazy_shared_ptr (database_type& db, const std::weak_ptr<Y>& r) | | lazy_shared_ptr (DB& db, const std::weak_ptr<Y>& r) | |
| : p_ (r) | | : p_ (r) | |
| { | | { | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class ID> | | template <class DB, class ID> | |
| inline void lazy_shared_ptr<T>:: | | inline void lazy_shared_ptr<T>:: | |
|
| reset (database_type& db, const ID& id) | | reset (DB& db, const ID& id) | |
| { | | { | |
| p_.reset (); | | p_.reset (); | |
| i_.reset (db, id); | | i_.reset (db, id); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y> | | template <class DB, class Y> | |
| inline void lazy_shared_ptr<T>:: | | inline void lazy_shared_ptr<T>:: | |
|
| reset (database_type& db, Y* p) | | reset (DB& db, Y* p) | |
| { | | { | |
| p_.reset (p); | | p_.reset (p); | |
| | | | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| else | | else | |
| i_.reset (); | | i_.reset (); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y, class D> | | template <class DB, class Y, class D> | |
| inline void lazy_shared_ptr<T>:: | | inline void lazy_shared_ptr<T>:: | |
|
| reset (database_type& db, Y* p, D d) | | reset (DB& db, Y* p, D d) | |
| { | | { | |
| p_.reset (p, d); | | p_.reset (p, d); | |
| | | | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| else | | else | |
| i_.reset (); | | i_.reset (); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y, class D, class A> | | template <class DB, class Y, class D, class A> | |
| inline void lazy_shared_ptr<T>:: | | inline void lazy_shared_ptr<T>:: | |
|
| reset (database_type& db, Y* p, D d, A a) | | reset (DB& db, Y* p, D d, A a) | |
| { | | { | |
| p_.reset (p, d, a); | | p_.reset (p, d, a); | |
| | | | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| else | | else | |
| i_.reset (); | | i_.reset (); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y> | | template <class DB, class Y> | |
| inline void lazy_shared_ptr<T>:: | | inline void lazy_shared_ptr<T>:: | |
|
| reset (database_type& db, std::auto_ptr<Y>&& r) | | reset (DB& db, std::auto_ptr<Y>&& r) | |
| { | | { | |
| p_ = std::move (r); | | p_ = std::move (r); | |
| | | | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| else | | else | |
| i_.reset (); | | i_.reset (); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y> | | template <class DB, class Y> | |
| inline void lazy_shared_ptr<T>:: | | inline void lazy_shared_ptr<T>:: | |
|
| reset (database_type& db, const std::shared_ptr<Y>& r) | | reset (DB& db, const std::shared_ptr<Y>& r) | |
| { | | { | |
| p_ = r; | | p_ = r; | |
| | | | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| else | | else | |
| i_.reset (); | | i_.reset (); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y> | | template <class DB, class Y> | |
| inline void lazy_shared_ptr<T>:: | | inline void lazy_shared_ptr<T>:: | |
|
| reset (database_type& db, std::shared_ptr<Y>&& r) | | reset (DB& db, std::shared_ptr<Y>&& r) | |
| { | | { | |
| p_ = std::move (r); | | p_ = std::move (r); | |
| | | | |
| if (p_) | | if (p_) | |
|
| i_.reset (db); | | i_.reset_db (db); | |
| else | | else | |
| i_.reset (); | | i_.reset (); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
| template <class O> | | template <class O> | |
| inline typename object_traits<O>::id_type lazy_shared_ptr<T>:: | | inline typename object_traits<O>::id_type lazy_shared_ptr<T>:: | |
| object_id () const | | object_id () const | |
| { | | { | |
| typedef typename object_traits<T>::object_type object_type; | | typedef typename object_traits<T>::object_type object_type; | |
| | | | |
| skipping to change at line 1487 | | skipping to change at line 1493 | |
| inline lazy_weak_ptr<T>:: | | inline lazy_weak_ptr<T>:: | |
| lazy_weak_ptr (const std::shared_ptr<Y>& r): p_ (r) {} | | lazy_weak_ptr (const std::shared_ptr<Y>& r): p_ (r) {} | |
| | | | |
| template <class T> | | template <class T> | |
| template <class Y> | | template <class Y> | |
| inline lazy_weak_ptr<T>& lazy_weak_ptr<T>:: | | inline lazy_weak_ptr<T>& lazy_weak_ptr<T>:: | |
| operator= (const std::weak_ptr<Y>& r) | | operator= (const std::weak_ptr<Y>& r) | |
| { | | { | |
| p_ = r; | | p_ = r; | |
| i_.reset (); | | i_.reset (); | |
|
| return this; | | return *this; | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
| template <class Y> | | template <class Y> | |
| inline lazy_weak_ptr<T>& lazy_weak_ptr<T>:: | | inline lazy_weak_ptr<T>& lazy_weak_ptr<T>:: | |
| operator= (const std::shared_ptr<Y>& r) | | operator= (const std::shared_ptr<Y>& r) | |
| { | | { | |
| p_ = r; | | p_ = r; | |
| i_.reset (); | | i_.reset (); | |
|
| return this; | | return *this; | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
| inline bool lazy_weak_ptr<T>:: | | inline bool lazy_weak_ptr<T>:: | |
| loaded () const | | loaded () const | |
| { | | { | |
| bool i (i_); | | bool i (i_); | |
| return expired () != i; // expired () XOR i_ | | return expired () != i; // expired () XOR i_ | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 1532 | | skipping to change at line 1538 | |
| template <class T> | | template <class T> | |
| inline void lazy_weak_ptr<T>:: | | inline void lazy_weak_ptr<T>:: | |
| unload () const | | unload () const | |
| { | | { | |
| // With weak pointer we always keep i_ up to date. | | // With weak pointer we always keep i_ up to date. | |
| // | | // | |
| p_.reset (); | | p_.reset (); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class ID> | | template <class DB, class ID> | |
| inline lazy_weak_ptr<T>:: | | inline lazy_weak_ptr<T>:: | |
|
| lazy_weak_ptr (database_type& db, const ID& id): i_ (db, id) {} | | lazy_weak_ptr (DB& db, const ID& id): i_ (db, id) {} | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y> | | template <class DB, class Y> | |
| inline lazy_weak_ptr<T>:: | | inline lazy_weak_ptr<T>:: | |
|
| lazy_weak_ptr (database_type& db, const std::shared_ptr<Y>& r) | | lazy_weak_ptr (DB& db, const std::shared_ptr<Y>& r) | |
| : p_ (r) | | : p_ (r) | |
| { | | { | |
| typedef typename object_traits<T>::object_type object_type; | | typedef typename object_traits<T>::object_type object_type; | |
| | | | |
| if (r) | | if (r) | |
| i_.reset (db, object_traits<object_type>::id (*r)); | | i_.reset (db, object_traits<object_type>::id (*r)); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y> | | template <class DB, class Y> | |
| inline lazy_weak_ptr<T>:: | | inline lazy_weak_ptr<T>:: | |
|
| lazy_weak_ptr (database_type& db, const std::weak_ptr<Y>& r) | | lazy_weak_ptr (DB& db, const std::weak_ptr<Y>& r) | |
| : p_ (r) | | : p_ (r) | |
| { | | { | |
| typedef typename object_traits<T>::object_type object_type; | | typedef typename object_traits<T>::object_type object_type; | |
| | | | |
| std::shared_ptr<T> sp (p_.lock ()); | | std::shared_ptr<T> sp (p_.lock ()); | |
| | | | |
| if (sp) | | if (sp) | |
| i_.reset (db, object_traits<object_type>::id (*sp)); | | i_.reset (db, object_traits<object_type>::id (*sp)); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class ID> | | template <class DB, class ID> | |
| inline void lazy_weak_ptr<T>:: | | inline void lazy_weak_ptr<T>:: | |
|
| reset (database_type& db, const ID& id) | | reset (DB& db, const ID& id) | |
| { | | { | |
| p_.reset (); | | p_.reset (); | |
| i_.reset (db, id); | | i_.reset (db, id); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y> | | template <class DB, class Y> | |
| inline void lazy_weak_ptr<T>:: | | inline void lazy_weak_ptr<T>:: | |
|
| reset (database_type& db, const std::shared_ptr<Y>& r) | | reset (DB& db, const std::shared_ptr<Y>& r) | |
| { | | { | |
| typedef typename object_traits<T>::object_type object_type; | | typedef typename object_traits<T>::object_type object_type; | |
| | | | |
| p_ = r; | | p_ = r; | |
| | | | |
| if (r) | | if (r) | |
| i_.reset (db, object_traits<object_type>::id (*r)); | | i_.reset (db, object_traits<object_type>::id (*r)); | |
| else | | else | |
| i_.reset (); | | i_.reset (); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| template <class Y> | | template <class DB, class Y> | |
| inline void lazy_weak_ptr<T>:: | | inline void lazy_weak_ptr<T>:: | |
|
| reset (database_type& db, const std::weak_ptr<Y>& r) | | reset (DB& db, const std::weak_ptr<Y>& r) | |
| { | | { | |
| typedef typename object_traits<T>::object_type object_type; | | typedef typename object_traits<T>::object_type object_type; | |
| | | | |
| p_ = r; | | p_ = r; | |
| std::shared_ptr<T> sp (p_.lock ()); | | std::shared_ptr<T> sp (p_.lock ()); | |
| | | | |
| if (sp) | | if (sp) | |
| i_.reset (db, object_traits<object_type>::id (*sp)); | | i_.reset (db, object_traits<object_type>::id (*sp)); | |
| else | | else | |
| i_.reset (); | | i_.reset (); | |
| | | | |
End of changes. 112 change blocks. |
| 106 lines changed or deleted | | 112 lines changed or added | |
|
| no-id-object-result.hxx | | no-id-object-result.hxx | |
| // file : odb/no-id-object-result.hxx | | // file : odb/no-id-object-result.hxx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_NO_ID_OBJECT_RESULT_HXX | | #ifndef ODB_NO_ID_OBJECT_RESULT_HXX | |
| #define ODB_NO_ID_OBJECT_RESULT_HXX | | #define ODB_NO_ID_OBJECT_RESULT_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
| #include <cstddef> // std::size_t | | #include <cstddef> // std::size_t | |
| #include <utility> // std::move | | #include <utility> // std::move | |
| | | | |
| #include <odb/forward.hxx> | | #include <odb/forward.hxx> | |
| #include <odb/traits.hxx> | | #include <odb/traits.hxx> | |
| #include <odb/result.hxx> | | #include <odb/result.hxx> | |
| #include <odb/object-result.hxx> | | #include <odb/object-result.hxx> | |
| #include <odb/pointer-traits.hxx> | | #include <odb/pointer-traits.hxx> | |
| | | | |
| #include <odb/details/config.hxx> // ODB_CXX11 | | #include <odb/details/config.hxx> // ODB_CXX11 | |
|
| #include <odb/details/shared-ptr.hxx> | | | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| // Implementation for objects without object id (always non-polymorphic). | | // Implementation for objects without object id (always non-polymorphic). | |
| // | | // | |
| template <typename T> | | template <typename T> | |
|
| class no_id_object_result_impl: public details::shared_base | | class no_id_object_result_impl: public result_impl | |
| { | | { | |
|
| public: | | | |
| virtual | | | |
| ~no_id_object_result_impl (); | | | |
| | | | |
| protected: | | protected: | |
|
| typedef odb::database database_type; | | | |
| | | | |
| // In result_impl, T is always non-const and the same as object_type. | | // In result_impl, T is always non-const and the same as object_type. | |
| // | | // | |
| typedef T object_type; | | typedef T object_type; | |
| typedef odb::object_traits<object_type> object_traits; | | typedef odb::object_traits<object_type> object_traits; | |
| | | | |
| typedef typename object_traits::pointer_type pointer_type; | | typedef typename object_traits::pointer_type pointer_type; | |
| typedef odb::pointer_traits<pointer_type> pointer_traits; | | typedef odb::pointer_traits<pointer_type> pointer_traits; | |
| | | | |
| friend class result<T>; | | friend class result<T>; | |
| friend class result<const T>; | | friend class result<const T>; | |
| friend class result_iterator<T, class_object>; | | friend class result_iterator<T, class_object>; | |
| friend class result_iterator<const T, class_object>; | | friend class result_iterator<const T, class_object>; | |
| friend class object_result_iterator<T, void, false>; | | friend class object_result_iterator<T, void, false>; | |
| friend class object_result_iterator<const T, void, false>; | | friend class object_result_iterator<const T, void, false>; | |
| | | | |
| protected: | | protected: | |
|
| no_id_object_result_impl (database_type& db) | | no_id_object_result_impl (odb::connection& conn) | |
| : begin_ (true), end_ (false), db_ (db), current_ () | | : result_impl (conn), begin_ (true), end_ (false), current_ () | |
| { | | | |
| } | | | |
| | | | |
| database_type& | | | |
| database () const | | | |
| { | | { | |
|
| return db_; | | | |
| } | | } | |
| | | | |
| // To make this work with all kinds of pointers (raw, std::auto_ptr, | | // To make this work with all kinds of pointers (raw, std::auto_ptr, | |
| // shared), we need to make sure we don't make any copies of the | | // shared), we need to make sure we don't make any copies of the | |
| // pointer on the return path. | | // pointer on the return path. | |
| // | | // | |
| pointer_type& | | pointer_type& | |
| current () | | current () | |
| { | | { | |
| if (pointer_traits::null_ptr (current_) && !end_) | | if (pointer_traits::null_ptr (current_) && !end_) | |
| | | | |
| skipping to change at line 143 | | skipping to change at line 130 | |
| #endif | | #endif | |
| | | | |
| bool begin_; | | bool begin_; | |
| bool end_; | | bool end_; | |
| | | | |
| private: | | private: | |
| void | | void | |
| load (); | | load (); | |
| | | | |
| private: | | private: | |
|
| database_type& db_; | | | |
| pointer_type current_; | | pointer_type current_; | |
| typename pointer_traits::guard guard_; | | typename pointer_traits::guard guard_; | |
| }; | | }; | |
| | | | |
| template <typename T> | | template <typename T> | |
| class object_result_iterator<T, void, false> | | class object_result_iterator<T, void, false> | |
| { | | { | |
| public: | | public: | |
| // T can be const T while object_type is always non-const. | | // T can be const T while object_type is always non-const. | |
| // | | // | |
| | | | |
End of changes. 8 change blocks. |
| 18 lines changed or deleted | | 4 lines changed or added | |
|
| polymorphic-map.hxx | | polymorphic-map.hxx | |
| // file : odb/polymorphic-map.hxx | | // file : odb/polymorphic-map.hxx | |
|
| // copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_POLYMORPHIC_MAP_HXX | | #ifndef ODB_POLYMORPHIC_MAP_HXX | |
| #define ODB_POLYMORPHIC_MAP_HXX | | #define ODB_POLYMORPHIC_MAP_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
| #include <map> | | #include <map> | |
| #include <utility> // std::move | | #include <utility> // std::move | |
| #include <cstddef> // std::size_t | | #include <cstddef> // std::size_t | |
| | | | |
| skipping to change at line 69 | | skipping to change at line 69 | |
| const info_type*, | | const info_type*, | |
| discriminator_comparator> | | discriminator_comparator> | |
| discriminator_map; | | discriminator_map; | |
| | | | |
| public: | | public: | |
| std::size_t ref_count_; | | std::size_t ref_count_; | |
| type_map type_map_; | | type_map type_map_; | |
| discriminator_map discriminator_map_; | | discriminator_map discriminator_map_; | |
| }; | | }; | |
| | | | |
|
| template <typename R> | | template <typename R, database_id DB> | |
| struct polymorphic_entry_impl | | struct polymorphic_entry_impl | |
| { | | { | |
| typedef R root_type; | | typedef R root_type; | |
|
| typedef object_traits<root_type> root_traits; | | typedef object_traits_impl<root_type, DB> root_traits; | |
| typedef polymorphic_concrete_info<root_type> info_type; | | typedef polymorphic_concrete_info<root_type> info_type; | |
| | | | |
| static void | | static void | |
| insert (const info_type&); | | insert (const info_type&); | |
| | | | |
| static void | | static void | |
| erase (const info_type&); | | erase (const info_type&); | |
| }; | | }; | |
| | | | |
| template <typename T> | | template <typename T> | |
| | | | |
| skipping to change at line 106 | | skipping to change at line 106 | |
| // Implicit downcast. | | // Implicit downcast. | |
| // | | // | |
| #ifdef ODB_CXX11 | | #ifdef ODB_CXX11 | |
| root_pointer_type r (std::move (p)); | | root_pointer_type r (std::move (p)); | |
| #else | | #else | |
| root_pointer_type r (p); | | root_pointer_type r (p); | |
| #endif | | #endif | |
| return r; | | return r; | |
| } | | } | |
| | | | |
|
| template <typename T, typename R> | | template <typename T, database_id DB, typename R> | |
| struct dispatch_load | | struct dispatch_load | |
| { | | { | |
| static void | | static void | |
| call (database& db, T& obj, std::size_t d) | | call (database& db, T& obj, std::size_t d) | |
| { | | { | |
|
| object_traits<T>::load_ (db, obj, d); | | object_traits_impl<T, DB>::load_ (db, obj, d); | |
| } | | } | |
| }; | | }; | |
| | | | |
|
| template <typename R> | | template <typename R, database_id DB> | |
| struct dispatch_load<R, R> | | struct dispatch_load<R, DB, R> | |
| { | | { | |
| static void | | static void | |
| call (database&, R&, std::size_t) | | call (database&, R&, std::size_t) | |
| { | | { | |
| assert (false); | | assert (false); | |
| } | | } | |
| }; | | }; | |
| | | | |
|
| template <typename T, bool auto_id> | | template <typename T, database_id DB, bool auto_id> | |
| struct dispatch_persist | | struct dispatch_persist | |
| { | | { | |
| static void | | static void | |
| call (database& db, const T& obj) | | call (database& db, const T& obj) | |
| { | | { | |
| // Top-level call, no dynamic type checking. | | // Top-level call, no dynamic type checking. | |
| // | | // | |
|
| object_traits<T>::persist (db, obj, true, false); | | object_traits_impl<T, DB>::persist (db, obj, true, false); | |
| } | | } | |
| }; | | }; | |
| | | | |
|
| template <typename T> | | template <typename T, database_id DB> | |
| struct dispatch_persist<T, true> | | struct dispatch_persist<T, DB, true> | |
| { | | { | |
| static void | | static void | |
| call (database& db, const T& obj) | | call (database& db, const T& obj) | |
| { | | { | |
| // Top-level call, no dynamic type checking. | | // Top-level call, no dynamic type checking. | |
| // | | // | |
|
| object_traits<T>::persist (db, const_cast<T&> (obj), true, false); | | object_traits_impl<T, DB>::persist ( | |
| | | db, const_cast<T&> (obj), true, false); | |
| } | | } | |
| }; | | }; | |
| | | | |
|
| template <typename T> | | template <typename T, database_id DB> | |
| bool dispatch_impl ( | | bool dispatch_impl ( | |
| typename polymorphic_concrete_info< | | typename polymorphic_concrete_info< | |
| typename object_traits<T>::root_type>::call_type c, | | typename object_traits<T>::root_type>::call_type c, | |
| database& db, | | database& db, | |
| const typename object_traits<T>::root_type* pobj, | | const typename object_traits<T>::root_type* pobj, | |
| const void* arg) | | const void* arg) | |
| { | | { | |
|
| typedef object_traits<T> derived_traits; | | typedef object_traits_impl<T, DB> derived_traits; | |
| typedef typename derived_traits::root_type root_type; | | typedef typename derived_traits::root_type root_type; | |
|
| typedef object_traits<root_type> root_traits; | | typedef object_traits_impl<root_type, DB> root_traits; | |
| typedef typename root_traits::id_type id_type; | | typedef typename root_traits::id_type id_type; | |
| typedef polymorphic_concrete_info<root_type> info_type; | | typedef polymorphic_concrete_info<root_type> info_type; | |
| | | | |
| bool r (false); | | bool r (false); | |
| | | | |
| switch (c) | | switch (c) | |
| { | | { | |
| case info_type::call_callback: | | case info_type::call_callback: | |
| { | | { | |
| derived_traits::callback ( | | derived_traits::callback ( | |
| db, | | db, | |
| *const_cast<T*> (static_cast<const T*> (pobj)), | | *const_cast<T*> (static_cast<const T*> (pobj)), | |
| *static_cast<const callback_event*> (arg)); | | *static_cast<const callback_event*> (arg)); | |
| break; | | break; | |
| } | | } | |
| case info_type::call_persist: | | case info_type::call_persist: | |
| { | | { | |
|
| dispatch_persist<T, root_traits::auto_id>::call ( | | dispatch_persist<T, DB, root_traits::auto_id>::call ( | |
| db, | | db, | |
| *static_cast<const T*> (pobj)); | | *static_cast<const T*> (pobj)); | |
| break; | | break; | |
| } | | } | |
| case info_type::call_update: | | case info_type::call_update: | |
| { | | { | |
| derived_traits::update ( | | derived_traits::update ( | |
| db, | | db, | |
| *static_cast<const T*> (pobj), | | *static_cast<const T*> (pobj), | |
| true, // Top-level call. | | true, // Top-level call. | |
| | | | |
| skipping to change at line 211 | | skipping to change at line 212 | |
| case info_type::call_reload: | | case info_type::call_reload: | |
| { | | { | |
| r = derived_traits::reload ( | | r = derived_traits::reload ( | |
| db, | | db, | |
| *const_cast<T*> (static_cast<const T*> (pobj)), | | *const_cast<T*> (static_cast<const T*> (pobj)), | |
| false); // No dynamic type checking. | | false); // No dynamic type checking. | |
| break; | | break; | |
| } | | } | |
| case info_type::call_load: | | case info_type::call_load: | |
| { | | { | |
|
| dispatch_load<T, root_type>::call ( | | dispatch_load<T, DB, root_type>::call ( | |
| db, | | db, | |
| *const_cast<T*> (static_cast<const T*> (pobj)), | | *const_cast<T*> (static_cast<const T*> (pobj)), | |
| *static_cast<const std::size_t*> (arg)); | | *static_cast<const std::size_t*> (arg)); | |
| break; | | break; | |
| } | | } | |
| case info_type::call_erase: | | case info_type::call_erase: | |
| { | | { | |
| if (pobj != 0) | | if (pobj != 0) | |
| derived_traits::erase ( | | derived_traits::erase ( | |
| db, | | db, | |
| | | | |
End of changes. 15 change blocks. |
| 17 lines changed or deleted | | 18 lines changed or added | |
|
| polymorphic-object-result.hxx | | polymorphic-object-result.hxx | |
| // file : odb/polymorphic-object-result.hxx | | // file : odb/polymorphic-object-result.hxx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_POLYMORPHIC_OBJECT_RESULT_HXX | | #ifndef ODB_POLYMORPHIC_OBJECT_RESULT_HXX | |
| #define ODB_POLYMORPHIC_OBJECT_RESULT_HXX | | #define ODB_POLYMORPHIC_OBJECT_RESULT_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
| #include <cstddef> // std::size_t | | #include <cstddef> // std::size_t | |
| #include <utility> // std::move | | #include <utility> // std::move | |
| | | | |
| #include <odb/forward.hxx> | | #include <odb/forward.hxx> | |
| #include <odb/traits.hxx> | | #include <odb/traits.hxx> | |
| #include <odb/result.hxx> | | #include <odb/result.hxx> | |
| #include <odb/object-result.hxx> | | #include <odb/object-result.hxx> | |
| #include <odb/pointer-traits.hxx> | | #include <odb/pointer-traits.hxx> | |
| | | | |
| #include <odb/details/config.hxx> // ODB_CXX11 | | #include <odb/details/config.hxx> // ODB_CXX11 | |
|
| #include <odb/details/shared-ptr.hxx> | | | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| // Implementation for polymorphic objects with object id. | | // Implementation for polymorphic objects with object id. | |
| // | | // | |
| template <typename T> | | template <typename T> | |
|
| class polymorphic_object_result_impl: public details::shared_base | | class polymorphic_object_result_impl: public result_impl | |
| { | | { | |
|
| public: | | | |
| virtual | | | |
| ~polymorphic_object_result_impl (); | | | |
| | | | |
| protected: | | protected: | |
|
| typedef odb::database database_type; | | | |
| | | | |
| // In result_impl, T is always non-const and the same as object_type. | | // In result_impl, T is always non-const and the same as object_type. | |
| // | | // | |
| typedef T object_type; | | typedef T object_type; | |
| typedef odb::object_traits<object_type> object_traits; | | typedef odb::object_traits<object_type> object_traits; | |
| typedef typename object_traits::id_type id_type; | | typedef typename object_traits::id_type id_type; | |
| | | | |
| typedef typename object_traits::pointer_type pointer_type; | | typedef typename object_traits::pointer_type pointer_type; | |
| typedef odb::pointer_traits<pointer_type> pointer_traits; | | typedef odb::pointer_traits<pointer_type> pointer_traits; | |
| | | | |
| typedef typename object_traits::root_type root_type; | | typedef typename object_traits::root_type root_type; | |
| | | | |
| skipping to change at line 57 | | skipping to change at line 50 | |
| typedef typename root_traits::discriminator_type discriminator_type; | | typedef typename root_traits::discriminator_type discriminator_type; | |
| | | | |
| friend class result<T>; | | friend class result<T>; | |
| friend class result<const T>; | | friend class result<const T>; | |
| friend class result_iterator<T, class_object>; | | friend class result_iterator<T, class_object>; | |
| friend class result_iterator<const T, class_object>; | | friend class result_iterator<const T, class_object>; | |
| friend class object_result_iterator<T, id_type, true>; | | friend class object_result_iterator<T, id_type, true>; | |
| friend class object_result_iterator<const T, id_type, true>; | | friend class object_result_iterator<const T, id_type, true>; | |
| | | | |
| protected: | | protected: | |
|
| polymorphic_object_result_impl (database_type& db) | | polymorphic_object_result_impl (odb::connection& conn) | |
| : begin_ (true), end_ (false), db_ (db), current_ () | | : result_impl (conn), begin_ (true), end_ (false), current_ () | |
| { | | | |
| } | | | |
| | | | |
| database_type& | | | |
| database () const | | | |
| { | | { | |
|
| return db_; | | | |
| } | | } | |
| | | | |
| // To make this work with all kinds of pointers (raw, std::auto_ptr, | | // To make this work with all kinds of pointers (raw, std::auto_ptr, | |
| // shared), we need to make sure we don't make any copies of the | | // shared), we need to make sure we don't make any copies of the | |
| // pointer on the return path. | | // pointer on the return path. | |
| // | | // | |
| pointer_type& | | pointer_type& | |
| current () | | current () | |
| { | | { | |
| if (pointer_traits::null_ptr (current_) && !end_) | | if (pointer_traits::null_ptr (current_) && !end_) | |
| | | | |
| skipping to change at line 114 | | skipping to change at line 101 | |
| protected: | | protected: | |
| // The fetch argument is a hint to the implementation. If it is | | // The fetch argument is a hint to the implementation. If it is | |
| // false then it means load_id() was already called (and presumably | | // false then it means load_id() was already called (and presumably | |
| // fetched the data into the object image) and the object image | | // fetched the data into the object image) and the object image | |
| // is still valid (so the implementation doesn't need to fetch | | // is still valid (so the implementation doesn't need to fetch | |
| // the data again). | | // the data again). | |
| // | | // | |
| // The load() signature differs from the non-polymorphic cases in | | // The load() signature differs from the non-polymorphic cases in | |
| // that we pass a pointer to object instead of a reference. The | | // that we pass a pointer to object instead of a reference. The | |
| // object is only passed if the user requests loading into an | | // object is only passed if the user requests loading into an | |
|
| // existing instance. Otherwise, we pass NULL an load() is | | // existing instance. Otherwise, we pass NULL and load() is | |
| // responsible for creating the object of a correct dynamic | | // responsible for creating the object of a correct dynamic | |
| // type and managing the object cache insertion. | | // type and managing the object cache insertion. | |
| // | | // | |
| virtual void | | virtual void | |
| load (object_type*, bool fetch = true) = 0; | | load (object_type*, bool fetch = true) = 0; | |
| | | | |
| virtual id_type | | virtual id_type | |
| load_id () = 0; | | load_id () = 0; | |
| | | | |
| virtual discriminator_type | | virtual discriminator_type | |
| | | | |
| skipping to change at line 175 | | skipping to change at line 162 | |
| #endif | | #endif | |
| | | | |
| bool begin_; | | bool begin_; | |
| bool end_; | | bool end_; | |
| | | | |
| private: | | private: | |
| void | | void | |
| load (); | | load (); | |
| | | | |
| private: | | private: | |
|
| database_type& db_; | | | |
| pointer_type current_; | | pointer_type current_; | |
| typename pointer_traits::guard guard_; | | typename pointer_traits::guard guard_; | |
| }; | | }; | |
| | | | |
| template <typename T, typename ID> | | template <typename T, typename ID> | |
| class object_result_iterator<T, ID, true> | | class object_result_iterator<T, ID, true> | |
| { | | { | |
| public: | | public: | |
| // T can be const T while object_type is always non-const. | | // T can be const T while object_type is always non-const. | |
| // | | // | |
| | | | |
End of changes. 9 change blocks. |
| 19 lines changed or deleted | | 5 lines changed or added | |
|
| query.hxx | | query.hxx | |
| // file : odb/query.hxx | | // file : odb/query.hxx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_QUERY_HXX | | #ifndef ODB_QUERY_HXX | |
| #define ODB_QUERY_HXX | | #define ODB_QUERY_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
|
| | | #include <odb/forward.hxx> | |
| #include <odb/traits.hxx> | | #include <odb/traits.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
|
| // Table alias for type T and alias tag Tag. The dummy third template | | // Table alias for type T and tag Tag. | |
| // argument is used to make the C++ compiler weed out duplicates. | | | |
| // | | // | |
| // The alias_traits interface consists of two things: the table_name | | // The alias_traits interface consists of two things: the table_name | |
| // static variable containing the name and, in case of a derived type | | // static variable containing the name and, in case of a derived type | |
| // in a polymorphic hierarchy, the base_traits typedef. Note that the | | // in a polymorphic hierarchy, the base_traits typedef. Note that the | |
| // same interface is exposed by object_traits, which is used when | | // same interface is exposed by object_traits, which is used when | |
| // we need straight tables instead of aliases. | | // we need straight tables instead of aliases. | |
| // | | // | |
| // | | // | |
|
| template <typename T, typename Tag, bool dummy = true> | | template <typename T, database_id DB, typename Tag> | |
| struct alias_traits; | | struct alias_traits; | |
| | | | |
|
| template <typename T> | | template <typename T, database_id DB> | |
| struct query_columns_base; | | struct query_columns_base; | |
| | | | |
|
| template <typename T, typename Alias> | | template <typename T, database_id DB, typename A> | |
| struct query_columns; | | struct query_columns; | |
| | | | |
|
| template <typename T, typename Alias> | | template <typename T, database_id DB, typename A> | |
| struct pointer_query_columns; | | struct pointer_query_columns; | |
| | | | |
| // Object pointer syntax wrapper. | | // Object pointer syntax wrapper. | |
| // | | // | |
| template <typename T> | | template <typename T> | |
| struct query_pointer | | struct query_pointer | |
| { | | { | |
| query_pointer () | | query_pointer () | |
| { | | { | |
| // For some reason GCC needs this dummy c-tor if we make a static | | // For some reason GCC needs this dummy c-tor if we make a static | |
| // data member of this type const. | | // data member of this type const. | |
| } | | } | |
| | | | |
| T* | | T* | |
| operator-> () const | | operator-> () const | |
| { | | { | |
| return 0; // All members in T are static. | | return 0; // All members in T are static. | |
| } | | } | |
| }; | | }; | |
| | | | |
|
| | | // Query parameter decay traits. | |
| | | // | |
| | | template <typename T> | |
| | | struct decay_traits | |
| | | { | |
| | | typedef const T& type; | |
| | | | |
| | | static type | |
| | | instance (); | |
| | | }; | |
| | | | |
| | | template <typename T, std::size_t N> | |
| | | struct decay_traits<T[N]> | |
| | | { | |
| | | typedef const T* type; | |
| | | | |
| | | // Use the pointer comparability as a proxy for data comparability. | |
| | | // Note that it is stricter than using element comparability (i.e., | |
| | | // one can compare int to char but not int* to char*). | |
| | | // | |
| | | static type | |
| | | instance (); | |
| | | }; | |
| | | | |
| // VC9 cannot handle certain cases of non-type arguments with default | | // VC9 cannot handle certain cases of non-type arguments with default | |
| // values in template functions (e.g., database::query()). As a result, | | // values in template functions (e.g., database::query()). As a result, | |
| // we have to use the impl trick below instead of simply having kind | | // we have to use the impl trick below instead of simply having kind | |
| // as a second template argument with a default value. | | // as a second template argument with a default value. | |
| // | | // | |
|
| template <typename T, class_kind kind> | | template <typename T, database_id DB, class_kind kind> | |
| struct query_selector_impl; | | struct query_selector_impl; | |
| | | | |
|
| template <typename T> | | template <typename T, database_id DB> | |
| struct query_selector_impl<T, class_object> | | struct query_selector_impl<T, DB, class_object> | |
| { | | { | |
|
| typedef typename object_traits<T>::query_base_type base_type; | | typedef typename object_traits_impl<T, DB>::query_base_type base_type; | |
| typedef query_columns<T, access::object_traits<T> > columns_type; | | | |
| | | typedef | |
| | | query_columns<T, DB, access::object_traits_impl<T, DB> > | |
| | | columns_type; | |
| }; | | }; | |
| | | | |
|
| template <typename T> | | template <typename T, database_id DB> | |
| struct query_selector_impl<T, class_view> | | struct query_selector_impl<T, DB, class_view> | |
| { | | { | |
|
| typedef typename view_traits<T>::query_base_type base_type; | | typedef typename view_traits_impl<T, DB>::query_base_type base_type; | |
| typedef typename view_traits<T>::query_columns columns_type; | | typedef typename view_traits_impl<T, DB>::query_columns columns_type; | |
| }; | | }; | |
| | | | |
|
| template <typename T> | | template <typename T, database_id DB> | |
| struct query_selector: query_selector_impl<T, class_traits<T>::kind> | | struct query_selector: query_selector_impl<T, DB, class_traits<T>::kind> | |
| { | | { | |
| }; | | }; | |
| | | | |
|
| template <typename T, typename Q = typename query_selector<T>::base_type> | | template <typename T, | |
| | | typename B = typename query_selector<T, id_common>::base_type> | |
| class query; | | class query; | |
| | | | |
| namespace core | | namespace core | |
| { | | { | |
| using odb::query; | | using odb::query; | |
| } | | } | |
| } | | } | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| | | | |
End of changes. 15 change blocks. |
| 19 lines changed or deleted | | 47 lines changed or added | |
|
| session.hxx | | session.hxx | |
| // file : odb/session.hxx | | // file : odb/session.hxx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_SESSION_HXX | | #ifndef ODB_SESSION_HXX | |
| #define ODB_SESSION_HXX | | #define ODB_SESSION_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
| #include <map> | | #include <map> | |
| #include <typeinfo> | | #include <typeinfo> | |
| | | | |
| | | | |
| skipping to change at line 45 | | skipping to change at line 45 | |
| // | | // | |
| ~session (); | | ~session (); | |
| | | | |
| // Current session. | | // Current session. | |
| // | | // | |
| public: | | public: | |
| // Return true if there is a session in effect in the current | | // Return true if there is a session in effect in the current | |
| // thread. | | // thread. | |
| // | | // | |
| static bool | | static bool | |
|
| has_current (); | | has_current () {return current_pointer () != 0;} | |
| | | | |
| // Get current thread's session. Throw if no session is in effect. | | // Get current thread's session. Throw if no session is in effect. | |
| // | | // | |
| static session& | | static session& | |
| current (); | | current (); | |
| | | | |
| // Set current thread's session. | | // Set current thread's session. | |
| // | | // | |
| static void | | static void | |
|
| current (session&); | | current (session& s) {current_pointer (&s);} | |
| | | | |
| // Revert to the no session in effect state for the current thread. | | // Revert to the no session in effect state for the current thread. | |
| // | | // | |
| static void | | static void | |
|
| reset_current (); | | reset_current () {current_pointer (0);} | |
| | | | |
| | | // Pointer versions. | |
| | | // | |
| | | static session* | |
| | | current_pointer (); | |
| | | | |
| | | static void | |
| | | current_pointer (session*); | |
| | | | |
| // Copying or assignment of sessions is not supported. | | // Copying or assignment of sessions is not supported. | |
| // | | // | |
| private: | | private: | |
| session (const session&); | | session (const session&); | |
| session& operator= (const session&); | | session& operator= (const session&); | |
| | | | |
|
| protected: | | public: | |
| struct LIBODB_EXPORT object_map_base: details::shared_base | | struct LIBODB_EXPORT object_map_base: details::shared_base | |
| { | | { | |
| virtual | | virtual | |
| ~object_map_base (); | | ~object_map_base (); | |
| }; | | }; | |
| | | | |
| template <typename T> | | template <typename T> | |
|
| struct object_map: | | struct object_map: object_map_base, | |
| object_map_base, | | std::map<typename object_traits<T>::id_type, | |
| std::map<typename object_traits<T>::id_type, | | typename object_traits<T>::pointer_type> | |
| typename object_traits<T>::pointer_type> | | | |
| { | | { | |
| }; | | }; | |
| | | | |
| // Object cache. | | // Object cache. | |
| // | | // | |
| public: | | public: | |
|
| | | // Position in the cache of the inserted element. | |
| | | // | |
| template <typename T> | | template <typename T> | |
|
| struct object_position | | struct cache_position; | |
| { | | | |
| typedef T object_type; | | | |
| typedef object_map<object_type> map; | | | |
| typedef typename map::iterator iterator; | | | |
| | | | |
| object_position (): map_ (0) {} | | | |
| object_position (map& m, const iterator& p): map_ (&m), pos_ (p) {} | | | |
| | | | |
| map* map_; | | | |
| iterator pos_; | | | |
| }; | | | |
| | | | |
| template <typename T> | | template <typename T> | |
|
| object_position<T> | | cache_position<T> | |
| insert (database_type&, | | cache_insert (database_type&, | |
| const typename object_traits<T>::id_type&, | | const typename object_traits<T>::id_type&, | |
| const typename object_traits<T>::pointer_type&); | | const typename object_traits<T>::pointer_type&); | |
| | | | |
| template <typename T> | | template <typename T> | |
| typename object_traits<T>::pointer_type | | typename object_traits<T>::pointer_type | |
|
| find (database_type&, const typename object_traits<T>::id_type&) const; | | cache_find (database_type&, | |
| | | const typename object_traits<T>::id_type&) const; | |
| | | | |
| template <typename T> | | template <typename T> | |
| void | | void | |
|
| erase (database_type&, const typename object_traits<T>::id_type&); | | cache_erase (const cache_position<T>&); | |
| | | | |
| template <typename T> | | template <typename T> | |
| void | | void | |
|
| erase (const object_position<T>&); | | cache_erase (database_type&, const typename object_traits<T>::id_type&)
; | |
| | | | |
|
| protected: | | // Low-level object cache access (iteration, etc). | |
| | | // | |
| | | public: | |
| typedef std::map<const std::type_info*, | | typedef std::map<const std::type_info*, | |
| details::shared_ptr<object_map_base>, | | details::shared_ptr<object_map_base>, | |
| details::type_info_comparator> type_map; | | details::type_info_comparator> type_map; | |
| | | | |
| typedef std::map<database_type*, type_map> database_map; | | typedef std::map<database_type*, type_map> database_map; | |
| | | | |
|
| | | database_map& | |
| | | map () {return db_map_;} | |
| | | | |
| | | const database_map& | |
| | | map () const {return db_map_;} | |
| | | | |
| | | // Static cache API as expected by the rest of ODB. | |
| | | // | |
| | | public: | |
| | | // Position in the cache of the inserted element. The requirements | |
| | | // for this class template are: default and copy-constructible as | |
| | | // well as copy-assignable. The default constructor creates an | |
| | | // empty/NULL position. | |
| | | // | |
| | | template <typename T> | |
| | | struct cache_position | |
| | | { | |
| | | typedef object_map<T> map; | |
| | | typedef typename map::iterator iterator; | |
| | | | |
| | | cache_position (): map_ (0) {} | |
| | | cache_position (map& m, const iterator& p): map_ (&m), pos_ (p) {} | |
| | | | |
| | | cache_position& | |
| | | operator= (const cache_position& p) | |
| | | { | |
| | | // It might not be ok to use an uninitialized iterator on the rhs. | |
| | | // | |
| | | if (p.map_ != 0) | |
| | | pos_ = p.pos_; | |
| | | map_ = p.map_; | |
| | | return *this; | |
| | | } | |
| | | | |
| | | map* map_; | |
| | | iterator pos_; | |
| | | }; | |
| | | | |
| | | // The following cache management functions are all static to | |
| | | // allow for a custom notion of a current session. The erase() | |
| | | // function is called to remove the object if the operation | |
| | | // that caused it to be inserted (e.g., load) failed. | |
| | | // | |
| | | template <typename T> | |
| | | static cache_position<T> | |
| | | _cache_insert (database_type&, | |
| | | const typename object_traits<T>::id_type&, | |
| | | const typename object_traits<T>::pointer_type&); | |
| | | | |
| | | template <typename T> | |
| | | static typename object_traits<T>::pointer_type | |
| | | _cache_find (database_type&, const typename object_traits<T>::id_type&) | |
| | | ; | |
| | | | |
| | | template <typename T> | |
| | | static void | |
| | | _cache_erase (const cache_position<T>&); | |
| | | | |
| | | // Notifications. These are called after per-object callbacks for | |
| | | // post_{persist, load, update, erase} events. | |
| | | // | |
| | | template <typename T> | |
| | | static void | |
| | | _cache_persist (const cache_position<T>&) {} | |
| | | | |
| | | template <typename T> | |
| | | static void | |
| | | _cache_load (const cache_position<T>&) {} | |
| | | | |
| | | template <typename T> | |
| | | static void | |
| | | _cache_update (database_type&, const T&) {} | |
| | | | |
| | | template <typename T> | |
| | | static void | |
| | | _cache_erase (database_type&, const typename object_traits<T>::id_type& | |
| | | ); | |
| | | | |
| | | protected: | |
| database_map db_map_; | | database_map db_map_; | |
| }; | | }; | |
| } | | } | |
| | | | |
| #include <odb/session.ixx> | | #include <odb/session.ixx> | |
| #include <odb/session.txx> | | #include <odb/session.txx> | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| #endif // ODB_SESSION_HXX | | #endif // ODB_SESSION_HXX | |
| | | | |
End of changes. 14 change blocks. |
| 29 lines changed or deleted | | 109 lines changed or added | |
|
| simple-object-result.hxx | | simple-object-result.hxx | |
| // file : odb/simple-object-result.hxx | | // file : odb/simple-object-result.hxx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_SIMPLE_OBJECT_RESULT_HXX | | #ifndef ODB_SIMPLE_OBJECT_RESULT_HXX | |
| #define ODB_SIMPLE_OBJECT_RESULT_HXX | | #define ODB_SIMPLE_OBJECT_RESULT_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
| #include <cstddef> // std::size_t | | #include <cstddef> // std::size_t | |
| #include <utility> // std::move | | #include <utility> // std::move | |
| | | | |
| #include <odb/forward.hxx> | | #include <odb/forward.hxx> | |
| #include <odb/traits.hxx> | | #include <odb/traits.hxx> | |
| #include <odb/result.hxx> | | #include <odb/result.hxx> | |
| #include <odb/object-result.hxx> | | #include <odb/object-result.hxx> | |
| #include <odb/pointer-traits.hxx> | | #include <odb/pointer-traits.hxx> | |
| | | | |
| #include <odb/details/config.hxx> // ODB_CXX11 | | #include <odb/details/config.hxx> // ODB_CXX11 | |
|
| #include <odb/details/shared-ptr.hxx> | | | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| // Implementation for non-polymorphic objects with object id. | | // Implementation for non-polymorphic objects with object id. | |
| // | | // | |
| template <typename T> | | template <typename T> | |
|
| class object_result_impl: public details::shared_base | | class object_result_impl: public result_impl | |
| { | | { | |
|
| public: | | | |
| virtual | | | |
| ~object_result_impl (); | | | |
| | | | |
| protected: | | protected: | |
|
| typedef odb::database database_type; | | | |
| | | | |
| // In result_impl, T is always non-const and the same as object_type. | | // In result_impl, T is always non-const and the same as object_type. | |
| // | | // | |
| typedef T object_type; | | typedef T object_type; | |
| typedef odb::object_traits<object_type> object_traits; | | typedef odb::object_traits<object_type> object_traits; | |
| typedef typename object_traits::id_type id_type; | | typedef typename object_traits::id_type id_type; | |
| | | | |
| typedef typename object_traits::pointer_type pointer_type; | | typedef typename object_traits::pointer_type pointer_type; | |
| typedef odb::pointer_traits<pointer_type> pointer_traits; | | typedef odb::pointer_traits<pointer_type> pointer_traits; | |
| | | | |
| friend class result<T>; | | friend class result<T>; | |
| friend class result<const T>; | | friend class result<const T>; | |
| friend class result_iterator<T, class_object>; | | friend class result_iterator<T, class_object>; | |
| friend class result_iterator<const T, class_object>; | | friend class result_iterator<const T, class_object>; | |
| friend class object_result_iterator<T, id_type, false>; | | friend class object_result_iterator<T, id_type, false>; | |
| friend class object_result_iterator<const T, id_type, false>; | | friend class object_result_iterator<const T, id_type, false>; | |
| | | | |
| protected: | | protected: | |
|
| object_result_impl (database_type& db) | | object_result_impl (odb::connection& conn) | |
| : begin_ (true), end_ (false), db_ (db), current_ () | | : result_impl (conn), begin_ (true), end_ (false), current_ () | |
| { | | | |
| } | | | |
| | | | |
| database_type& | | | |
| database () const | | | |
| { | | { | |
|
| return db_; | | | |
| } | | } | |
| | | | |
| // To make this work with all kinds of pointers (raw, std::auto_ptr, | | // To make this work with all kinds of pointers (raw, std::auto_ptr, | |
| // shared), we need to make sure we don't make any copies of the | | // shared), we need to make sure we don't make any copies of the | |
| // pointer on the return path. | | // pointer on the return path. | |
| // | | // | |
| pointer_type& | | pointer_type& | |
| current () | | current () | |
| { | | { | |
| if (pointer_traits::null_ptr (current_) && !end_) | | if (pointer_traits::null_ptr (current_) && !end_) | |
| | | | |
| skipping to change at line 161 | | skipping to change at line 148 | |
| #endif | | #endif | |
| | | | |
| bool begin_; | | bool begin_; | |
| bool end_; | | bool end_; | |
| | | | |
| private: | | private: | |
| void | | void | |
| load (); | | load (); | |
| | | | |
| private: | | private: | |
|
| database_type& db_; | | | |
| pointer_type current_; | | pointer_type current_; | |
| typename pointer_traits::guard guard_; | | typename pointer_traits::guard guard_; | |
| }; | | }; | |
| | | | |
| template <typename T, typename ID> | | template <typename T, typename ID> | |
| class object_result_iterator<T, ID, false> | | class object_result_iterator<T, ID, false> | |
| { | | { | |
| public: | | public: | |
| // T can be const T while object_type is always non-const. | | // T can be const T while object_type is always non-const. | |
| // | | // | |
| | | | |
End of changes. 8 change blocks. |
| 18 lines changed or deleted | | 4 lines changed or added | |
|
| std-map-traits.hxx | | std-map-traits.hxx | |
| // file : odb/std-map-traits.hxx | | // file : odb/std-map-traits.hxx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_STD_MAP_TRAITS_HXX | | #ifndef ODB_STD_MAP_TRAITS_HXX | |
| #define ODB_STD_MAP_TRAITS_HXX | | #define ODB_STD_MAP_TRAITS_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
| #include <map> | | #include <map> | |
| #include <utility> // std::move | | #include <utility> // std::move | |
| | | | |
| #include <odb/container-traits.hxx> | | #include <odb/container-traits.hxx> | |
| #include <odb/details/config.hxx> // ODB_CXX11 | | #include <odb/details/config.hxx> // ODB_CXX11 | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| template <typename K, typename V, typename C, typename A> | | template <typename K, typename V, typename C, typename A> | |
| class access::container_traits<std::map<K, V, C, A> > | | class access::container_traits<std::map<K, V, C, A> > | |
| { | | { | |
| public: | | public: | |
|
| static container_kind const kind = ck_map; | | static const container_kind kind = ck_map; | |
| | | static const bool smart = false; | |
| | | | |
| typedef std::map<K, V, C, A> container_type; | | typedef std::map<K, V, C, A> container_type; | |
| | | | |
| typedef K key_type; | | typedef K key_type; | |
| typedef V value_type; | | typedef V value_type; | |
| typedef typename container_type::value_type pair_type; | | typedef typename container_type::value_type pair_type; | |
| | | | |
| typedef map_functions<key_type, value_type> functions; | | typedef map_functions<key_type, value_type> functions; | |
| | | | |
| public: | | public: | |
| static void | | static void | |
| persist (const container_type& c, const functions& f) | | persist (const container_type& c, const functions& f) | |
| { | | { | |
| for (typename container_type::const_iterator i (c.begin ()), | | for (typename container_type::const_iterator i (c.begin ()), | |
| e (c.end ()); i != e; ++i) | | e (c.end ()); i != e; ++i) | |
|
| f.insert_one (i->first, i->second); | | f.insert (i->first, i->second); | |
| } | | } | |
| | | | |
| static void | | static void | |
| load (container_type& c, bool more, const functions& f) | | load (container_type& c, bool more, const functions& f) | |
| { | | { | |
| c.clear (); | | c.clear (); | |
| | | | |
| while (more) | | while (more) | |
| { | | { | |
| key_type k; | | key_type k; | |
| value_type v; | | value_type v; | |
|
| more = f.load_all (k, v); | | more = f.select (k, v); | |
| #ifdef ODB_CXX11 | | #ifdef ODB_CXX11 | |
| c.insert (pair_type (std::move (k), std::move (v))); | | c.insert (pair_type (std::move (k), std::move (v))); | |
| #else | | #else | |
| c.insert (pair_type (k, v)); | | c.insert (pair_type (k, v)); | |
| #endif | | #endif | |
| } | | } | |
| } | | } | |
| | | | |
| static void | | static void | |
| update (const container_type& c, const functions& f) | | update (const container_type& c, const functions& f) | |
| { | | { | |
|
| f.delete_all (); | | f.delete_ (); | |
| | | | |
| for (typename container_type::const_iterator i (c.begin ()), | | for (typename container_type::const_iterator i (c.begin ()), | |
| e (c.end ()); i != e; ++i) | | e (c.end ()); i != e; ++i) | |
|
| f.insert_one (i->first, i->second); | | f.insert (i->first, i->second); | |
| } | | } | |
| | | | |
| static void | | static void | |
| erase (const functions& f) | | erase (const functions& f) | |
| { | | { | |
|
| f.delete_all (); | | f.delete_ (); | |
| } | | } | |
| }; | | }; | |
| | | | |
| // C++03 does not guarantee insertion order of equal values but C++11 | | // C++03 does not guarantee insertion order of equal values but C++11 | |
| // changes that. The current implementation in the generated code does | | // changes that. The current implementation in the generated code does | |
| // not guarantee this either. | | // not guarantee this either. | |
| // | | // | |
| template <typename K, typename V, typename C, typename A> | | template <typename K, typename V, typename C, typename A> | |
| class access::container_traits<std::multimap<K, V, C, A> > | | class access::container_traits<std::multimap<K, V, C, A> > | |
| { | | { | |
| public: | | public: | |
|
| static container_kind const kind = ck_multimap; | | static const container_kind kind = ck_multimap; | |
| | | static const bool smart = false; | |
| | | | |
| typedef std::multimap<K, V, C, A> container_type; | | typedef std::multimap<K, V, C, A> container_type; | |
| | | | |
| typedef K key_type; | | typedef K key_type; | |
| typedef V value_type; | | typedef V value_type; | |
| typedef typename container_type::value_type pair_type; | | typedef typename container_type::value_type pair_type; | |
| | | | |
| typedef map_functions<key_type, value_type> functions; | | typedef map_functions<key_type, value_type> functions; | |
| | | | |
| public: | | public: | |
| static void | | static void | |
| persist (const container_type& c, const functions& f) | | persist (const container_type& c, const functions& f) | |
| { | | { | |
| for (typename container_type::const_iterator i (c.begin ()), | | for (typename container_type::const_iterator i (c.begin ()), | |
| e (c.end ()); i != e; ++i) | | e (c.end ()); i != e; ++i) | |
|
| f.insert_one (i->first, i->second); | | f.insert (i->first, i->second); | |
| } | | } | |
| | | | |
| static void | | static void | |
| load (container_type& c, bool more, const functions& f) | | load (container_type& c, bool more, const functions& f) | |
| { | | { | |
| c.clear (); | | c.clear (); | |
| | | | |
| while (more) | | while (more) | |
| { | | { | |
| key_type k; | | key_type k; | |
| value_type v; | | value_type v; | |
|
| more = f.load_all (k, v); | | more = f.select (k, v); | |
| #ifdef ODB_CXX11 | | #ifdef ODB_CXX11 | |
| c.insert (pair_type (std::move (k), std::move (v))); | | c.insert (pair_type (std::move (k), std::move (v))); | |
| #else | | #else | |
| c.insert (pair_type (k, v)); | | c.insert (pair_type (k, v)); | |
| #endif | | #endif | |
| } | | } | |
| } | | } | |
| | | | |
| static void | | static void | |
| update (const container_type& c, const functions& f) | | update (const container_type& c, const functions& f) | |
| { | | { | |
|
| f.delete_all (); | | f.delete_ (); | |
| | | | |
| for (typename container_type::const_iterator i (c.begin ()), | | for (typename container_type::const_iterator i (c.begin ()), | |
| e (c.end ()); i != e; ++i) | | e (c.end ()); i != e; ++i) | |
|
| f.insert_one (i->first, i->second); | | f.insert (i->first, i->second); | |
| } | | } | |
| | | | |
| static void | | static void | |
| erase (const functions& f) | | erase (const functions& f) | |
| { | | { | |
|
| f.delete_all (); | | f.delete_ (); | |
| } | | } | |
| }; | | }; | |
| } | | } | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| #endif // ODB_STD_MAP_TRAITS_HXX | | #endif // ODB_STD_MAP_TRAITS_HXX | |
| | | | |
End of changes. 13 change blocks. |
| 13 lines changed or deleted | | 15 lines changed or added | |
|
| std-set-traits.hxx | | std-set-traits.hxx | |
| // file : odb/std-set-traits.hxx | | // file : odb/std-set-traits.hxx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_STD_SET_TRAITS_HXX | | #ifndef ODB_STD_SET_TRAITS_HXX | |
| #define ODB_STD_SET_TRAITS_HXX | | #define ODB_STD_SET_TRAITS_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
| #include <set> | | #include <set> | |
| #include <utility> // std::move | | #include <utility> // std::move | |
| | | | |
| #include <odb/container-traits.hxx> | | #include <odb/container-traits.hxx> | |
| #include <odb/details/config.hxx> // ODB_CXX11 | | #include <odb/details/config.hxx> // ODB_CXX11 | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| template <typename V, typename C, typename A> | | template <typename V, typename C, typename A> | |
| class access::container_traits<std::set<V, C, A> > | | class access::container_traits<std::set<V, C, A> > | |
| { | | { | |
| public: | | public: | |
|
| static container_kind const kind = ck_set; | | static const container_kind kind = ck_set; | |
| | | static const bool smart = false; | |
| | | | |
| typedef std::set<V, C, A> container_type; | | typedef std::set<V, C, A> container_type; | |
| typedef V value_type; | | typedef V value_type; | |
| | | | |
| typedef set_functions<value_type> functions; | | typedef set_functions<value_type> functions; | |
| | | | |
| public: | | public: | |
| static void | | static void | |
| persist (const container_type& c, const functions& f) | | persist (const container_type& c, const functions& f) | |
| { | | { | |
| for (typename container_type::const_iterator i (c.begin ()), | | for (typename container_type::const_iterator i (c.begin ()), | |
| e (c.end ()); i != e; ++i) | | e (c.end ()); i != e; ++i) | |
|
| f.insert_one (*i); | | f.insert (*i); | |
| } | | } | |
| | | | |
| static void | | static void | |
| load (container_type& c, bool more, const functions& f) | | load (container_type& c, bool more, const functions& f) | |
| { | | { | |
| c.clear (); | | c.clear (); | |
| | | | |
| while (more) | | while (more) | |
| { | | { | |
| value_type v; | | value_type v; | |
|
| more = f.load_all (v); | | more = f.select (v); | |
| #ifdef ODB_CXX11 | | #ifdef ODB_CXX11 | |
| c.insert (std::move (v)); | | c.insert (std::move (v)); | |
| #else | | #else | |
| c.insert (v); | | c.insert (v); | |
| #endif | | #endif | |
| } | | } | |
| } | | } | |
| | | | |
| static void | | static void | |
| update (const container_type& c, const functions& f) | | update (const container_type& c, const functions& f) | |
| { | | { | |
|
| f.delete_all (); | | f.delete_ (); | |
| | | | |
| for (typename container_type::const_iterator i (c.begin ()), | | for (typename container_type::const_iterator i (c.begin ()), | |
| e (c.end ()); i != e; ++i) | | e (c.end ()); i != e; ++i) | |
|
| f.insert_one (*i); | | f.insert (*i); | |
| } | | } | |
| | | | |
| static void | | static void | |
| erase (const functions& f) | | erase (const functions& f) | |
| { | | { | |
|
| f.delete_all (); | | f.delete_ (); | |
| } | | } | |
| }; | | }; | |
| | | | |
| // C++03 does not guarantee insertion order of equal values but C++11 | | // C++03 does not guarantee insertion order of equal values but C++11 | |
| // changes that. The current implementation in the generated code does | | // changes that. The current implementation in the generated code does | |
| // not guarantee this either. | | // not guarantee this either. | |
| // | | // | |
| template <typename V, typename C, typename A> | | template <typename V, typename C, typename A> | |
| class access::container_traits<std::multiset<V, C, A> > | | class access::container_traits<std::multiset<V, C, A> > | |
| { | | { | |
| public: | | public: | |
|
| static container_kind const kind = ck_multiset; | | static const container_kind kind = ck_multiset; | |
| | | static const bool smart = false; | |
| | | | |
| typedef std::multiset<V, C, A> container_type; | | typedef std::multiset<V, C, A> container_type; | |
| typedef V value_type; | | typedef V value_type; | |
| | | | |
| typedef set_functions<value_type> functions; | | typedef set_functions<value_type> functions; | |
| | | | |
| public: | | public: | |
| static void | | static void | |
| persist (const container_type& c, const functions& f) | | persist (const container_type& c, const functions& f) | |
| { | | { | |
| for (typename container_type::const_iterator i (c.begin ()), | | for (typename container_type::const_iterator i (c.begin ()), | |
| e (c.end ()); i != e; ++i) | | e (c.end ()); i != e; ++i) | |
|
| f.insert_one (*i); | | f.insert (*i); | |
| } | | } | |
| | | | |
| static void | | static void | |
| load (container_type& c, bool more, const functions& f) | | load (container_type& c, bool more, const functions& f) | |
| { | | { | |
| c.clear (); | | c.clear (); | |
| | | | |
| while (more) | | while (more) | |
| { | | { | |
| value_type v; | | value_type v; | |
|
| more = f.load_all (v); | | more = f.select (v); | |
| #ifdef ODB_CXX11 | | #ifdef ODB_CXX11 | |
| c.insert (std::move (v)); | | c.insert (std::move (v)); | |
| #else | | #else | |
| c.insert (v); | | c.insert (v); | |
| #endif | | #endif | |
| } | | } | |
| } | | } | |
| | | | |
| static void | | static void | |
| update (const container_type& c, const functions& f) | | update (const container_type& c, const functions& f) | |
| { | | { | |
|
| f.delete_all (); | | f.delete_ (); | |
| | | | |
| for (typename container_type::const_iterator i (c.begin ()), | | for (typename container_type::const_iterator i (c.begin ()), | |
| e (c.end ()); i != e; ++i) | | e (c.end ()); i != e; ++i) | |
|
| f.insert_one (*i); | | f.insert (*i); | |
| } | | } | |
| | | | |
| static void | | static void | |
| erase (const functions& f) | | erase (const functions& f) | |
| { | | { | |
|
| f.delete_all (); | | f.delete_ (); | |
| } | | } | |
| }; | | }; | |
| } | | } | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| #endif // ODB_STD_SET_TRAITS_HXX | | #endif // ODB_STD_SET_TRAITS_HXX | |
| | | | |
End of changes. 13 change blocks. |
| 13 lines changed or deleted | | 15 lines changed or added | |
|
| std-unordered-map-traits.hxx | | std-unordered-map-traits.hxx | |
| // file : odb/std-unordered-map-traits.hxx | | // file : odb/std-unordered-map-traits.hxx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_STD_UNORDERED_MAP_TRAITS_HXX | | #ifndef ODB_STD_UNORDERED_MAP_TRAITS_HXX | |
| #define ODB_STD_UNORDERED_MAP_TRAITS_HXX | | #define ODB_STD_UNORDERED_MAP_TRAITS_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
| #include <utility> // std::move | | #include <utility> // std::move | |
| #include <unordered_map> | | #include <unordered_map> | |
| | | | |
| #include <odb/container-traits.hxx> | | #include <odb/container-traits.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| template <typename K, typename V, typename H, typename P, typename A> | | template <typename K, typename V, typename H, typename P, typename A> | |
| class access::container_traits<std::unordered_map<K, V, H, P, A>> | | class access::container_traits<std::unordered_map<K, V, H, P, A>> | |
| { | | { | |
| public: | | public: | |
|
| static container_kind const kind = ck_map; | | static const container_kind kind = ck_map; | |
| | | static const bool smart = false; | |
| | | | |
| typedef std::unordered_map<K, V, H, P, A> container_type; | | typedef std::unordered_map<K, V, H, P, A> container_type; | |
| | | | |
| typedef K key_type; | | typedef K key_type; | |
| typedef V value_type; | | typedef V value_type; | |
| typedef typename container_type::value_type pair_type; | | typedef typename container_type::value_type pair_type; | |
| | | | |
| typedef map_functions<key_type, value_type> functions; | | typedef map_functions<key_type, value_type> functions; | |
| | | | |
| public: | | public: | |
| static void | | static void | |
| persist (const container_type& c, const functions& f) | | persist (const container_type& c, const functions& f) | |
| { | | { | |
| for (typename container_type::const_iterator i (c.begin ()), | | for (typename container_type::const_iterator i (c.begin ()), | |
| e (c.end ()); i != e; ++i) | | e (c.end ()); i != e; ++i) | |
|
| f.insert_one (i->first, i->second); | | f.insert (i->first, i->second); | |
| } | | } | |
| | | | |
| static void | | static void | |
| load (container_type& c, bool more, const functions& f) | | load (container_type& c, bool more, const functions& f) | |
| { | | { | |
| c.clear (); | | c.clear (); | |
| | | | |
| while (more) | | while (more) | |
| { | | { | |
| key_type k; | | key_type k; | |
| value_type v; | | value_type v; | |
|
| more = f.load_all (k, v); | | more = f.select (k, v); | |
| c.insert (pair_type (std::move (k), std::move (v))); | | c.insert (pair_type (std::move (k), std::move (v))); | |
| } | | } | |
| } | | } | |
| | | | |
| static void | | static void | |
| update (const container_type& c, const functions& f) | | update (const container_type& c, const functions& f) | |
| { | | { | |
|
| f.delete_all (); | | f.delete_ (); | |
| | | | |
| for (typename container_type::const_iterator i (c.begin ()), | | for (typename container_type::const_iterator i (c.begin ()), | |
| e (c.end ()); i != e; ++i) | | e (c.end ()); i != e; ++i) | |
|
| f.insert_one (i->first, i->second); | | f.insert (i->first, i->second); | |
| } | | } | |
| | | | |
| static void | | static void | |
| erase (const functions& f) | | erase (const functions& f) | |
| { | | { | |
|
| f.delete_all (); | | f.delete_ (); | |
| } | | } | |
| }; | | }; | |
| | | | |
| // @@ Does multimap preserve insertion order of equal elements? The | | // @@ Does multimap preserve insertion order of equal elements? The | |
| // current implementation in the generated code does not guarantee | | // current implementation in the generated code does not guarantee | |
| // this. | | // this. | |
| // | | // | |
| template <typename K, typename V, typename H, typename P, typename A> | | template <typename K, typename V, typename H, typename P, typename A> | |
| class access::container_traits<std::unordered_multimap<K, V, H, P, A>> | | class access::container_traits<std::unordered_multimap<K, V, H, P, A>> | |
| { | | { | |
| public: | | public: | |
|
| static container_kind const kind = ck_multimap; | | static const container_kind kind = ck_multimap; | |
| | | static const bool smart = false; | |
| | | | |
| typedef std::unordered_multimap<K, V, H, P, A> container_type; | | typedef std::unordered_multimap<K, V, H, P, A> container_type; | |
| | | | |
| typedef K key_type; | | typedef K key_type; | |
| typedef V value_type; | | typedef V value_type; | |
| typedef typename container_type::value_type pair_type; | | typedef typename container_type::value_type pair_type; | |
| | | | |
| typedef map_functions<key_type, value_type> functions; | | typedef map_functions<key_type, value_type> functions; | |
| | | | |
| public: | | public: | |
| static void | | static void | |
| persist (const container_type& c, const functions& f) | | persist (const container_type& c, const functions& f) | |
| { | | { | |
| for (typename container_type::const_iterator i (c.begin ()), | | for (typename container_type::const_iterator i (c.begin ()), | |
| e (c.end ()); i != e; ++i) | | e (c.end ()); i != e; ++i) | |
|
| f.insert_one (i->first, i->second); | | f.insert (i->first, i->second); | |
| } | | } | |
| | | | |
| static void | | static void | |
| load (container_type& c, bool more, const functions& f) | | load (container_type& c, bool more, const functions& f) | |
| { | | { | |
| c.clear (); | | c.clear (); | |
| | | | |
| while (more) | | while (more) | |
| { | | { | |
| key_type k; | | key_type k; | |
| value_type v; | | value_type v; | |
|
| more = f.load_all (k, v); | | more = f.select (k, v); | |
| c.insert (pair_type (std::move (k), std::move (v))); | | c.insert (pair_type (std::move (k), std::move (v))); | |
| } | | } | |
| } | | } | |
| | | | |
| static void | | static void | |
| update (const container_type& c, const functions& f) | | update (const container_type& c, const functions& f) | |
| { | | { | |
|
| f.delete_all (); | | f.delete_ (); | |
| | | | |
| for (typename container_type::const_iterator i (c.begin ()), | | for (typename container_type::const_iterator i (c.begin ()), | |
| e (c.end ()); i != e; ++i) | | e (c.end ()); i != e; ++i) | |
|
| f.insert_one (i->first, i->second); | | f.insert (i->first, i->second); | |
| } | | } | |
| | | | |
| static void | | static void | |
| erase (const functions& f) | | erase (const functions& f) | |
| { | | { | |
|
| f.delete_all (); | | f.delete_ (); | |
| } | | } | |
| }; | | }; | |
| } | | } | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| #endif // ODB_STD_UNORDERED_MAP_TRAITS_HXX | | #endif // ODB_STD_UNORDERED_MAP_TRAITS_HXX | |
| | | | |
End of changes. 13 change blocks. |
| 13 lines changed or deleted | | 15 lines changed or added | |
|
| std-unordered-set-traits.hxx | | std-unordered-set-traits.hxx | |
| // file : odb/std-unordered-set-traits.hxx | | // file : odb/std-unordered-set-traits.hxx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_STD_UNORDERED_SET_TRAITS_HXX | | #ifndef ODB_STD_UNORDERED_SET_TRAITS_HXX | |
| #define ODB_STD_UNORDERED_SET_TRAITS_HXX | | #define ODB_STD_UNORDERED_SET_TRAITS_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
| #include <utility> // std::move | | #include <utility> // std::move | |
| #include <unordered_set> | | #include <unordered_set> | |
| | | | |
| #include <odb/container-traits.hxx> | | #include <odb/container-traits.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| template <typename V, typename H, typename P, typename A> | | template <typename V, typename H, typename P, typename A> | |
| class access::container_traits<std::unordered_set<V, H, P, A>> | | class access::container_traits<std::unordered_set<V, H, P, A>> | |
| { | | { | |
| public: | | public: | |
|
| static container_kind const kind = ck_set; | | static const container_kind kind = ck_set; | |
| | | static const bool smart = false; | |
| | | | |
| typedef std::unordered_set<V, H, P, A> container_type; | | typedef std::unordered_set<V, H, P, A> container_type; | |
| typedef V value_type; | | typedef V value_type; | |
| | | | |
| typedef set_functions<value_type> functions; | | typedef set_functions<value_type> functions; | |
| | | | |
| public: | | public: | |
| static void | | static void | |
| persist (const container_type& c, const functions& f) | | persist (const container_type& c, const functions& f) | |
| { | | { | |
| for (typename container_type::const_iterator i (c.begin ()), | | for (typename container_type::const_iterator i (c.begin ()), | |
| e (c.end ()); i != e; ++i) | | e (c.end ()); i != e; ++i) | |
|
| f.insert_one (*i); | | f.insert (*i); | |
| } | | } | |
| | | | |
| static void | | static void | |
| load (container_type& c, bool more, const functions& f) | | load (container_type& c, bool more, const functions& f) | |
| { | | { | |
| c.clear (); | | c.clear (); | |
| | | | |
| while (more) | | while (more) | |
| { | | { | |
| value_type v; | | value_type v; | |
|
| more = f.load_all (v); | | more = f.select (v); | |
| c.insert (std::move (v)); | | c.insert (std::move (v)); | |
| } | | } | |
| } | | } | |
| | | | |
| static void | | static void | |
| update (const container_type& c, const functions& f) | | update (const container_type& c, const functions& f) | |
| { | | { | |
|
| f.delete_all (); | | f.delete_ (); | |
| | | | |
| for (typename container_type::const_iterator i (c.begin ()), | | for (typename container_type::const_iterator i (c.begin ()), | |
| e (c.end ()); i != e; ++i) | | e (c.end ()); i != e; ++i) | |
|
| f.insert_one (*i); | | f.insert (*i); | |
| } | | } | |
| | | | |
| static void | | static void | |
| erase (const functions& f) | | erase (const functions& f) | |
| { | | { | |
|
| f.delete_all (); | | f.delete_ (); | |
| } | | } | |
| }; | | }; | |
| | | | |
| // @@ Does multiset preserve insertion order of equal elements? The | | // @@ Does multiset preserve insertion order of equal elements? The | |
| // current implementation in the generated code does not guarantee | | // current implementation in the generated code does not guarantee | |
| // this. | | // this. | |
| // | | // | |
| template <typename V, typename H, typename P, typename A> | | template <typename V, typename H, typename P, typename A> | |
| class access::container_traits<std::unordered_multiset<V, H, P, A>> | | class access::container_traits<std::unordered_multiset<V, H, P, A>> | |
| { | | { | |
| public: | | public: | |
|
| static container_kind const kind = ck_multiset; | | static const container_kind kind = ck_multiset; | |
| | | static const bool smart = false; | |
| | | | |
| typedef std::unordered_multiset<V, H, P, A> container_type; | | typedef std::unordered_multiset<V, H, P, A> container_type; | |
| typedef V value_type; | | typedef V value_type; | |
| | | | |
| typedef set_functions<value_type> functions; | | typedef set_functions<value_type> functions; | |
| | | | |
| public: | | public: | |
| static void | | static void | |
| persist (const container_type& c, const functions& f) | | persist (const container_type& c, const functions& f) | |
| { | | { | |
| for (typename container_type::const_iterator i (c.begin ()), | | for (typename container_type::const_iterator i (c.begin ()), | |
| e (c.end ()); i != e; ++i) | | e (c.end ()); i != e; ++i) | |
|
| f.insert_one (*i); | | f.insert (*i); | |
| } | | } | |
| | | | |
| static void | | static void | |
| load (container_type& c, bool more, const functions& f) | | load (container_type& c, bool more, const functions& f) | |
| { | | { | |
| c.clear (); | | c.clear (); | |
| | | | |
| while (more) | | while (more) | |
| { | | { | |
| value_type v; | | value_type v; | |
|
| more = f.load_all (v); | | more = f.select (v); | |
| c.insert (std::move (v)); | | c.insert (std::move (v)); | |
| } | | } | |
| } | | } | |
| | | | |
| static void | | static void | |
| update (const container_type& c, const functions& f) | | update (const container_type& c, const functions& f) | |
| { | | { | |
|
| f.delete_all (); | | f.delete_ (); | |
| | | | |
| for (typename container_type::const_iterator i (c.begin ()), | | for (typename container_type::const_iterator i (c.begin ()), | |
| e (c.end ()); i != e; ++i) | | e (c.end ()); i != e; ++i) | |
|
| f.insert_one (*i); | | f.insert (*i); | |
| } | | } | |
| | | | |
| static void | | static void | |
| erase (const functions& f) | | erase (const functions& f) | |
| { | | { | |
|
| f.delete_all (); | | f.delete_ (); | |
| } | | } | |
| }; | | }; | |
| } | | } | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| #endif // ODB_STD_UNORDERED_SET_TRAITS_HXX | | #endif // ODB_STD_UNORDERED_SET_TRAITS_HXX | |
| | | | |
End of changes. 13 change blocks. |
| 13 lines changed or deleted | | 15 lines changed or added | |
|
| traits.hxx | | traits.hxx | |
| // file : odb/traits.hxx | | // file : odb/traits.hxx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_TRAITS_HXX | | #ifndef ODB_TRAITS_HXX | |
| #define ODB_TRAITS_HXX | | #define ODB_TRAITS_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
| #include <odb/forward.hxx> | | #include <odb/forward.hxx> | |
| #include <odb/pointer-traits.hxx> | | #include <odb/pointer-traits.hxx> | |
| | | | |
| | | | |
| skipping to change at line 81 | | skipping to change at line 81 | |
| }; | | }; | |
| }; | | }; | |
| | | | |
| // | | // | |
| // class_traits | | // class_traits | |
| // | | // | |
| enum class_kind | | enum class_kind | |
| { | | { | |
| class_object, | | class_object, | |
| class_view, | | class_view, | |
|
| class_composite, | | | |
| class_other | | class_other | |
| }; | | }; | |
| | | | |
| template <typename T> | | template <typename T> | |
| struct class_traits | | struct class_traits | |
| { | | { | |
| static const class_kind kind = class_other; | | static const class_kind kind = class_other; | |
| }; | | }; | |
| | | | |
| template <typename T> | | template <typename T> | |
| struct class_traits<const T> | | struct class_traits<const T> | |
| { | | { | |
| static const class_kind kind = class_traits<T>::kind; | | static const class_kind kind = class_traits<T>::kind; | |
| }; | | }; | |
| | | | |
| // | | // | |
| // object_traits | | // object_traits | |
| // | | // | |
| | | | |
| template <typename T> | | template <typename T> | |
|
| | | // | |
| | | // If a C++ compiler issues an error pointing to this struct and | |
| | | // saying that it is incomplete, then you are most likely trying to | |
| | | // perform a database operation on a C++ type that is not a persistent | |
| | | // object. Or you forgot to include the corresponding -odb.hxx file. | |
| | | // | |
| struct object_traits: | | struct object_traits: | |
| access::object_traits<T>, | | access::object_traits<T>, | |
| access::object_factory<T, typename access::object_traits<T>::pointer_ty
pe> | | access::object_factory<T, typename access::object_traits<T>::pointer_ty
pe> | |
| { | | { | |
|
| // | | | |
| // If a C++ compiler issues an error pointing to this struct and | | | |
| // saying that it is incomplete, then you are most likely trying to | | | |
| // perform a database operation on a C++ type that is not a persistent | | | |
| // object. Or you forgot to include the corresponding -odb.hxx file. | | | |
| // | | | |
| | | | |
| typedef | | typedef | |
| odb::pointer_traits<typename access::object_traits<T>::pointer_type> | | odb::pointer_traits<typename access::object_traits<T>::pointer_type> | |
| pointer_traits; | | pointer_traits; | |
| | | | |
| typedef typename access::object_traits<T>::object_type object_type; | | typedef typename access::object_traits<T>::object_type object_type; | |
| typedef typename access::object_traits<T>::pointer_type pointer_type; | | typedef typename access::object_traits<T>::pointer_type pointer_type; | |
| typedef typename pointer_traits::const_pointer_type const_pointer_type; | | typedef typename pointer_traits::const_pointer_type const_pointer_type; | |
| }; | | }; | |
| | | | |
| // Specialization for const objects. It only defines the id, object, | | // Specialization for const objects. It only defines the id, object, | |
| | | | |
| skipping to change at line 163 | | skipping to change at line 161 | |
| struct id_type {}; | | struct id_type {}; | |
| }; | | }; | |
| | | | |
| template <typename T> | | template <typename T> | |
| struct object_traits<T* const> | | struct object_traits<T* const> | |
| { | | { | |
| struct id_type {}; | | struct id_type {}; | |
| }; | | }; | |
| | | | |
| template <typename T, template <typename> class P> | | template <typename T, template <typename> class P> | |
|
| struct object_traits< P<T> > | | struct object_traits<P<T> > | |
| { | | { | |
| struct id_type {}; | | struct id_type {}; | |
| }; | | }; | |
| | | | |
| template <typename T, typename A1, template <typename, typename> class P> | | template <typename T, typename A1, template <typename, typename> class P> | |
|
| struct object_traits< P<T, A1> > | | struct object_traits<P<T, A1> > | |
| { | | { | |
| struct id_type {}; | | struct id_type {}; | |
| }; | | }; | |
| | | | |
| template <typename T, template <typename> class P> | | template <typename T, template <typename> class P> | |
|
| struct object_traits< const P<T> > | | struct object_traits<const P<T> > | |
| { | | { | |
| struct id_type {}; | | struct id_type {}; | |
| }; | | }; | |
| | | | |
| template <typename T, typename A1, template <typename, typename> class P> | | template <typename T, typename A1, template <typename, typename> class P> | |
|
| struct object_traits< const P<T, A1> > | | struct object_traits<const P<T, A1> > | |
| { | | { | |
| struct id_type {}; | | struct id_type {}; | |
| }; | | }; | |
| | | | |
|
| | | template <typename T, database_id DB> | |
| | | // | |
| | | // If a C++ compiler issues an error pointing to this struct and | |
| | | // saying that it is incomplete, then you are most likely trying to | |
| | | // perform a database operation on a C++ type that is not a persistent | |
| | | // object. Or you forgot to include the corresponding -odb.hxx file. | |
| | | // | |
| | | struct object_traits_impl: | |
| | | access::object_traits_impl<T, DB>, | |
| | | access::object_factory<T, typename access::object_traits<T>::pointer_ty | |
| | | pe> | |
| | | { | |
| | | typedef | |
| | | odb::pointer_traits<typename access::object_traits<T>::pointer_type> | |
| | | pointer_traits; | |
| | | | |
| | | typedef typename access::object_traits<T>::object_type object_type; | |
| | | typedef typename access::object_traits<T>::pointer_type pointer_type; | |
| | | typedef typename pointer_traits::const_pointer_type const_pointer_type; | |
| | | }; | |
| | | | |
| // | | // | |
| // view_traits | | // view_traits | |
| // | | // | |
| | | | |
| template <typename T> | | template <typename T> | |
|
| | | // | |
| | | // If a C++ compiler issues an error pointing to this struct and | |
| | | // saying that it is incomplete, then you are most likely trying to | |
| | | // perform a database operation on a C++ type that is not a view | |
| | | // Or you forgot to include the corresponding -odb.hxx file. | |
| | | // | |
| struct view_traits: | | struct view_traits: | |
| access::view_traits<T>, | | access::view_traits<T>, | |
| access::view_factory<T, typename access::view_traits<T>::pointer_type> | | access::view_factory<T, typename access::view_traits<T>::pointer_type> | |
| { | | { | |
|
| // | | | |
| // If a C++ compiler issues an error pointing to this struct and | | | |
| // saying that it is incomplete, then you are most likely trying to | | | |
| // perform a database operation on a C++ type that is not a view | | | |
| // Or you forgot to include the corresponding -odb.hxx file. | | | |
| // | | | |
| | | | |
| typedef | | typedef | |
| odb::pointer_traits<typename access::view_traits<T>::pointer_type> | | odb::pointer_traits<typename access::view_traits<T>::pointer_type> | |
| pointer_traits; | | pointer_traits; | |
| | | | |
| typedef typename access::view_traits<T>::view_type view_type; | | typedef typename access::view_traits<T>::view_type view_type; | |
| typedef typename access::view_traits<T>::pointer_type pointer_type; | | typedef typename access::view_traits<T>::pointer_type pointer_type; | |
| }; | | }; | |
| | | | |
| // Specialization for const views. It only defines the view, pointer, | | // Specialization for const views. It only defines the view, pointer, | |
| // and const_pointer types with pointer and const_pointer being the | | // and const_pointer types with pointer and const_pointer being the | |
| | | | |
| skipping to change at line 230 | | skipping to change at line 247 | |
| typedef | | typedef | |
| odb::pointer_traits<typename access::view_traits<T>::pointer_type> | | odb::pointer_traits<typename access::view_traits<T>::pointer_type> | |
| pointer_traits; | | pointer_traits; | |
| | | | |
| public: | | public: | |
| typedef typename access::view_traits<T>::view_type view_type; | | typedef typename access::view_traits<T>::view_type view_type; | |
| typedef typename pointer_traits::const_pointer_type const_pointer_type; | | typedef typename pointer_traits::const_pointer_type const_pointer_type; | |
| typedef const_pointer_type pointer_type; | | typedef const_pointer_type pointer_type; | |
| }; | | }; | |
| | | | |
|
| | | template <typename T, database_id DB> | |
| | | // | |
| | | // If a C++ compiler issues an error pointing to this struct and | |
| | | // saying that it is incomplete, then you are most likely trying to | |
| | | // perform a database operation on a C++ type that is not a view | |
| | | // Or you forgot to include the corresponding -odb.hxx file. | |
| | | // | |
| | | struct view_traits_impl: | |
| | | access::view_traits_impl<T, DB>, | |
| | | access::view_factory<T, typename access::view_traits<T>::pointer_type> | |
| | | { | |
| | | typedef | |
| | | odb::pointer_traits<typename access::view_traits<T>::pointer_type> | |
| | | pointer_traits; | |
| | | | |
| | | typedef typename access::view_traits<T>::view_type view_type; | |
| | | typedef typename access::view_traits<T>::pointer_type pointer_type; | |
| | | }; | |
| | | | |
| // | | // | |
| // composite_value_traits | | // composite_value_traits | |
| // | | // | |
| | | | |
|
| template <typename T> | | template <typename T, database_id DB> | |
| struct composite_value_traits: access::composite_value_traits<T> | | struct composite_value_traits: access::composite_value_traits<T, DB> | |
| { | | { | |
| }; | | }; | |
| } | | } | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| #endif // ODB_TRAITS_HXX | | #endif // ODB_TRAITS_HXX | |
| | | | |
End of changes. 13 change blocks. |
| 22 lines changed or deleted | | 59 lines changed or added | |
|
| transaction.hxx | | transaction.hxx | |
| // file : odb/transaction.hxx | | // file : odb/transaction.hxx | |
|
| // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_TRANSACTION_HXX | | #ifndef ODB_TRANSACTION_HXX | |
| #define ODB_TRANSACTION_HXX | | #define ODB_TRANSACTION_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
|
| | | #include <vector> | |
| | | #include <cstddef> // std::size_t | |
| | | | |
| #include <odb/forward.hxx> | | #include <odb/forward.hxx> | |
| | | | |
| #include <odb/details/export.hxx> | | #include <odb/details/export.hxx> | |
| #include <odb/details/unique-ptr.hxx> | | #include <odb/details/unique-ptr.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| class transaction_impl; | | class transaction_impl; | |
| | | | |
| class LIBODB_EXPORT transaction | | class LIBODB_EXPORT transaction | |
| | | | |
| skipping to change at line 96 | | skipping to change at line 99 | |
| | | | |
| void | | void | |
| tracer (tracer_type&); | | tracer (tracer_type&); | |
| | | | |
| void | | void | |
| tracer (tracer_type*); | | tracer (tracer_type*); | |
| | | | |
| tracer_type* | | tracer_type* | |
| tracer () const; | | tracer () const; | |
| | | | |
|
| | | // Post-commit/rollback callbacks. | |
| | | // | |
| | | public: | |
| | | static const unsigned short event_commit = 0x01; | |
| | | static const unsigned short event_rollback = 0x02; | |
| | | static const unsigned short event_all = event_commit | event_rollback; | |
| | | | |
| | | typedef void (*callback_type) ( | |
| | | unsigned short event, void* key, unsigned long long data); | |
| | | | |
| | | // Register a post-commit/rollback callback. The data argument | |
| | | // can be used to store any user data that does not exceed 8 | |
| | | // bytes and doesn't require alignment greater than unsigned | |
| | | // long long, such as an old value that needs to be restored | |
| | | // in case of a rollback. | |
| | | // | |
| | | // The state argument can be used to indicate to the caller | |
| | | // that the callback has been unregistered because the | |
| | | // transaction has terminated. In this case the transaction | |
| | | // resets the passed pointer to 0. | |
| | | // | |
| | | // Note that the order in which the callbacks are called is | |
| | | // unspecified. | |
| | | // | |
| | | void | |
| | | callback_register (callback_type, | |
| | | void* key, | |
| | | unsigned short event = event_all, | |
| | | unsigned long long data = 0, | |
| | | transaction** state = 0); | |
| | | | |
| | | // Unregister a post-commit/rollback callback. Note that this is a | |
| | | // potentially slow operation. You also don't need to unregister | |
| | | // a callback that has been called or auto-reset using the state | |
| | | // argument passed to register(). This function does nothing if | |
| | | // the key is not found. | |
| | | // | |
| | | void | |
| | | callback_unregister (void* key); | |
| | | | |
| | | // Update the event, data, and state values for a callback. Note | |
| | | // that just like unregister(), this is a potentially slow operation. | |
| | | // | |
| | | void | |
| | | callback_update (void* key, | |
| | | unsigned short event, | |
| | | unsigned long long data = 0, | |
| | | transaction** state = 0); | |
| | | | |
| public: | | public: | |
| transaction_impl& | | transaction_impl& | |
| implementation (); | | implementation (); | |
| | | | |
| // Copying or assignment of transactions is not supported. | | // Copying or assignment of transactions is not supported. | |
| // | | // | |
| private: | | private: | |
| transaction (const transaction&); | | transaction (const transaction&); | |
| transaction& operator= (const transaction&); | | transaction& operator= (const transaction&); | |
| | | | |
| protected: | | protected: | |
|
| | | friend struct rollback_guard; | |
| | | | |
| | | std::size_t | |
| | | callback_find (void* key); | |
| | | | |
| | | void | |
| | | callback_call (unsigned short event); | |
| | | | |
| | | protected: | |
| bool finalized_; | | bool finalized_; | |
| details::unique_ptr<transaction_impl> impl_; | | details::unique_ptr<transaction_impl> impl_; | |
|
| | | | |
| | | // Callbacks. | |
| | | // | |
| | | struct callback_data | |
| | | { | |
| | | unsigned short event; | |
| | | callback_type func; | |
| | | void* key; | |
| | | unsigned long long data; | |
| | | transaction** state; | |
| | | }; | |
| | | | |
| | | // Slots for the first 20 callback are pre-allocated on the stack. | |
| | | // For the rest they are allocated dynamically as needed. | |
| | | // | |
| | | // Note, if you change stack_callback_count, make sure you also | |
| | | // update the common/transaction/callback test accordingly. | |
| | | // | |
| | | static const std::size_t stack_callback_count = 20; | |
| | | static const std::size_t max_callback_count = ~(std::size_t (0)); | |
| | | | |
| | | callback_data stack_callbacks_[stack_callback_count]; | |
| | | std::vector<callback_data> dyn_callbacks_; | |
| | | | |
| | | // When a callback is unregistered, the free slot from the stack is | |
| | | // added to the linked list of free slots which is organized by | |
| | | // re-using the key data member to store the slot's index (we cannot | |
| | | // store a pointer because std::vector may move slots on expansion). | |
| | | // The value equal to max_callback_count indicates no free slots are | |
| | | // available. | |
| | | // | |
| | | std::size_t free_callback_; | |
| | | | |
| | | // Total number of used slots, both registered and in the free list. | |
| | | // | |
| | | std::size_t callback_count_; | |
| }; | | }; | |
| | | | |
| class LIBODB_EXPORT transaction_impl | | class LIBODB_EXPORT transaction_impl | |
| { | | { | |
| public: | | public: | |
| typedef odb::database database_type; | | typedef odb::database database_type; | |
| typedef odb::connection connection_type; | | typedef odb::connection connection_type; | |
| | | | |
| virtual | | virtual | |
| ~transaction_impl (); | | ~transaction_impl (); | |
| | | | |
End of changes. 5 change blocks. |
| 1 lines changed or deleted | | 98 lines changed or added | |
|