Mercurial > repos > public > sbplib
changeset 583:75f9b7a80f28 feature/grids
Allow more than one type in type assertion
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 07 Sep 2017 14:08:31 +0200 |
parents | ce44af8d7dd1 |
children | b0386d2c180d |
files | assertType.m isAnyOf.m |
diffstat | 2 files changed, 19 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
diff -r ce44af8d7dd1 -r 75f9b7a80f28 assertType.m --- a/assertType.m Thu Sep 07 10:21:15 2017 +0200 +++ b/assertType.m Thu Sep 07 14:08:31 2017 +0200 @@ -1,5 +1,11 @@ function assertType(obj, type) - if ~isa(obj, type) - error('sbplib:assertType:wrongType', '"%s" must have type "%s", found "%s"', inputname(1), type, class(obj)); + if ~iscell(type) + if ~isa(obj, type) + error('sbplib:assertType:wrongType', '"%s" must have type "%s", found "%s"', inputname(1), type, class(obj)); + end + else + if ~isAnyOf(obj, type) + error('sbplib:assertType:wrongType', '"%s" must be one of the types %s, found "%s"', inputname(1), toString(type), class(obj)); + end end end
diff -r ce44af8d7dd1 -r 75f9b7a80f28 isAnyOf.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/isAnyOf.m Thu Sep 07 14:08:31 2017 +0200 @@ -0,0 +1,11 @@ +% Returns true of obj is any of he types in the cell array types +% b = isAnyOf(obj, types) +function b = isAnyOf(obj, types) + for i = 1:length(types) + if isa(obj, types{i}); + b = true; + return + end + end + b = false; +end \ No newline at end of file