diff options
Diffstat (limited to 'src/sharedcore.h')
-rw-r--r-- | src/sharedcore.h | 30 |
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 | ||
16 | namespace Bu | 16 | namespace 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(); |