Elektra  0.8.24
Plugin: type

This plugin is a type checker plugin using the CORBA data types.

A common and successful type system happens to be CORBA. The system is well suited because of the many well-defined mappings it provides to other programming languages.

The type checker plugin supports all basic CORBA types: short, unsigned_short, long, unsigned_long, long_long, unsigned_long_long, float, double, char, boolean, any and octet. When checking any it will always be successful, regardless of the content.

Deprecation

empty and FSType are deprecated. Please use regular expressions or enums instead.

Sometimes the type should expresses that, for example, both an empty or another type is valid. This type checker allowed a space-separated list of types to expresses that. If any of those types match, the whole type was valid. For example, the type string empty equals the type any. This facility builds a union of the sets of instances existing types specify. It is now deprecated due to a more general sum type facility.

check/type/min and check/type/max are deprecated, please use the range plugin instead.

Example

# Mount the plugin
sudo kdb mount typetest.dump user/tests/type dump type
# Store a character value
kdb set user/tests/type/key a
# Only allow character values
kdb setmeta user/tests/type/key check/type char
kdb get user/tests/type/key
#> a
# If we store another character everything works fine
kdb set user/tests/type/key b
kdb get user/tests/type/key
#> b
# If we try to store a string Elektra will not change the value
kdb set user/tests/type/key 'Not a char'
# STDERR: .*Description: could not type check value of key.*
# ERROR: 52
# RET: 5
kdb get user/tests/type/key
#> b
# Undo modifications to the database
kdb rm user/tests/type/key
sudo kdb umount user/tests/type

Limitations

wchar is missing.

Enum and records are part of other plugins.

The CORBA type system also has its limits. The types string and enum can be unsatisfactory. While string is too general and makes no limit on how the sequence of characters is structured, the enumeration is too finite. For example, it is not possible to say that a string is not allowed to have a specific symbol in it. Combine this plugin with other type checker plugins to circumvent such limitations.