📄 unknown.html
字号:
<html><!-- #BeginTemplate "/Templates/tmpl.dwt" --><head><!-- #BeginEditable "doctitle" --> <title>PTypes: unknown & component</title><!-- #EndEditable --> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link rel="stylesheet" href="styles.css"></head><body bgcolor="#FFFFFF" leftmargin="40" marginwidth="40"><p><a href="../index.html"><img src="title-1.7.gif" width="213" height="34" alt="C++ Portable Types Library (PTypes) Version 1.7" border="0"></a> <hr noshade><!-- #BeginEditable "body" --> <p class="hpath"><a href="index.html">Top</a>: <a href="basic.html">Basic types</a>: unknown & component</p><p> <blockquote> <pre class="lang">#include <ptypes.h>unknown::unknown();virtual unknown::~unknown();component::component();virtual component::~component();component* addref(component*);<br>bool release(component*);template <class T> class compref;int objalloc;</pre></blockquote><p>The <span class="lang">unknown</span> interface encapsulates the fundamental behavior common to most interfaces (classes) in PTypes, except <span class="lang">string</span>, <span class="lang">cset</span>, <span class="lang">variant</span>, <span class="lang">mutex</span> and <span class="lang">rwlock</span>. The <span class="lang">unknown</span> class has no semantic or functional meaning, however, deriving a class from <span class="lang">unknown</span> ensures that the descendant class could be used with various container objects, e.g. <a href="lists.strlist.html">strlist</a> and <a href="lists.strmap.html">strmap</a>.</p><p>The <span class="lang">component</span> class adds reference-counting functionality to <span class="lang">unknown</span> (see <span class="lang">addref()</span> and <span class="lang">release()</span> below). PTypes variants require the objects to be derived from <span class="lang">component</span> instead of <span class="lang">unknown</span> to be able to make assignments and destruction of variants properly. It should be noted that the reference counting scheme has a potential memory leak problem when there exists a circular reference between 2 or more objects.</p><p>A global variable <span class="lang">objalloc</span> is declared to keep track of the number of allocated objects in the application program, which can help you to find memory leaks or other potential bugs. If the memory is cleaned up properly, this value should be zero upon program termination. You can write code (possibly enclosed within <span class="lang">#ifdef DEBUG ... #endif</span>) which checks whether this value is zero at the end of <span class="lang">main()</span>.</p><p><span class="def">component* addref(component* c)</span> increments the reference counter for the given object <span class="lang">c</span>. The return value is the same as <span class="lang">c</span> and is provided for convenience.</p><p><span class="def">bool release(component* c)</span> decrements the reference counter and destroys the object if the counter reached 0. Returns <span class="lang">true</span> if the object has been destroyed. Passing <span class="lang">NULL</span> to this function is not an error.</p><p><span class="def">template <class T> class compref</span> implements a 'smart' pointer to <span class="lang">component</span> (or any derivative class) with automatic reference counting. Use this template in place of a plain pointer declaration (e.g. <span class="lang">compref<myclass></span> instead of <span class="lang">myclass*</span>) to automatically destroy objects as soon as there are no more references left. The behavior of <span class="lang">compref</span> pointers is similar to plain pointers, except that they perform additional actions when assigning new values to them.</p><p class="seealso">See also: <a href="lists.html">Lists</a>, <a href="variant.html">variant</a></p><!-- #EndEditable --> <hr size="1"><a href="../index.html" class="ns">PTypes home</a></body><!-- #EndTemplate --></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -