haiku-website/static/legacy-docs/bebook/BPropertyInfo_Overview.html

87 lines
11 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>The Be Book - System Overview - The Application Kit</title><link rel="stylesheet" href="be_book.css" type="text/css" media="all" /><link rel="shortcut icon" type="image/vnd.microsoft.icon" href="./images/favicon.ico" /><!--[if IE]>
<link rel="stylesheet" type="text/css" href="be_book_ie.css" />
<![endif]--><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><meta name="keywords" content="Access, BeOS, BeBook, API" /><link rel="start" href="index.html" title="The Be Book" /><link rel="up" href="TheApplicationKit_Overview.html" title="The Application Kit" /><link rel="prev" href="BMessenger_Overview.html" title="BMessenger" /><link rel="next" href="BRoster_Overview.html" title="BRoster" /></head><body><div id="header"><div id="headerT"><div id="headerTL"><a accesskey="p" href="BMessenger_Overview.html" title="BMessenger"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a accesskey="u" href="TheApplicationKit_Overview.html" title="The Application Kit"><img src="./images/navigation/up.png" alt="Up" /></a> <a accesskey="n" href="BRoster_Overview.html" title="BRoster"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="headerTR"><div id="navigpeople"><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div><div class="navigboxed" id="navigindex"><a accesskey="i" href="ClassIndex.html" title="Index">I</a></div><div class="navigboxed" id="naviglang" title="English">en</div></div><div id="headerTC">The Be Book - System Overview - The Application Kit</div></div><div id="headerB">Prev: <a href="BMessenger_Overview.html">BMessenger</a>  Up: <a href="TheApplicationKit_Overview.html">The Application Kit</a>  Next: <a href="BRoster_Overview.html">BRoster</a></div><hr /></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h2 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BPropertyInfo_Overview"></a>BPropertyInfo</h2></div></div></div><a id="id445824" class="indexterm"></a><p><a class="link" href="BPropertyInfo.html" title="BPropertyInfo"><code class="classname">BPropertyInfo</code></a>
is a simple class that manages scripting. A program
describes its scripting interface to a
<a class="link" href="BPropertyInfo.html" title="BPropertyInfo"><code class="classname">BPropertyInfo</code></a>
object through an array of
<a class="link" href="BPropertyInfo.html#property_info" title="property_info"><span class="type">property_info</span></a>
structures, with each entry describing a piece of
the scripting suite.</p><p>A <a class="link" href="BPropertyInfo.html" title="BPropertyInfo"><code class="classname">BPropertyInfo</code></a> is instantiated by passing a zero-terminated array of
<a class="link" href="BPropertyInfo.html#property_info" title="property_info"><span class="type">property_info</span></a>
to its constructor. A typical initialization looks like:</p><pre class="programlisting example cpp">static <span class="type">property_info</span> <code class="varname">prop_list</code>[] = {
{ "duck",
{ <code class="constant">B_GET_PROPERTY</code>, <code class="constant">B_SET_PROPERTY</code>, 0 },
{ <code class="constant">B_DIRECT_SPECIFIER</code>, <code class="constant">B_INDEX_SPECIFIER</code>, 0 },
"get or set duck"
},
{ "head",
{ <code class="constant">B_GET_PROPERTY</code>, 0 },
{ <code class="constant">B_DIRECT_SPECIFIER</code>, 0 },
"get head"
},
{ "head",
{ <code class="constant">B_SET_PROPERTY</code>, 0 },
{ <code class="constant">B_DIRECT_SPECIFIER</code>, 0 },
"set head"
},
{ "feet",
{0}, {0}, "can do anything with his orange feet"
},
0 <span class="comment">// terminate list</span>};
<code class="classname">BPropertyInfo</code> <code class="varname">prop_info</code>(<code class="varname">prop_list</code>);
</pre><p>Since <a class="link" href="BPropertyInfo.html" title="BPropertyInfo"><code class="classname">BPropertyInfo</code></a> only stores a pointer to the array, it is important
that the life span of the array is at least as long as that of the
<a class="link" href="BPropertyInfo.html" title="BPropertyInfo"><code class="classname">BPropertyInfo</code></a> object.
</p><p>Notice that <a class="link" href="BPropertyInfo.html" title="BPropertyInfo"><code class="classname">BPropertyInfo</code></a> doesn't impose any particular structure upon
the array; in particular, not all commands and specifiers for a given
property need be placed in a single entry in the array. You are free to
organize your scripting suite in whatever manner is most convenient for
your particular object.
</p><p><a class="link" href="BPropertyInfo.html" title="BPropertyInfo"><code class="classname">BPropertyInfo</code></a> is a descendant of
<a class="link" href="BFlattenable.html" title="BFlattenable"><code class="classname">BFlattenable</code></a>,
and can therefore be used to store a description of an object's supported scripting suite. This is
particularly useful when overriding
<a class="link" href="BApplication.html#BApplication_GetSupportedSuites" title="GetSupportedSuites()"><code class="methodname">GetSupportedSuites()</code></a>:
</p><pre class="programlisting example cpp"><span class="type">status_t</span> <code class="classname">MyHandler</code>::<code class="methodname">GetSupportedSuites</code>(<span class="type">BMessage *</span><code class="parameter">msg</code>)
{
<code class="parameter">msg</code>-&gt;<code class="methodname">AddString</code>("suites", "suite/vnd.Me-my_handler");
<code class="classname">BPropertyInfo</code> <code class="varname">prop_info</code>(<code class="varname">prop_list</code>);
<code class="parameter">msg</code>-&gt;<code class="methodname">AddFlat</code>("messages", &amp;<code class="varname">prop_info</code>);
return <span class="emphasis"><em><code class="classname">baseClass</code></em></span>::<code class="methodname">GetSupportedSuites</code>(<code class="parameter">msg</code>);
}</pre><p>Naturally, <a class="link" href="BPropertyInfo.html" title="BPropertyInfo"><code class="classname">BPropertyInfo</code></a> is equally as useful in interpreting the results
obtained from querying an object for its supported suites.
</p><p><a class="link" href="BPropertyInfo.html" title="BPropertyInfo"><code class="classname">BPropertyInfo</code></a> defines the
<a class="link" href="BPropertyInfo.html#BPropertyInfo_FindMatch" title="FindMatch()"><code class="methodname">FindMatch()</code></a>
method designed to simplify the implementation of
<a class="link" href="BHandler.html#BHandler_ResolveSpecifier" title="ResolveSpecifier()"><code class="methodname">ResolveSpecifier()</code></a>.
It returns the index of the
property info matching the description given to it, or -1 if none match.
This reduces
<a class="link" href="BHandler.html#BHandler_ResolveSpecifier" title="ResolveSpecifier()"><code class="methodname">ResolveSpecifier()</code></a>
in the simplest cases to:
</p><pre class="programlisting example cpp"><span class="type">BHandler*</span>
<code class="classname">MyHandler</code>::<code class="methodname">ResolveSpecifier</code>(<span class="type">BMessage* </span><code class="parameter">msg</code>, <span class="type">int32</span> <code class="parameter">index</code>,
<span class="type">BMessage*</span> <code class="parameter">spec</code>, <span class="type">int32</span> <code class="parameter">form</code>,
<span class="type">const char*</span> <code class="parameter">prop</code>)
{
<code class="classname">BPropertyInfo</code> <code class="varname">prop_info</code>(<code class="varname">prop_list</code>);
if (<code class="varname">prop_info</code>.<code class="methodname">FindMatch</code>(<code class="parameter">msg</code>, <code class="parameter">index</code>, <code class="parameter">spec</code>, <code class="parameter">form</code>, <code class="parameter">prop</code>) &gt;= 0)
return <code class="varname">this</code>;
return <span class="emphasis"><em><code class="classname">baseClass</code></em></span>::<code class="methodname">ResolveSpecifier</code>(<code class="parameter">msg</code>, <code class="parameter">index</code>, <code class="parameter">spec</code>, <code class="parameter">form</code>,
<code class="parameter">prop</code>);
}</pre><p>Of course, for more complicated objects,
<a class="link" href="BHandler.html#BHandler_ResolveSpecifier" title="ResolveSpecifier()"><code class="methodname">ResolveSpecifier()</code></a>
may need to
set the target handler to an object other than itself, so more processing
may be required. In those cases, the object can use the index returned by
<a class="link" href="BPropertyInfo.html#BPropertyInfo_FindMatch" title="FindMatch()"><code class="methodname">FindMatch()</code></a>
to help it determine the target of the scripting message.
</p></div><div id="footer"><hr /><div id="footerT">Prev: <a href="BMessenger_Overview.html">BMessenger</a>  Up: <a href="TheApplicationKit_Overview.html">The Application Kit</a>  Next: <a href="BRoster_Overview.html">BRoster</a> </div><div id="footerB"><div id="footerBL"><a href="BMessenger_Overview.html" title="BMessenger"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a href="TheApplicationKit_Overview.html" title="The Application Kit"><img src="./images/navigation/up.png" alt="Up" /></a> <a href="BRoster_Overview.html" title="BRoster"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="footerBR"><div><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div></div><div id="footerBC"><a href="http://www.access-company.com/home.html" title="ACCESS Co."><img alt="Access Company" src="./images/access_logo.png" /></a></div></div></div><div id="licenseFooter"><div id="licenseFooterBL"><a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/" title="Creative Commons License"><img alt="Creative Commons License" style="border-width:0" src="https://licensebuttons.net/l/by-nc-nd/3.0/88x31.png" /></a></div><div id="licenseFooterBR"><a href="./LegalNotice.html">Legal Notice</a></div><div id="licenseFooterBC"><span id="licenseText">This work is licensed under a
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/">Creative
Commons Attribution-Non commercial-No Derivative Works 3.0 License</a>.</span></div></div></body></html>