📄 lists.strlist.manipulation.html
字号:
<html><!-- #BeginTemplate "/Templates/tmpl.dwt" --><head><!-- #BeginEditable "doctitle" --> <title>PTypes: lists: strlist: 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.strlist.html">strlist</a>: Manipulation </p><blockquote> <pre class="lang">#include <ptypes.h>int length(const strlist& s);void clear(strlist& s);void pack(strlist& s);void ins(strlist& s, int i, const string& str, unknown* obj);int add(strlist& s, const string& str, unknown* obj);void put(strlist& s, int i, const string& str, unknown* obj);void put(strlist& s, int i, unknown* obj);void del(strlist& s, int i);const string& getstr(const strlist& s, int i);unknown* get(const strlist& s, int i);</pre></blockquote><p><span class="def">int length(const strlist& s)</span> returns the number of items in the given string list <span class="lang">s</span>.</p><p><span class="def">clear(strlist& s)</span> clears all items of the list <span class="lang">s</span>. This function may also destroy all objects if the list "owns" the objects.</p><p><span class="def">pack(strlist& s)</span> optimizes the memory usage for the strlist object. Useful when a big number of objects has been inserted and then deleted from the list.</p><p><span class="def">ins(strlist& s, int i, const string& istr, unknown* iobj)</span> inserts string <span class="lang">s</span> and 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> does the same as function <span class="lang">add()</span>. This function can <b>not</b> be called for sorted string lists.</p><p><span class="def">int add(strlist& s, const string& str, unknown* obj)</span> adds string <span class="lang">s</span> and 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. If the list is sorted, the new item is inserted at the proper position, otherwise it is appended to the end of the list.</p><p><span class="def">put(strlist& s, int i, string const& str, unknown* obj)</span> assigns a new string/object pair values to the item <span class="lang">i</span> of the string list <span class="lang">s</span>. This operation is <b>not</b> allowed on sorted lists. The previous object may be destroyed depending on the flag <span class="lang">SL_OWNOBJECTS</span>.</p><p><span class="def">put(strlist& s, int i, unknown* obj)</span> assigns a new object value to the item <span class="lang">i</span> of the string list <span class="lang">s</span>. The previous object may be destroyed depending on the flag <span class="lang">SL_OWNOBJECTS</span>.</p><p> <span class="def">del(strlist& s, int i)</span> removes the item at the position <span class="lang">i</span> from the string list <span class="lang">s</span>. The object associated with this item may be destroyed depending on the flag <span class="lang">SL_OWNOBJECTS</span>.</p><p><span class="def">const string& getstr(const strlist& s, int i)</span> returns the string value of the item at the position <span class="lang">i</span>. See also <b><i>Note</i></b> below.</p><p><span class="def">unknown* get(const strlist& s, int i)</span> returns the object value of the item at the position <span class="lang">i</span>. Indexed access to objects is also allowed through <span class="lang">operator[]</span>. See also <b><i>Note</i></b> below.</p><p><b><i>Note</i></b>: <span class="lang">getstr()</span>, <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 class="seealso">See also: <a href="lists.strlist.constructors.html">Constructors/destructors</a>, <a href="lists.strlist.search.html">Search</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 + -