1 | #ifndef _SHAREDPTR_H_ |
---|
2 | #define _SHAREDPTR_H_ |
---|
3 | |
---|
4 | #include "GaussNumber.h" |
---|
5 | #define NULL 0 |
---|
6 | |
---|
7 | class Storage { |
---|
8 | |
---|
9 | private: |
---|
10 | GaussNumber *p_obj; |
---|
11 | int count; |
---|
12 | |
---|
13 | public: |
---|
14 | Storage(GaussNumber *p_obj); |
---|
15 | ~Storage(); |
---|
16 | void increaseCount(); |
---|
17 | void decreaseCount(); |
---|
18 | GaussNumber *ptr() const; |
---|
19 | bool isNull() const; |
---|
20 | |
---|
21 | }; |
---|
22 | |
---|
23 | |
---|
24 | class shared_ptr { |
---|
25 | |
---|
26 | private: |
---|
27 | Storage *storage; |
---|
28 | |
---|
29 | public: |
---|
30 | shared_ptr(); |
---|
31 | shared_ptr(GaussNumber *p_obj); |
---|
32 | shared_ptr(const shared_ptr &sptr); |
---|
33 | ~shared_ptr(); |
---|
34 | const shared_ptr &operator=(const shared_ptr &sptr); |
---|
35 | GaussNumber &operator*() const; |
---|
36 | GaussNumber *operator->() const; |
---|
37 | GaussNumber *ptr() const; |
---|
38 | bool isNull() const; |
---|
39 | |
---|
40 | }; |
---|
41 | |
---|
42 | #endif |
---|