📄 lists.objlist.manipulation.html
字号:
<html><!-- #BeginTemplate "/Templates/tmpl.dwt" --><head><!-- #BeginEditable "doctitle" --> <title>PTypes: lists: objlist: manipulation</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>: <a href="lists.html">Lists</a>: <a href="lists.objlist.html">objlist</a>: Manipulation </p><blockquote> <pre class="lang">#include <ptypes.h>int length(const objlist& s);void setlength(objlist& s, int newcount);void pack(objlist& s);void clear(objlist& s);void ins(objlist& s, int i, unknown* obj);int add(objlist& s, unknown* obj);void put(objlist& s, int i, unknown* obj);void del(objlist& s, int i);unknown* get(const objlist& s, int i);int indexof(const objlist& s, unknown* obj);</pre></blockquote><p><span class="def">int length(const objlist& s)</span> returns the number of items in the given object list <span class="lang">s</span>.</p><p><span class="def"> setlength(objlist& s, int newcount)</span> sets the length of the dynamic array to <span class="lang">newcount</span>. If the new count is greater than the old number of items, all extra positions are filled with <span class="lang">NULL</span> pointers. If the new count is less than the old number and the list "owns" objects, all objects left out of the list are destroyed.</p><p><span class="def">pack(objlist& s)</span> optimizes the memory usage for the objlist object. Useful when a big number of objects has been inserted and then deleted from the list.</p><p><span class="def">clear(objlist& s)</span> clears all items of the list <span class="lang">s</span>. This function may also destroy all objects if the list "owns" objects.</p><p><span class="def"> ins(objlist& s, int i, unknown* iobj)</span> inserts object <span class="lang">obj</span> at the position <span class="lang">i</span>. The position is 0-based. Inserting a new item at the position equal to the number of items is not an error -- in this case the function <span class="lang">ins()</span> simply adds the object like <span class="lang">add()</span>.</p><p><span class="def">int add(objlist& s, unknown* obj)</span> adds object <span class="lang">obj</span> to the list <span class="lang">s</span> and returns the actual position at which the item was inserted.</p><p><span class="def">put(objlist& s, int i, unknown* obj)</span> assigns a new object value to the item <span class="lang">i</span> of the list <span class="lang">s</span>. The previous object may be destroyed depending on whether the list "owns" objects.</p><p><span class="def">del(objlist& s, int i)</span> removes the item at the position <span class="lang">i</span>. The object associated with this item may be destroyed depending on whether the list "owns" objects.</p><p><span class="def">unknown* get(const objlist& s, int i)</span> returns the object value at position <span class="lang">i</span>. Indexed access is also allowed through <span class="lang">operator[]</span>. Both <span class="lang">get()</span> and <span class="lang">operator[]</span> may generate an unrecoverable error if the index is out of bounds <b>and</b> if the library is compiled with either _DEBUG or DEBUG conditional symbol. In other words, the non-debugging version of the library never checks for index overlfows, thus making your program somewhat faster but less safe.</p><p><span class="def">int indexof(const objlist& s, unknown* obj)</span> finds a pointer <span class="lang">obj</span> in the object list. If the pointer is not found in the list, this function returns -1, otherwise it returns the index of the item.</p><p class="seealso">See also: <a href="lists.objlist.constructors.html">Constructors/destructors</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 + -