1 | #define TIXML_USE_TICPP |
---|
2 | |
---|
3 | /* |
---|
4 | http://code.google.com/p/ticpp/ |
---|
5 | Copyright (c) 2006 Ryan Pusztai, Ryan Mulder |
---|
6 | |
---|
7 | Permission is hereby granted, free of charge, to any person obtaining a copy of |
---|
8 | this software and associated documentation files (the "Software"), to deal in |
---|
9 | the Software without restriction, including without limitation the rights to |
---|
10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
---|
11 | the Software, and to permit persons to whom the Software is furnished to do so, |
---|
12 | subject to the following conditions: |
---|
13 | |
---|
14 | The above copyright notice and this permission notice shall be included in all |
---|
15 | copies or substantial portions of the Software. |
---|
16 | |
---|
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
---|
19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
---|
20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
---|
21 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
---|
22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
---|
23 | */ |
---|
24 | |
---|
25 | #ifdef TIXML_USE_TICPP |
---|
26 | |
---|
27 | #ifndef TICPPRC_INCLUDED |
---|
28 | #define TICPPRC_INCLUDED |
---|
29 | |
---|
30 | #include <vector> |
---|
31 | |
---|
32 | // Forward declare ticpp::Node, so it can be made a friend of TiCppRC |
---|
33 | namespace ticpp |
---|
34 | { |
---|
35 | class Base; |
---|
36 | } |
---|
37 | |
---|
38 | // Forward declare TiCppRCImp so TiCppRC can hold a pointer to it |
---|
39 | class TiCppRCImp; |
---|
40 | |
---|
41 | /** |
---|
42 | Base class for reference counting functionality |
---|
43 | */ |
---|
44 | class TiCppRC |
---|
45 | { |
---|
46 | // Allow ticpp::Node to directly modify reference count |
---|
47 | friend class ticpp::Base; |
---|
48 | |
---|
49 | private: |
---|
50 | |
---|
51 | TiCppRCImp* m_tiRC; /**< Pointer to reference counter */ |
---|
52 | |
---|
53 | public: |
---|
54 | |
---|
55 | /** |
---|
56 | Constructor |
---|
57 | Spawns new reference counter with a pointer to this |
---|
58 | */ |
---|
59 | TiCppRC(); |
---|
60 | |
---|
61 | /** |
---|
62 | Destructor |
---|
63 | Nullifies the pointer to this held by the reference counter |
---|
64 | Decrements reference count |
---|
65 | */ |
---|
66 | virtual ~TiCppRC(); |
---|
67 | |
---|
68 | std::vector< ticpp::Base* > m_spawnedWrappers; /**< Remember all wrappers that we've created with 'new' - ( e.g. NodeFactory, FirstChildElement, etc. )*/ |
---|
69 | |
---|
70 | /** |
---|
71 | Delete all container objects we've spawned with 'new'. |
---|
72 | */ |
---|
73 | void DeleteSpawnedWrappers(); |
---|
74 | }; |
---|
75 | |
---|
76 | class TiCppRCImp |
---|
77 | { |
---|
78 | private: |
---|
79 | |
---|
80 | int m_count; /**< Holds reference count to me, and to the node I point to */ |
---|
81 | |
---|
82 | TiCppRC* m_tiCppRC; /**< Holds pointer to an object inheriting TiCppRC */ |
---|
83 | |
---|
84 | public: |
---|
85 | |
---|
86 | /** |
---|
87 | Initializes m_tiCppRC pointer, and set reference count to 1 |
---|
88 | */ |
---|
89 | TiCppRCImp( TiCppRC* tiCppRC ); |
---|
90 | |
---|
91 | /** |
---|
92 | Allows the TiCppRC object to set the pointer to itself ( m_tiCppRc ) to NULL when the TiCppRC object is deleted |
---|
93 | */ |
---|
94 | void Nullify(); |
---|
95 | |
---|
96 | /** |
---|
97 | Increment Reference Count |
---|
98 | */ |
---|
99 | void IncRef(); |
---|
100 | |
---|
101 | /** |
---|
102 | Decrement Reference Count |
---|
103 | */ |
---|
104 | void DecRef(); |
---|
105 | |
---|
106 | /** |
---|
107 | Set Reference Count to 1 - dangerous! - Use only if you are sure of the consequences |
---|
108 | */ |
---|
109 | void InitRef(); |
---|
110 | |
---|
111 | /** |
---|
112 | Get internal pointer to the TiCppRC object - not reference counted, use at your own risk |
---|
113 | */ |
---|
114 | TiCppRC* Get(); |
---|
115 | |
---|
116 | /** |
---|
117 | Returns state of internal pointer - will be null if the object was deleted |
---|
118 | */ |
---|
119 | bool IsNull(); |
---|
120 | }; |
---|
121 | |
---|
122 | #endif // TICPP_INCLUDED |
---|
123 | |
---|
124 | #endif // TIXML_USE_TICPP |
---|