Debian Codegraph @

lang/cxx/stl/dbstl_inner_utility.h

raw
1 /*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2009, 2013 Oracle and/or its affiliates. All rights reserved.
5 *
6 * $Id$
7 */
8
9 #ifndef _DB_STL_GLOBAL_INNER_OBJECT_
10 #define _DB_STL_GLOBAL_INNER_OBJECT_
11
12 #include "dbstl_common.h"
13
14 START_NS(dbstl)
15 /*
16 * This is the interface for all classes that has some global/singleton
17 * instances that will survive during the entire process lifetime and
18 * need to be deleted before process exit. Not deleting them won't make
19 * a difference because they have to be alive when the process is alive,
20 * they are not memory leaks. However, we will still delete them before
21 * process exit, to make no memory leak reports by memory leak checkers.
22 */
23 class _exported DbstlGlobalInnerObject
24 {
25 public:
26 DbstlGlobalInnerObject(){}
27 virtual ~DbstlGlobalInnerObject(){}
28
29 }; // DbstlGlobalInnerObject
30
31 void _exported register_global_object(DbstlGlobalInnerObject *gio);
32
33 // This class stores the pointer of an object allocated on heap, and when
34 // an instance of this class is destructed, it deletes that object.
35 // Any instance of this class can only be created on the heap so that we
36 // can control when to destruct its instances. It derives from
37 // DbstlGlobalInnerObject so that we can register pointers to instances of
38 // this class into ResourceManager, just like other objects which implements
39 // the DbstlGlobalInnerObject interface. So the ultimate purpose for this
40 // template is to manage objects which can't implement DbstlGlobalInnerObject
41 // interface, like objects of Db, DbEnv, etc.
42 //
43 template<typename T>
44 class _exported DbstlHeapObject : public DbstlGlobalInnerObject
45 {
46 private:
47 typedef DbstlHeapObject<T> self;
48 T *obj;
49
50 // Only allow creating to heap.
51 DbstlHeapObject(T *obj1) { obj = obj1; }
52 public:
53 static self *instance(T *obj1) { return new self(obj1); }
54 virtual ~DbstlHeapObject() { delete obj; }
55 }; // DbstlHeapObject
56
57 END_NS
58 #endif // !_DB_STL_GLOBAL_INNER_OBJECT_
59