diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-07-03 00:28:59 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-07-03 00:28:59 +0000 |
commit | ac517a2b7625e0aa0862679e961c6349f859ea3b (patch) | |
tree | e3e27a6b9bd5e2be6150088495c91fc91786ad9d /src/tests/constsptr.cpp | |
parent | f8d4301e9fa4f3709258505941e37fab2eadadc6 (diff) | |
parent | bd865cee5f89116c1f054cd0e5c275e97c2d0a9b (diff) | |
download | libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.gz libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.bz2 libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.xz libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.zip |
The reorg is being put in trunk, I think it's ready. Now we just get to find
out how many applications won't work anymore :)
Diffstat (limited to '')
-rw-r--r-- | src/tests/constsptr.cpp | 94 |
1 files changed, 0 insertions, 94 deletions
diff --git a/src/tests/constsptr.cpp b/src/tests/constsptr.cpp deleted file mode 100644 index e6f87c7..0000000 --- a/src/tests/constsptr.cpp +++ /dev/null | |||
@@ -1,94 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include "sptr.h" | ||
3 | |||
4 | template <typename T> | ||
5 | class DataBase | ||
6 | { | ||
7 | public: | ||
8 | DataBase(): | ||
9 | _bHas(false) | ||
10 | { | ||
11 | } | ||
12 | |||
13 | virtual ~DataBase() | ||
14 | { | ||
15 | clr(); | ||
16 | } | ||
17 | |||
18 | virtual bool has() const | ||
19 | { | ||
20 | return _bHas; | ||
21 | } | ||
22 | |||
23 | virtual void clr() | ||
24 | { | ||
25 | _bHas = false; | ||
26 | } | ||
27 | |||
28 | virtual void set(T d) | ||
29 | { | ||
30 | _tVal = d; | ||
31 | _bHas = true; | ||
32 | } | ||
33 | |||
34 | virtual T const &get() const | ||
35 | { | ||
36 | if(!has()) | ||
37 | throw "no data"; | ||
38 | return _tVal; | ||
39 | } | ||
40 | |||
41 | virtual T &get() | ||
42 | { | ||
43 | if(!has()) | ||
44 | throw "no data"; | ||
45 | return _tVal; | ||
46 | } | ||
47 | |||
48 | protected: | ||
49 | bool _bHas; | ||
50 | T _tVal; | ||
51 | }; | ||
52 | |||
53 | |||
54 | class Test | ||
55 | { | ||
56 | public: | ||
57 | Test(){}; | ||
58 | virtual ~Test(){}; | ||
59 | |||
60 | void set(int i) | ||
61 | { | ||
62 | _i = i; | ||
63 | } | ||
64 | |||
65 | int get() const | ||
66 | { | ||
67 | return _i; | ||
68 | } | ||
69 | |||
70 | private: | ||
71 | int _i; | ||
72 | }; | ||
73 | |||
74 | int main() | ||
75 | { | ||
76 | typedef SPtr<Test> TestPtr; | ||
77 | |||
78 | TestPtr t1(new Test); | ||
79 | t1->set(42); | ||
80 | |||
81 | printf("t1: %d.\n", t1->get()); | ||
82 | |||
83 | const TestPtr t2 = t1; | ||
84 | |||
85 | printf("t2: %d.\n", t2->get()); | ||
86 | |||
87 | typedef DataBase<const TestPtr> DBTP; | ||
88 | |||
89 | DBTP db; | ||
90 | db.set(t1); | ||
91 | |||
92 | printf("dbt1: %d.\n", db.get()->get()); | ||
93 | } | ||
94 | |||