TABLE OF CONTENTS
::pwtk::checkOType_
SYNOPSIS
proc ::pwtk::checkOType_ {option value type {typeTxt {}}} {
DESCRIPTION
Check that the value of an option is of correct type.
Note that empty string matches the type (for the opposite behaviour, use the strict version, checkOTypeStrict_)
ARGUMENTS
- option == name of the option
- value == value of the option
- type == type for the value
- typeTxt == [optional, default = $type] a textual-type of value that is printed to error message (for example: type = double, typeTxt = number)
SOURCE
if { $typeTxt == {} } { set typeTxt $type } set option -[string trim $option -] set err "expected a $typeTxt for the value of the $option option, but got: \"$value\"" switch -exact -- [lindex $type 0] { number - numberlist - range - gp_range - gp_size - intseq - rangestring { if { ! [eval ::pwtk::type::$type [list $value]] } { uplevel 1 [list ::pwtk::error $err 1] } } optionlist { set allowedValues [lrange $type 1 end] if { ! [::pwtk::type::optionlist $allowedValues $value] } { uplevel 1 [list ::pwtk::error "expected one of [join $allowedValues {, }] for the value of the $option option, but got: \"$value\"" 1] } } default { if { ! [string is $type $value] } { uplevel 1 [list ::pwtk::error $err 1] } } } }