aboutsummaryrefslogtreecommitdiff
path: root/src/sharedcore.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-10-14 23:26:25 +0000
committerMike Buland <eichlan@xagasoft.com>2010-10-14 23:26:25 +0000
commit867dae89929a11a421ec21af71d494ad0ecc1963 (patch)
tree85d4330d5cdc0567194f1bfb2f9b1bda4e95b444 /src/sharedcore.h
parent13fa07280dd9ed2c62ad2be0848f88b0d85fe322 (diff)
downloadlibbu++-867dae89929a11a421ec21af71d494ad0ecc1963.tar.gz
libbu++-867dae89929a11a421ec21af71d494ad0ecc1963.tar.bz2
libbu++-867dae89929a11a421ec21af71d494ad0ecc1963.tar.xz
libbu++-867dae89929a11a421ec21af71d494ad0ecc1963.zip
SharedCore has more features now, which is cool, including a test to see if
another object of the parent type has the same core, and another to clone the parent object. That one is pretty cool, it means you can now get a real copy when you want to, great for multi-threaded stuff. Also, two more classes are now SharedCore: Hash and Heap!
Diffstat (limited to 'src/sharedcore.h')
-rw-r--r--src/sharedcore.h30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/sharedcore.h b/src/sharedcore.h
index 5a44df9..ac36606 100644
--- a/src/sharedcore.h
+++ b/src/sharedcore.h
@@ -15,10 +15,10 @@
15 15
16namespace Bu 16namespace Bu
17{ 17{
18 template<typename Core> 18 template<typename Shell, typename Core>
19 class SharedCore 19 class SharedCore
20 { 20 {
21 typedef class SharedCore<Core> _SharedType; 21 typedef class SharedCore<Shell, Core> _SharedType;
22 public: 22 public:
23 SharedCore() : 23 SharedCore() :
24 core( NULL ), 24 core( NULL ),
@@ -54,6 +54,18 @@ namespace Bu
54 return *iRefCount; 54 return *iRefCount;
55 } 55 }
56 56
57 Shell clone() const
58 {
59 Shell s( dynamic_cast<const Shell &>(*this) );
60 s._hardCopy();
61 return s;
62 }
63
64 bool isCoreShared( const Shell &rOther ) const
65 {
66 return rOther.core == core;
67 }
68
57 protected: 69 protected:
58 Core *core; 70 Core *core;
59 void _hardCopy() 71 void _hardCopy()
@@ -68,6 +80,20 @@ namespace Bu
68 iRefCount = new int( 1 ); 80 iRefCount = new int( 1 );
69 } 81 }
70 82
83 /**
84 * Reset core acts like a hard copy, except instead of providing a
85 * standalone copy of the shared core, it provides a brand new core.
86 *
87 * Very useful in functions used to reset the state of an object.
88 */
89 void _resetCore()
90 {
91 if( core )
92 _deref();
93 core = _allocateCore();
94 iRefCount = new int( 1 );
95 }
96
71 virtual Core *_allocateCore() 97 virtual Core *_allocateCore()
72 { 98 {
73 return new Core(); 99 return new Core();