  
  [1X17 [5Xsimpcomp[1X internals[0X
  
  The  package  [5Xsimpcomp[0m works with geometric objects for which the [5XGAP[0m object
  types  [10XSCSimplicialComplex[0m  and  [10XSCNormalSurface[0m  are defined and calculates
  properties  of  these  objects via so called property handlers. This chapter
  describes how to extend [5Xsimpcomp[0m by writing own property handlers.
  
  If  you  extended [5Xsimpcomp[0m 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 [5Xsimpcomp[0m.
  
  
  [1X17.1 The [5XGAP[1X object type [10XSCPropertyObject[1X[0X
  
  In the following, we present a number of functions to manage a [5XGAP[0m object of
  type   [10XSCPropertyObject[0m.   Since  most  properties  of  [10XSCPolyhedralComplex[0m,
  [10XSCSimplicialComplex[0m  and [10XSCNormalSurface[0m are managed by the GAP4 type system
  (cf.  [BL98]),  the  functions described below are mainly used by the object
  type [10XSCLibRepository[0m and to store temporary properties.
  
  [1X17.1-1 SCProperties[0m
  
  [2X> SCProperties( [0X[3Xpo[0X[2X ) _________________________________________________[0Xmethod
  [6XReturns:[0X  a record upon success.
  
  Returns the record of all stored properties of the [10XSCPropertyObject[0m [3Xpo[0m.
  
  [1X17.1-2 SCPropertiesFlush[0m
  
  [2X> SCPropertiesFlush( [0X[3Xpo[0X[2X ) ____________________________________________[0Xmethod
  [6XReturns:[0X  [9Xtrue[0m upon success.
  
  Drops all properties and temporary properties of the [10XSCPropertyObject[0m [3Xpo[0m.
  
  [1X17.1-3 SCPropertiesManaged[0m
  
  [2X> SCPropertiesManaged( [0X[3Xpo[0X[2X ) __________________________________________[0Xmethod
  [6XReturns:[0X  a list of managed properties upon success, [9Xfail[0m otherwise.
  
  Returns  a  list of all properties that are managed for the [10XSCPropertyObject[0m
  [3Xpo[0m via property handler functions. See [2XSCPropertyHandlersSet[0m ([14X17.1-9[0m).
  
  [1X17.1-4 SCPropertiesNames[0m
  
  [2X> SCPropertiesNames( [0X[3Xpo[0X[2X ) ____________________________________________[0Xmethod
  [6XReturns:[0X  a list upon success.
  
  Returns   a  list  of  all  the  names  of  the  stored  properties  of  the
  [10XSCPropertyObject[0m  [3Xpo[0m.  These can be accessed via [2XSCPropertySet[0m ([14X17.1-10[0m) and
  [2XSCPropertyDrop[0m ([14X17.1-8[0m).
  
  [1X17.1-5 SCPropertiesTmp[0m
  
  [2X> SCPropertiesTmp( [0X[3Xpo[0X[2X ) ______________________________________________[0Xmethod
  [6XReturns:[0X  a record upon success.
  
  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 [10XSCPropertyObject[0m [3Xpo[0m.
  
  [1X17.1-6 SCPropertiesTmpNames[0m
  
  [2X> SCPropertiesTmpNames( [0X[3Xpo[0X[2X ) _________________________________________[0Xmethod
  [6XReturns:[0X  a list upon success.
  
  Returns  a  list  of all the names of the stored temporary properties of the
  [10XSCPropertyObject[0m  [3Xpo[0m.  These  can be accessed via [2XSCPropertyTmpSet[0m ([14X17.1-14[0m)
  and [2XSCPropertyTmpDrop[0m ([14X17.1-13[0m).
  
  [1X17.1-7 SCPropertyByName[0m
  
  [2X> SCPropertyByName( [0X[3Xpo, name[0X[2X ) _______________________________________[0Xmethod
  [6XReturns:[0X  any value upon success, [9Xfail[0m otherwise.
  
  Returns  the value of the property with name [3Xname[0m of the [10XSCPropertyObject[0m [3Xpo[0m
  if  this  property  is  known  for [3Xpo[0m and [9Xfail[0m otherwise. The names of known
  properties can be accessed via the function [2XSCPropertiesNames[0m ([14X17.1-4[0m)
  
  [1X17.1-8 SCPropertyDrop[0m
  
  [2X> SCPropertyDrop( [0X[3Xpo, name[0X[2X ) _________________________________________[0Xmethod
  [6XReturns:[0X  [9Xtrue[0m upopn success, [9Xfail[0m otherwise
  
  Drops  the  property with name [3Xname[0m of the [10XSCPropertyObject[0m [3Xpo[0m. Returns [9Xtrue[0m
  if  the  property  is  successfully dropped and [9Xfail[0m if a property with that
  name did not exist.
  
  [1X17.1-9 SCPropertyHandlersSet[0m
  
  [2X> SCPropertyHandlersSet( [0X[3Xpo, handlers[0X[2X ) ______________________________[0Xmethod
  [6XReturns:[0X  [9Xtrue[0m
  
  Sets  the  property  handling  functions  for  a  SCPropertyObject [3Xpo[0m to the
  functions  described  in  the  record  [3Xhandlers[0m.  The record [3Xhandlers[0m has to
  contain  entries of the following structure: [10X[Property Name]:=[Function name
  computing  and  returning the property][0m. For [10XSCSimplicialComplex[0m for example
  [5Xsimpcomp[0m   defines   (among   many   others):  [10XF:=SCFVector[0m.  See  the  file
  [10Xlib/prophandler.gd[0m.
  
  [1X17.1-10 SCPropertySet[0m
  
  [2X> SCPropertySet( [0X[3Xpo, name, data[0X[2X ) ____________________________________[0Xmethod
  [6XReturns:[0X  [9Xtrue[0m upon success.
  
  Sets  the value of the property with name [3Xname[0m of the [10XSCPropertyObject[0m [3Xpo[0m to
  [3Xdata[0m.  Note  that  the  argument becomes immutable. If this behaviour is not
  desired, use [2XSCPropertySetMutable[0m ([14X17.1-11[0m) instead.
  
  [1X17.1-11 SCPropertySetMutable[0m
  
  [2X> SCPropertySetMutable( [0X[3Xpo, name, data[0X[2X ) _____________________________[0Xmethod
  [6XReturns:[0X  [9Xtrue[0m upon success.
  
  Sets  the value of the property with name [3Xname[0m of the [10XSCPropertyObject[0m [3Xpo[0m to
  [3Xdata[0m. Note that the argument does not become immutable. If this behaviour is
  not desired, use [2XSCPropertySet[0m ([14X17.1-10[0m) instead.
  
  [1X17.1-12 SCPropertyTmpByName[0m
  
  [2X> SCPropertyTmpByName( [0X[3Xpo, name[0X[2X ) ____________________________________[0Xmethod
  [6XReturns:[0X  any value upon success, [9Xfail[0m otherwise.
  
  Returns  the  value  of  the  temporary  property  with the name [3Xname[0m of the
  [10XSCPropertyObject[0m  [3Xpo[0m  if  this  temporary  property is known for [3Xpo[0m and [9Xfail[0m
  otherwise.  The  names of known temporary properties can be accessed via the
  function [2XSCPropertiesTmpNames[0m ([14X17.1-6[0m)
  
  [1X17.1-13 SCPropertyTmpDrop[0m
  
  [2X> SCPropertyTmpDrop( [0X[3Xpo, name[0X[2X ) ______________________________________[0Xmethod
  [6XReturns:[0X  [9Xtrue[0m upon success, [9Xfail[0m otherwise
  
  Drops  the  temporary  property  with  name [3Xname[0m of the [10XSCPropertyObject[0m [3Xpo[0m.
  Returns [9Xtrue[0m if the property is successfully dropped and [9Xfail[0m if a temporary
  property with that name did not exist.
  
  [1X17.1-14 SCPropertyTmpSet[0m
  
  [2X> SCPropertyTmpSet( [0X[3Xpo, name, data[0X[2X ) _________________________________[0Xmethod
  [6XReturns:[0X  [9Xtrue[0m upon success.
  
  Sets   the   value   of  the  temporary  property  with  name  [3Xname[0m  of  the
  [10XSCPropertyObject[0m  [3Xpo[0m  to  [3Xdata[0m.  Note  that  the  argument  does  not become
  immutable. This is the standard behaviour for temporary properties.
  
  
  [1X17.2 Example of a common attribute[0X
  
  In   this   section   we   will   have   a  look  at  the  property  handler
  [2XSCEulerCharacteristic[0m  ([14X7.3-3[0m)  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 [5Xsimpcomp[0m:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4XDeclareAttribute("SCEulerCharacteristic",SCIsPolyhedralComplex);[0X
    [4X[0X
    [4XInstallMethod(SCEulerCharacteristic,[0X
    [4X"for SCSimplicialComplex",[0X
    [4X[SCIsSimplicialComplex],[0X
    [4Xfunction(complex)[0X
    [4X[0X
    [4X	local  f, chi, i;[0X
    [4X[0X
    [4X	f:=SCFVector(complex);[0X
    [4X	if f=fail then[0X
    [4X		return fail;[0X
    [4X	fi;[0X
    [4X	chi:=0;[0X
    [4X[0X
    [4X	for i in [1..Size(f)] do[0X
    [4X			chi:=chi + ((-1)^(i+1))*f[i];[0X
    [4X	od;[0X
    [4X[0X
    [4X	return chi;[0X
    [4Xend);[0X
    [4X[0X
    [4XInstallMethod(SCEulerCharacteristic,[0X
    [4X"for SCNormalSurface",[0X
    [4X[SCIsNormalSurface],[0X
    [4Xfunction(sl)[0X
    [4X[0X
    [4X 	local facets, f, chi;[0X
    [4X[0X
    [4X  	[0X
    [4X 	f:=SCFVector(sl);[0X
    [4X 	if(f=fail) then[0X
    [4X 		return fail;[0X
    [4X 	fi;[0X
    [4X	[0X
    [4X	if Length(f) = 1 then[0X
    [4X	 		return f[1];[0X
    [4X	elif Length(f) =3 then[0X
    [4X 	 		return f[1]-f[2]+f[3];[0X
    [4X 	elif Length(f) =4 then[0X
    [4X 	 		return f[1]-f[2]+f[3]+f[4];[0X
    [4X 	else[0X
    [4X 		Info(InfoSimpcomp,1,"SCEulerCharacteristic: illegal f-vector found: ",f,". ");[0X
    [4X 		return fail;[0X
    [4X 	fi;[0X
    [4X[0X
    [4Xend);[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  When  looking at the code one already sees the structure that such a handler
  needs to have:
  
  (1)   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 [10XSCSimplicialComplex[0m
        and [10XSCNormalSurface[0m).
  
  (2)   First  note  that the validity of the arguments is checked by GAP. For
        example,   the   first   method  only  accepts  an  argument  of  type
        [10XSCSimplicialComplex[0m.
  
  (3)   If   the   property   was  already  computed,  the  GAP4  type  system
        automatically  returns the cached property avoiding unnecessary double
        calculations.
  
  (4)   If the property is not already known. it is computed and returned (and
        automatically cached by the GAP4 type system).
  
  
  [1X17.3 Writing a method for an attribute[0X
  
  This section provides the skeleton of a method that can be used when writing
  own methods:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4XDeclareAttribute("SCMyPropertyHandler",SCPolyhedralComplex);[0X
    [4X[0X
    [4XInstallMethod(SCMyPropertyHandler,[0X
    [4X"for SCSimplicialComplex[ and further arguments]",[0X
    [4X[SCIsSimplicialComplex[, further arguments]],[0X
    [4Xfunction(complex[, further arguments])[0X
    [4X[0X
    [4X	local myprop, ...;[0X
    [4X[0X
    [4X	# compute the property[0X
    [4X [ do property computation here][0X
    [4X[0X
    [4X	return myprop;[0X
    [4Xend);[0X
  [4X------------------------------------------------------------------[0X
  
