AddToProp / SubFromProp eingefuehrt
Short-cuts fuer QueryProp() und += bzw. -= gefolgt von einem
SetProp().
Erlaubte Typen sind nur solche, mit denen += und -= was anfangen
koennen und welche zum aktuellen Wert der Property passen.
Change-Id: I699c9c605026e8058e72faad57c6e1a917ab8cb4
diff --git a/std/thing/properties.c b/std/thing/properties.c
index fb70913..5852704 100644
--- a/std/thing/properties.c
+++ b/std/thing/properties.c
@@ -22,7 +22,6 @@
#include "/sys/thing/properties.h"
#include "/secure/wizlevels.h"
-
// the mapping where the actual properties are stored. Direct initialization.
// Indexed with F_VALUE, F_MODE, F_SET_METHOD and F_QUERY_METHOD
// F_MODE, F_SET_METHOD and F_QUERY_METHOD are usually 'sparse' (i.e. there is
@@ -237,6 +236,35 @@
return prop[F_VALUE][name];
}
+// Addiert einen Wert zu einer Prop. Eigentlich ist es nur ein Short-Cut fuer
+// QueryProp und += und SetProp. Dementsprechend gehen auch hier nur
+// Typ-Kombinationen, die += auch kann.
+public mixed AddToProp(string pname,
+ <int|float|string|mixed*|mapping|bytes> add_value)
+{
+ mixed value = QueryProp(pname);
+ string err = catch(value += add_value; nolog);
+ if (err)
+ raise_error(sprintf("Nicht unterstuetzter Typ des Summanden: %s\n",
+ err[strstr(err,":")+2..]));
+
+ return SetProp(pname, value, extern_call());
+}
+
+// "subtrahiert" einen Wert von einer Prop. Eigentlich ist es nur ein
+// Short-Cut fuer QueryProp und -= und SetProp. Dementsprechend gehen auch
+// hier nur Typ-Kombinationen, die -= auch kann.
+public mixed SubFromProp(string pname,
+ <int|float|string|mixed*|mapping|bytes> sub_value)
+{
+ mixed value = QueryProp(pname);
+ string err = catch(value -= sub_value; nolog);
+ if (err)
+ raise_error(sprintf("Nicht unterstuetzter Typ des Subtrahenden: %s\n",
+ err[strstr(err,":")+2..]));
+
+ return SetProp(pname, value, extern_call());
+}
// Viele Properties auf einen Schlag setzen.
// genutzt von simul_efun zum Setzen aller Properties, welche im