- infos = Information about the mathcheck plugin is in keys below
- infos/author = Thomas Waser thoma.nosp@m.s.wa.nosp@m.ser@l.nosp@m.ibel.nosp@m.ektra.nosp@m..org
- infos/licence = BSD
- infos/provides = check
- infos/needs =
- infos/placements = presetstorage
- infos/status = maintained unittest shelltest nodep discouraged
- infos/metadata = check/math
- infos/description = validates a set of keys through a mathematical expression
Compares a key value to a mathematical expression using polish prefix notation defined in the check/math
metakey. Operations are + - / *
. Operants are keys with names relative to the parent key. How the values are compared is specified at the beginning of the metakey using the conditions <, <=, ==, !=, =>, >, :=
:=
is used to set key values. All values are interpreted as double
floating point values.
Keynames
Keynames are all either relative to to-be-tested key (starting with ./
or ../
), relative to the parentkey (starting with @/
) or absolute (e.g. system/key
).
Examples
check/math = "== + ../testval1 + ../testval2 ../testval3"
compares the keyvalue to the sum of testval1-3 and yields an error if the values are not equal. check/math = "\<= - \@/testval1 * \@/testval2 \@/testval3"
tests if the keyvalue is less than or equal to testval1 - (testval2 * testval3)
and yields an error if not.
Full example:
1 # Backup-and-Restore:/tests/mathcheck
3 sudo kdb mount mathcheck.dump /tests/mathcheck mathcheck
5 kdb set /tests/mathcheck/a 3.1
6 kdb set /tests/mathcheck/b 4.5
7 kdb set /tests/mathcheck/k 7.6
8 kdb setmeta /tests/mathcheck/k check/math "== + ../a ../b"
11 kdb set /tests/mathcheck/k 7.7
15 # The command set failed while accessing the key database with the info:
16 # Error (#123) occurred!
17 # Description: invalid value
20 # At: /home/thomas/Dev/Elektra/libelektra/src/plugins/mathcheck/mathcheck.c:399
22 # Mountpoint: /tests/mathcheck
23 # Configfile: /home/thomas/.config/mathcheck.dump.25680:1478749409.938013.tmp
To calculate values on-demand you can use:
1 kdb setmeta /tests/mathcheck/k check/math ":= + @/a @/b"
2 kdb set /tests/mathcheck/a 8.0
3 kdb set /tests/mathcheck/b 4.5
5 kdb get /tests/mathcheck/k
8 kdb set /tests/mathcheck/a 5.5
10 kdb get /tests/mathcheck/k
It also works with constants:
1 kdb setmeta /tests/mathcheck/k check/math ":= + ../a '5'"
2 kdb set /tests/mathcheck/a 5.5
4 kdb get /tests/mathcheck/k
7 kdb set /tests/mathcheck/a 8.0
9 kdb get /tests/mathcheck/k
13 kdb rm -r /tests/mathcheck
14 sudo kdb umount /tests/mathcheck