  
  [1X14 [5Xsimpcomp[1X internals[0X
  
  The  package [5Xsimpcomp[0m works with simplicial complexes for which a [5XGAP[0m object
  type  [10XSCSimplicialComplex[0m  is  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.
  
  
  [1X14.1 The [5XGAP[1X object type [10XSCPropertyObject[1X[0X
  
  The  following functions compute basic properties of simplicial complexes of
  type  [10XSCSimplicialComplex[0m.  None  of  these functions alter the complex. All
  properties  are returned as immutable objects (this ensures data consistency
  of  the  cached  properties of a simplicial complex). Use [10XShallowCopy[0m or the
  internal [5Xsimpcomp[0m function [10XSCIntFunc.DeepCopy[0m to get a mutable copy.
  
  Note: every simplicial complex is internally stored with the standard vertex
  labeling from 1 to n and a maptable to restore the original vertex labeling.
  Thus,  we  have  to  relabel  some  of  the complex properties (facets, face
  lattice, generators, etc...) whenever we want to return them to the user. As
  a  consequence,  some  of  the  functions  exist twice, one of them with the
  appendix  "Ex".  These  functions  return  the standard labeling whereas the
  other ones relabel the result to the original labeling.
  
  [1X14.1-1 SCProperties[0m
  
  [2X> SCProperties( [0X[3Xpo[0X[2X ) _______________________________________________[0Xfunction
  [6XReturns:[0X  a record upon success.
  
  Returns the record of all stored properties of the [10XSCPropertyObject[0m [3Xpo[0m.
  
  [1X14.1-2 SCPropertiesFlush[0m
  
  [2X> SCPropertiesFlush( [0X[3Xpo[0X[2X ) __________________________________________[0Xfunction
  [6XReturns:[0X  [9Xtrue[0m upon success.
  
  Drops all properties and temporary properties of the [10XSCPropertyObject[0m [3Xpo[0m.
  
  [1X14.1-3 SCPropertiesManaged[0m
  
  [2X> SCPropertiesManaged( [0X[3Xpo[0X[2X ) ________________________________________[0Xfunction
  [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 ([14X14.1-9[0m).
  
  [1X14.1-4 SCPropertiesNames[0m
  
  [2X> SCPropertiesNames( [0X[3Xpo[0X[2X ) __________________________________________[0Xfunction
  [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 ([14X14.1-10[0m) and
  [2XSCPropertyDrop[0m ([14X14.1-8[0m).
  
  [1X14.1-5 SCPropertiesTmp[0m
  
  [2X> SCPropertiesTmp( [0X[3Xpo[0X[2X ) ____________________________________________[0Xfunction
  [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.
  
  [1X14.1-6 SCPropertiesTmpNames[0m
  
  [2X> SCPropertiesTmpNames( [0X[3Xpo[0X[2X ) _______________________________________[0Xfunction
  [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 ([14X14.1-14[0m)
  and [2XSCPropertyTmpDrop[0m ([14X14.1-13[0m).
  
  [1X14.1-7 SCPropertyByName[0m
  
  [2X> SCPropertyByName( [0X[3Xpo, name[0X[2X ) _____________________________________[0Xfunction
  [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 ([14X14.1-4[0m)
  
  [1X14.1-8 SCPropertyDrop[0m
  
  [2X> SCPropertyDrop( [0X[3Xpo, name[0X[2X ) _______________________________________[0Xfunction
  [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.
  
  [1X14.1-9 SCPropertyHandlersSet[0m
  
  [2X> SCPropertyHandlersSet( [0X[3Xpo, handlers[0X[2X ) ____________________________[0Xfunction
  [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.
  
  [1X14.1-10 SCPropertySet[0m
  
  [2X> SCPropertySet( [0X[3Xpo, name, data[0X[2X ) __________________________________[0Xfunction
  [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 ([14X14.1-11[0m) instead.
  
  [1X14.1-11 SCPropertySetMutable[0m
  
  [2X> SCPropertySetMutable( [0X[3Xpo, name, data[0X[2X ) ___________________________[0Xfunction
  [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. If this behaviour is not
  desired, use [2XSCPropertySet[0m ([14X14.1-10[0m) instead.
  
  [1X14.1-12 SCPropertyTmpByName[0m
  
  [2X> SCPropertyTmpByName( [0X[3Xpo, name[0X[2X ) __________________________________[0Xfunction
  [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 ([14X14.1-6[0m)
  
  [1X14.1-13 SCPropertyTmpDrop[0m
  
  [2X> SCPropertyTmpDrop( [0X[3Xpo, name[0X[2X ) ____________________________________[0Xfunction
  [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.
  
  [1X14.1-14 SCPropertyTmpSet[0m
  
  [2X> SCPropertyTmpSet( [0X[3Xpo, name, data[0X[2X ) _______________________________[0Xfunction
  [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.
  
  
  [1X14.2 Example of a common property handler[0X
  
  In   this   section   we   will   have   a  look  at  the  property  handler
  [2XSCEulerCharacteristic[0m  ([14X4.7-9[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
    [4XInstallGlobalFunction(SCEulerCharacteristic,[0X
    [4X	function(complex)[0X
    [4X[0X
    [4X	local f, chi, i;[0X
    [4X	[0X
    [4X	if(not SCIsSimplicialComplex(complex)) then[0X
    [4X		Info(InfoSimpcomp,1,"SCEulerCharacteristic: first argument [0X
    [4X		must be of type SCSimplicialComplex.");[0X
    [4X		return fail;[0X
    [4X	fi;[0X
    [4X[0X
    [4X[0X
    [4X	chi:=SCPropertyByName(complex,"Chi");[0X
    [4X	if chi<>fail and IsInt(chi) then[0X
    [4X		return chi;[0X
    [4X	else[0X
    [4X		SCPropertyDrop(complex,"Chi");[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		SCPropertySet(complex,"Chi",chi);[0X
    [4X		return chi;[0X
    [4X	fi;[0X
    [4X[0X
    [4Xend);[0X
  [4X------------------------------------------------------------------[0X
  
  When  looking  at the code one already see the structure that such a handler
  needs to have:
  
  (1)   The arguments are checked for validity -- in case of invalid arguments
        an  error  is signaled with [10XInfo(InfoSimpcomp,1,"Error message.");[0m and
        the function returns fail.
  
  (2)   It  is  checked  whether  the  property  was computed already with the
        function  [10XSCPropertyByName[0m -- it takes a complex (as [10XSCPropertyObject[0m)
        and  a property name (as [10XString[0m) as arguments and returns the property
        or [9Xfail[0m if that property does not exist.
  
  (3)   If [10XSCPropertyByName[0m did not return [9Xfail[0m and the cached property passes
        a validity check the cached property is returned.
  
  (4)   Otherwise   the   property   is   first   dropped   via  the  function
        [10XSCPropertyDrop[0m  --  it  takes  a  complex  (as [10XSCPropertyObject[0m) and a
        property  name (as [10XString[0m) as arguments -- then recomputed and finally
        written back to the complex via the function [10XSCPropertySet[0m (that takes
        a complex, a property name and a property as arguments) and returned.
  
  
  [1X14.3 Writing a property handler[0X
  
  This  section  provides  the skeleton of a property handler that can be used
  when writing own property handlers:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4XInstallGlobalFunction(SCMyPropertyHandler,[0X
    [4X	function(complex[, further arguments])[0X
    [4X[0X
    [4X	local myprop, ...;[0X
    [4X	[0X
    [4X	# test arguments[0X
    [4X	if(not SCIsSimplicialComplex(complex)) then[0X
    [4X		Info(InfoSimpcomp,1,"SCMyPropertyHandler: first argument [0X
    [4X		must be of type SCSimplicialComplex.");[0X
    [4X		return fail;[0X
    [4X	fi;[0X
    [4X[0X
    [4X	# check if the property that you want to compute is cached[0X
    [4X	myprop:=SCPropertyByName(complex,"MyProperty");[0X
    [4X[0X
    [4X	if myprop<>fail and [check of validity of myprop here] then[0X
    [4X		return myprop;[0X
    [4X	else[0X
    [4X		# first drop the property[0X
    [4X		SCPropertyDrop(complex,"MyProperty");[0X
    [4X		[0X
    [4X		# now (re)compute the property[0X
    [4X		[ do property computation here][0X
    [4X		[0X
    [4X		# set the newly created property and return it [0X
    [4X		SCPropertySet(complex,"MyProperty",myprop);[0X
    [4X		return myprop;[0X
    [4X	fi;[0X
    [4Xend);[0X
  [4X------------------------------------------------------------------[0X
  
