Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-05-18 08:29:46

0001 /*-
0002  * Copyright (c) 2009, 2020 Oracle and/or its affiliates.  All rights reserved.
0003  *
0004  * See the file LICENSE for license information.
0005  *
0006  * $Id$
0007  */
0008 
0009 #ifndef _DB_STL_GLOBAL_INNER_OBJECT_
0010 #define _DB_STL_GLOBAL_INNER_OBJECT_
0011 
0012 #include "dbstl_common.h"
0013 
0014 START_NS(dbstl)
0015 /* 
0016  * This is the interface for all classes that has some global/singleton 
0017  * instances that will survive during the entire process lifetime and 
0018  * need to be deleted before process exit. Not deleting them won't make
0019  * a difference because they have to be alive when the process is alive,
0020  * they are not memory leaks. However, we will still delete them before
0021  * process exit, to make no memory leak reports by memory leak checkers.
0022  */
0023 class _exported DbstlGlobalInnerObject
0024 {
0025 public:
0026     DbstlGlobalInnerObject(){}
0027     virtual ~DbstlGlobalInnerObject(){}
0028 
0029 }; // DbstlGlobalInnerObject
0030 
0031 void _exported register_global_object(DbstlGlobalInnerObject *gio);
0032 
0033 // This class stores the pointer of an object allocated on heap, and when
0034 // an instance of this class is destructed, it deletes that object.
0035 // Any instance of this class can only be created on the heap so that we
0036 // can control when to destruct its instances. It derives from 
0037 // DbstlGlobalInnerObject so that we can register pointers to instances of
0038 // this class into ResourceManager, just like other objects which implements
0039 // the DbstlGlobalInnerObject interface. So the ultimate purpose for this
0040 // template is to manage objects which can't implement DbstlGlobalInnerObject
0041 // interface, like objects of Db, DbEnv, etc.
0042 //
0043 template<typename T>
0044 class _exported DbstlHeapObject : public DbstlGlobalInnerObject
0045 {
0046 private:
0047     typedef DbstlHeapObject<T> self;
0048     T *obj;
0049 
0050     // Only allow creating to heap.
0051     DbstlHeapObject(T *obj1) { obj = obj1; }
0052 public:
0053     static self *instance(T *obj1) { return new self(obj1); }
0054     virtual ~DbstlHeapObject() { delete obj; }
0055 }; // DbstlHeapObject
0056 
0057 END_NS
0058 #endif // !_DB_STL_GLOBAL_INNER_OBJECT_
0059