| [1505] | 1 | #define TIXML_USE_TICPP |
|---|
| 2 | |
|---|
| [739] | 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 | |
|---|
| 31 | // Forward declare ticpp::Node, so it can be made a friend of TiCppRC |
|---|
| 32 | namespace ticpp |
|---|
| 33 | { |
|---|
| 34 | class Base; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | // Forward declare TiCppRCImp so TiCppRC can hold a pointer to it |
|---|
| 38 | class TiCppRCImp; |
|---|
| 39 | |
|---|
| 40 | /** |
|---|
| 41 | Base class for reference counting functionality |
|---|
| 42 | */ |
|---|
| 43 | class TiCppRC |
|---|
| 44 | { |
|---|
| 45 | // Allow ticpp::Node to directly modify reference count |
|---|
| 46 | friend class ticpp::Base; |
|---|
| 47 | |
|---|
| 48 | private: |
|---|
| 49 | |
|---|
| 50 | TiCppRCImp* m_tiRC; /**< Pointer to reference counter */ |
|---|
| 51 | |
|---|
| 52 | public: |
|---|
| 53 | |
|---|
| 54 | /** |
|---|
| 55 | Constructor |
|---|
| 56 | Spawns new reference counter with a pointer to this |
|---|
| 57 | */ |
|---|
| 58 | TiCppRC(); |
|---|
| 59 | |
|---|
| 60 | /** |
|---|
| 61 | Destructor |
|---|
| 62 | Nullifies the pointer to this held by the reference counter |
|---|
| 63 | Decrements reference count |
|---|
| 64 | */ |
|---|
| 65 | virtual ~TiCppRC(); |
|---|
| 66 | }; |
|---|
| 67 | |
|---|
| 68 | class TiCppRCImp |
|---|
| 69 | { |
|---|
| 70 | private: |
|---|
| 71 | |
|---|
| 72 | int m_count; /**< Holds reference count to me, and to the node I point to */ |
|---|
| 73 | |
|---|
| 74 | TiCppRC* m_tiCppRC; /**< Holds pointer to an object inheriting TiCppRC */ |
|---|
| 75 | |
|---|
| 76 | public: |
|---|
| 77 | |
|---|
| 78 | /** |
|---|
| 79 | Initializes m_tiCppRC pointer, and set reference count to 1 |
|---|
| 80 | */ |
|---|
| 81 | TiCppRCImp( TiCppRC* tiCppRC ); |
|---|
| 82 | |
|---|
| 83 | /** |
|---|
| 84 | Allows the TiCppRC object to set the pointer to itself ( m_tiCppRc ) to NULL when the TiCppRC object is deleted |
|---|
| 85 | */ |
|---|
| 86 | void Nullify(); |
|---|
| 87 | |
|---|
| 88 | /** |
|---|
| 89 | Increment Reference Count |
|---|
| 90 | */ |
|---|
| 91 | void IncRef(); |
|---|
| 92 | |
|---|
| 93 | /** |
|---|
| 94 | Decrement Reference Count |
|---|
| 95 | */ |
|---|
| 96 | void DecRef(); |
|---|
| 97 | |
|---|
| 98 | /** |
|---|
| 99 | Set Reference Count to 1 - dangerous! - Use only if you are sure of the consequences |
|---|
| 100 | */ |
|---|
| 101 | void InitRef(); |
|---|
| 102 | |
|---|
| 103 | /** |
|---|
| 104 | Get internal pointer to the TiCppRC object - not reference counted, use at your own risk |
|---|
| 105 | */ |
|---|
| 106 | TiCppRC* Get(); |
|---|
| 107 | |
|---|
| 108 | /** |
|---|
| 109 | Returns state of internal pointer - will be null if the object was deleted |
|---|
| 110 | */ |
|---|
| 111 | bool IsNull(); |
|---|
| 112 | }; |
|---|
| 113 | |
|---|
| 114 | #endif // TICPP_INCLUDED |
|---|
| 115 | |
|---|
| 116 | #endif // TIXML_USE_TICPP |
|---|