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