// file : odb/session.hxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file #ifndef ODB_SESSION_HXX #define ODB_SESSION_HXX #include #include #include #include #include #include #include #include namespace odb { class LIBODB_EXPORT session { public: typedef odb::database database_type; // If the make_current argument is true, then set the current thread's // session to this session. If another session is already in effect, // throw the already_in_session exception. // session (bool make_current = true); // Reset the current thread's session if it is this session. // ~session (); // Current session. // public: // Return true if there is a session in effect in the current // thread. // static bool has_current (); // Get current thread's session. Throw if no session is in effect. // static session& current (); // Set current thread's session. // static void current (session&); // Revert to the no session in effect state for the current thread. // static void reset_current (); // Copying or assignment of sessions is not supported. // private: session (const session&); session& operator= (const session&); protected: struct LIBODB_EXPORT object_map_base: details::shared_base { virtual ~object_map_base (); }; template struct object_map: object_map_base, std::map::id_type, typename object_traits::pointer_type> { }; // Object cache. // public: template struct object_position { typedef T object_type; typedef object_map 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 object_position insert (database_type&, const typename object_traits::id_type&, const typename object_traits::pointer_type&); template typename object_traits::pointer_type find (database_type&, const typename object_traits::id_type&) const; template void erase (database_type&, const typename object_traits::id_type&); template void erase (const object_position&); protected: typedef std::map, details::type_info_comparator> type_map; typedef std::map database_map; database_map db_map_; }; } #include #include #include #endif // ODB_SESSION_HXX