<p>The package <strong class="pkg">simpcomp</strong> works with geometric objects for which the <strong class="pkg">GAP</strong> object types <code class="code">SCSimplicialComplex</code> and <code class="code">SCNormalSurface</code> are defined and calculates properties of these objects via so called property handlers. This chapter describes how to extend <strong class="pkg">simpcomp</strong> by writing own property handlers.</p>
<p>If you extended <strong class="pkg">simpcomp</strong> and want to share your extension with other users please send your extension to one of the authors and we will consider including it (of course with giving credit) in a future release of <strong class="pkg">simpcomp</strong>.</p>
<h4>18.1 <span class="Heading">The <strong class="pkg">GAP</strong> object type <code class="code">SCPropertyObject</code></span></h4>
<p>In the following, we present a number of functions to manage a <strong class="pkg">GAP</strong> object of type <code class="code">SCPropertyObject</code>. Since most properties of <code class="code">SCPolyhedralComplex</code>, <code class="code">SCSimplicialComplex</code> and <code class="code">SCNormalSurface</code> are managed by the GAP4 type system (cf. <a href="chapBib.html#biBBreuer98GAP4TypeSystem">[BL98]</a>), the functions described below are mainly used by the object type <code class="code">SCLibRepository</code> and to store temporary properties.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SCPropertiesManaged</code>( <var class="Arg">po</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p>Returns: a list of managed properties upon success, <code class="keyw">fail</code> otherwise.</p>
<p>Returns a list of all properties that are managed for the <code class="code">SCPropertyObject</code> <var class="Arg">po</var> via property handler functions. See <code class="func">SCPropertyHandlersSet</code> (<a href="chap18.html#X7FC306B28335BFDC"><span class="RefLink">18.1-9</span></a>).</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SCPropertiesNames</code>( <var class="Arg">po</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p>Returns: a list upon success.</p>
<p>Returns a list of all the names of the stored properties of the <code class="code">SCPropertyObject</code> <var class="Arg">po</var>. These can be accessed via <code class="func">SCPropertySet</code> (<a href="chap18.html#X86FEBD517B7963C6"><span class="RefLink">18.1-10</span></a>) and <code class="func">SCPropertyDrop</code> (<a href="chap18.html#X8304C9BC7E8CF4F8"><span class="RefLink">18.1-8</span></a>).</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SCPropertiesTmp</code>( <var class="Arg">po</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p>Returns: a record upon success.</p>
<p>Returns the record of all stored temporary properties (these are mutable in contrast to regular properties and not serialized when the object is serialized to XML) of the <code class="code">SCPropertyObject</code> <var class="Arg">po</var>.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SCPropertiesTmpNames</code>( <var class="Arg">po</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p>Returns: a list upon success.</p>
<p>Returns a list of all the names of the stored temporary properties of the <code class="code">SCPropertyObject</code> <var class="Arg">po</var>. These can be accessed via <code class="func">SCPropertyTmpSet</code> (<a href="chap18.html#X86CF3B9585A965A0"><span class="RefLink">18.1-14</span></a>) and <code class="func">SCPropertyTmpDrop</code> (<a href="chap18.html#X836F936B7E09E5F1"><span class="RefLink">18.1-13</span></a>).</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SCPropertyByName</code>( <var class="Arg">po</var>, <var class="Arg">name</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p>Returns: any value upon success, <code class="keyw">fail</code> otherwise.</p>
<p>Returns the value of the property with name <var class="Arg">name</var> of the <code class="code">SCPropertyObject</code> <var class="Arg">po</var> if this property is known for <var class="Arg">po</var> and <code class="keyw">fail</code> otherwise. The names of known properties can be accessed via the function <code class="func">SCPropertiesNames</code> (<a href="chap18.html#X82EA577A830E0826"><span class="RefLink">18.1-4</span></a>)</p>
<p>Drops the property with name <var class="Arg">name</var> of the <code class="code">SCPropertyObject</code> <var class="Arg">po</var>. Returns <code class="keyw">true</code> if the property is successfully dropped and <code class="keyw">fail</code> if a property with that name did not exist.</p>
<p>Sets the property handling functions for a SCPropertyObject <var class="Arg">po</var> to the functions described in the record <var class="Arg">handlers</var>. The record <var class="Arg">handlers</var> has to contain entries of the following structure: <code class="code">[Property Name]:=[Function name computing and returning the property]</code>. For <code class="code">SCSimplicialComplex</code> for example <strong class="pkg">simpcomp</strong> defines (among many others): <code class="code">F:=SCFVector</code>. See the file <code class="code">lib/prophandler.gd</code>.</p>
<p>Sets the value of the property with name <var class="Arg">name</var> of the <code class="code">SCPropertyObject</code> <var class="Arg">po</var> to <var class="Arg">data</var>. Note that the argument becomes immutable. If this behaviour is not desired, use <code class="func">SCPropertySetMutable</code> (<a href="chap18.html#X798E9C9C7895C9F0"><span class="RefLink">18.1-11</span></a>) instead.</p>
<p>Sets the value of the property with name <var class="Arg">name</var> of the <code class="code">SCPropertyObject</code> <var class="Arg">po</var> to <var class="Arg">data</var>. Note that the argument does not become immutable. If this behaviour is not desired, use <code class="func">SCPropertySet</code> (<a href="chap18.html#X86FEBD517B7963C6"><span class="RefLink">18.1-10</span></a>) instead.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SCPropertyTmpByName</code>( <var class="Arg">po</var>, <var class="Arg">name</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p>Returns: any value upon success, <code class="keyw">fail</code> otherwise.</p>
<p>Returns the value of the temporary property with the name <var class="Arg">name</var> of the <codeclass="code">SCPropertyObject</code> <var class="Arg">po</var> if this temporary property is known for <var class="Arg">po</var> and <code class="keyw">fail</code> otherwise. The names of known temporary properties can be accessed via the function <code class="func">SCPropertiesTmpNames</code> (<a href="chap18.html#X797A290E8665E6D0"><span class="RefLink">18.1-6</span></a>)</p>
<p>Drops the temporary property with name <var class="Arg">name</var> of the <code class="code">SCPropertyObject</code> <var class="Arg">po</var>. Returns <code class="keyw">true</code> if the property is successfully dropped and <code class="keyw">fail</code> if a temporary property with that name did not exist.</p>
<p>Sets the value of the temporary property with name <var class="Arg">name</var> of the <code class="code">SCPropertyObject</code> <var class="Arg">po</var> to <var class="Arg">data</var>. Note that the argument does not become immutable. This is the standard behaviour for temporary properties.</p>
<h4>18.2 <span class="Heading">Example of a common attribute</span></h4>
<p>In this section we will have a look at the property handler <code class="func">SCEulerCharacteristic</code> (<a href="chap7.html#X788BAE187D584103"><span class="RefLink">7.3-3</span></a>) in order to explain the inner workings of property handlers. This is the code of the property handler for calculating the Euler characteristic of a complex in <strong class="pkg">simpcomp</strong>:</p>
f:=SCFVector(sl);
if(f=fail) then
return fail;
fi;
if Length(f) = 1 then
return f[1];
elif Length(f) =3 then
return f[1]-f[2]+f[3];
elif Length(f) =4 then
return f[1]-f[2]+f[3]+f[4];
else
Info(InfoSimpcomp,1,"SCEulerCharacteristic: illegal f-vector found: ",f,". ");
return fail;
fi;
end);
</pre></div>
<p>When looking at the code one already sees the structure that such a handler needs to have:</p>
<ol>
<li><p>Each property handler (a GAP operation) needs to be defined. This is done by the first line of code. Once an operation is defined, multiple methods can by implemented for various types of GAP objects (here two methods are implemented for the GAP object types <code class="code">SCSimplicialComplex</code> and <code class="code">SCNormalSurface</code>).</p>
</li>
<li><p>First note that the validity of the arguments is checked by GAP. For example, the first method only accepts an argument of type <code class="code">SCSimplicialComplex</code>.</p>
</li>
<li><p>If the property was already computed, the GAP4 type system automatically returns the cached property avoiding unnecessary double calculations.</p>
</li>
<li><p>If the property is not already known. it is computed and returned (and automatically cached by the GAP4 type system).</p>
InstallMethod(SCMyPropertyHandler, "for SCSimplicialComplex[ and further arguments]",
[SCIsSimplicialComplex[, further arguments]],
function(complex[, further arguments])
local myprop, ...;
# compute the property
[ do property computation here]
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.