Angelscript/docs/manual/doc_datatypes_dictionary.html

206 lines
10 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.18"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: dictionary</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="aslogo_small.png"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">AngelScript
</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.18 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('doc_datatypes_dictionary.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="PageDoc"><div class="header">
<div class="headertitle">
<div class="title">dictionary </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><dl class="section note"><dt>Note</dt><dd>Dictionaries are only available in the scripts if the application <a class="el" href="doc_addon_dict.html">registers the support for them</a>. The syntax for using dictionaries may differ for the application you're working with so consult the application's manual for more details.</dd></dl>
<p>The dictionary stores key-value pairs, where the key is a string, and the value can be of any type. Key-value pairs can be added or removed dynamically, making the dictionary a good general purpose container object.</p>
<pre>
obj object;
obj @handle;</pre><pre> // Initialize with a list
dictionary dict = {{'one', 1}, {'object', object}, {'handle', @handle}};</pre><pre> // Examine and access the values through get or set methods ...
if( dict.exists('one') )
{
// get returns true if the stored type is compatible with the requested type
bool isValid = dict.get('handle', @handle);
if( isValid )
{
dict.delete('object');
dict.set('value', 1);
}
}
</pre><p>Dictionary values can also be accessed or added by using the index operator.</p>
<pre>
// Read and modify an integer value
int val = int(dict['value']);
dict['value'] = val + 1;</pre><pre> // Read and modify a handle to an object instance
@handle = cast&lt;obj&gt;(dict['handle']);
if( handle is null )
@dict['handle'] = object;
</pre><p>Dictionaries can also be created and initialized within expressions as <a class="el" href="doc_expressions.html#anonobj">anonymous objects</a>.</p>
<pre>
// Call a function that expects a dictionary as input and no other overloads
// In this case it is possible to inform the initialization list without explicitly giving the type
foo({{'a', 1},{'b', 2}});</pre><pre> // Call a function where there are multiple overloads expecting different
// In this case it is necessary to explicitly define the type of the initialization list
foo2(dictionary = {{'a', 1},{'b', 2}});
</pre><p>Dictionaries of dictionaries are created using <a class="el" href="doc_expressions.html#anonobj">anonymous objects</a> as well.</p>
<pre>
dictionary d2 = {{'a', dictionary = {{'aa', 1}, {'ab', 2}}},
{'b', dictionary = {{'ba', 1}, {'bb', 2}}}};
</pre><h1><a class="anchor" id="doc_datatypes_dictionary_addon"></a>
Supporting dictionary object</h1>
<p>The dictionary object is a <a class="el" href="doc_datatypes_obj.html">reference type</a>, so it's possible to use handles to the dictionary object when passing it around to avoid costly copies.</p>
<h2><a class="anchor" id="doc_datatypes_dictionary_addon_ops"></a>
Operators</h2>
<p><b>= assignment</b><br />
</p>
<p>The assignment operator performs a shallow copy of the content.</p>
<p><b>[] index operator</b><br />
</p>
<p>The index operator takes a string for the key, and returns a reference to the <a class="el" href="doc_datatypes_dictionary.html#doc_datatypes_dictionaryValue_addon">value</a>. If the key/value pair doesn't exist it will be inserted with a null value.</p>
<h2><a class="anchor" id="doc_datatypes_dictionary_addon_mthd"></a>
Methods</h2>
<p><b>void set(const string &amp;in key, ? &amp;in value)</b><br />
<b>void set(const string &amp;in key, int64 &amp;in value)</b><br />
<b>void set(const string &amp;in key, double &amp;in value)</b><br />
</p>
<p>Sets a key/value pair in the dictionary. If the key already exists, the value will be changed.</p>
<p><b>bool get(const string &amp;in key, ? &amp;out value) const</b><br />
<b>bool get(const string &amp;in key, int64 &amp;out value) const</b><br />
<b>bool get(const string &amp;in key, double &amp;out value) const</b><br />
</p>
<p>Retrieves the value corresponding to the key. The methods return false if the key is not found, and in this case the value will maintain its default value based on the type.</p>
<p><b>array&lt;string&gt; @getKeys() const</b><br />
</p>
<p>This method returns an array with all of the existing keys in the dictionary. The order of the keys in the array is undefined.</p>
<p><b>bool exists(const string &amp;in key) const</b><br />
</p>
<p>Returns true if the key exists in the dictionary.</p>
<p><b>bool delete(const string &amp;in key)</b><br />
</p>
<p>Removes the key and the corresponding value from the dictionary. Returns false if the key wasn't found.</p>
<p><b>void deleteAll()</b><br />
</p>
<p>Removes all entries in the dictionary.</p>
<p><b>bool isEmpty() const</b><br />
</p>
<p>Returns true if the dictionary doesn't hold any entries.</p>
<p><b>uint getSize() const</b><br />
</p>
<p>Returns the number of keys in the dictionary.</p>
<h1><a class="anchor" id="doc_datatypes_dictionaryValue_addon"></a>
Supporting dictionaryValue object</h1>
<p>The dictionaryValue type is how the <a class="el" href="doc_datatypes_dictionary.html#doc_datatypes_dictionary_addon">dictionary</a> object stores the values. When accessing the values through the dictionary index operator a reference to a dictionaryValue is returned.</p>
<p>The dictionaryValue type itself is a value type, i.e. no handles to it can be held, but it can hold handles to other objects as well as values of any type.</p>
<h2><a class="anchor" id="doc_datatypes_dictionaryValue_addon_ops"></a>
Operators</h2>
<p><b>= assignment</b><br />
</p>
<p>The value assignment operator should be used to copy a value into the dictionaryValue.</p>
<p><b>@= handle assignment</b><br />
</p>
<p>The handle assignment operator should be used to set the dictionaryValue to refer to an object instance.</p>
<p><b>cast&lt;type&gt; cast operator</b><br />
</p>
<p>The cast operator is used to dynamically cast the handle held in the dictionaryValue to the desired type. If the dictionaryValue doesn't hold a handle, or the handle is not compatible with the desired type, the cast operator will return a null handle.</p>
<p><b>type() conversion operator</b><br />
</p>
<p>The conversion operator is used to return a new value of the desired type. If no value conversion is found, an uninitialized value of the desired type is returned. </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated on Sat Dec 5 2020 23:20:25 for AngelScript by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.18 </li>
</ul>
</div>
</body>
</html>