Listing 4
// Example creating a new environment class CAuthenticationDbEnvConfigPolicy : public IDbEnvConfigPolicy { public: typedef CThreadSafeCountedPtr< CAuthenticationDbEnvConfigPolicy > tsrcp_t; // Singleton accessor static tsrcp_t Instance(); { static tsrcp_t s_tsrcpDbEnvConfigPolicy( 0 ); if ( ! s_tsrcpDbEnvConfigPolicy.get() ) { s_tsrcpDbEnvConfigPolicy.reset( new CAuthenticationDbEnvConfigPolicy() ); } return s_tsrcpDbEnvConfigPolicy; } private: // Singleton so ctor is private. CAuthenticationDbEnvConfigPolicy() : IDbEnvConfigPolicy( "AuthenticationDbEnv", 1000000 ) { } }; // Actual database environment. typedef CDatabaseEnvironment< CAuthenticationDbEnvConfigPolicy > CAuthenticationDbEnv; // Example creating a new database in the above environment // Db ConfigPolicy uses monostate pattern - all static methods, // so no base class. class CAccountDBConfigPolicy { public: // Specify the particular DbEnv that this database should be part of. typedef CAuthenticationDbEnv DbEnv_t; static const char * GetDbFilename(); static DBTYPE GetDbType(); static u_int32_t GetDbOpenFlags(); static void SetDbPageSize( size_t uDbPageSize ); static void ConfigureDbBeforeOpen( Db * pDb ); private: static DBTYPE s_DbType; static u_int32_t s_DbOpenFlags; static size_t s_uDbPageSize; }; // The DB class typedef CDatabase< CAccountKey, CAccountRecord, CAccountDBConfigPolicy > CAccountDB; // Cursor to use with this DB typedef CCursor< CAccountDB > CAccount