// file : odb/mysql/statement-cache.hxx // author : Boris Kolpackov // copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file #ifndef ODB_MYSQL_STATEMENT_CACHE_HXX #define ODB_MYSQL_STATEMENT_CACHE_HXX #include #include #include #include #include #include #include #include namespace odb { namespace mysql { class connection; struct LIBODB_MYSQL_EXPORT type_info_comparator { bool operator() (const std::type_info* x, const std::type_info* y) const { // XL C++ on AIX has buggy type_info::before() in that // it returns true for two different type_info objects // that happened to be for the same type. // #if defined(__xlC__) && defined(_AIX) return *x != *y && x->before (*y); #else return x->before (*y); #endif } }; class LIBODB_MYSQL_EXPORT statement_cache { public: statement_cache (connection& conn) : conn_ (conn) { } template object_statements& find () { map::iterator i (map_.find (&typeid (T))); if (i != map_.end ()) return static_cast&> (*i->second); details::shared_ptr > p ( new (details::shared) object_statements (conn_)); map_.insert (map::value_type (&typeid (T), p)); return *p; } private: typedef std::map, type_info_comparator> map; connection& conn_; map map_; }; } } #include #endif // ODB_MYSQL_STATEMENT_CACHE_HXX