MatrixBerryCore
processpropvalue.m
Go to the documentation of this file.
1 function valueList=processpropvalue(objSizeVec,value,fTypeCheckFunc)
2 nExpected=prod(objSizeVec);
3 if ~isa(fTypeCheckFunc,'function_handle')
4  mxberry.core.throwerror('wrongInput',...
5  'expectedType is expected to be a function_handle');
6 end
7 if ~(isnumeric(nExpected)&&(fix(nExpected)==nExpected))
8  %&&(nExpected>0))
9  mxberry.core.throwerror('wrongInput',...
10  'nExpected is expected to be an integer positive number');
11 end
12 %
13 valueLength=numel(value);
14 %
15 if fTypeCheckFunc(value)
16  if valueLength==nExpected
17  valueList=num2cell(value);
18  elseif valueLength<=1
19  if valueLength==1&&iscell(value)&&fTypeCheckFunc(value{1})
20  mxberry.core.throwerror('wrongInput',...
21  ['an ambiguous attempt to assign the value: ',...
22  'the value''s type is correct but it is a cell and its content',...
23  'also has a correct type']);
24  end
25  valueList=repmat({value},objSizeVec);
26  else
27  mxberry.core.throwerror('wrongInput',...
28  ['the passed value''s length (%d) doesn''t equal the expected ',...
29  'lenght (%d)'],...
30  valueLength,nExpected);
31  end
32 elseif iscell(value)
33  if (valueLength==nExpected)
34  if all(cellfun(fTypeCheckFunc,value))
35  valueList=value;
36  else
37  mxberry.core.throwerror('wrongInput',...
38  ['all elements of passed cell ',...
39  'array are expected to have the type specified by ',...
40  'function %s '],func2str(fTypeCheckFunc));
41  end
42  elseif valueLength==1
43  valueList=repmat(value,objSizeVec);
44  else
45  mxberry.core.throwerror('wrongInput',...
46  ['the passed value''s length (%d) doesn''t equal the expected ',...
47  'lenght (%d)'],...
48  valueLength,nExpected);
49  end
50 else
51  mxberry.core.throwerror('wrongInput',...
52  'the passed value''s type (%s) is not expected',...
53  class(value));
54 end
function num2cell(in inpArray, in varargin)
NUM2CELL is an extension of Matlab built-in function "num2cell" designed to work correctly with empty...
function throwerror(in msgTag, in varargin)
THROWERROR works similarly to built-in ERROR function in case when there is no output arguments but s...
function repmat(in inpArray, in varargin)
function processpropvalue(in objSizeVec, in value, in fTypeCheckFunc)
PROCESSPROPVALUE is a helper function for assigning property values especially when a set of values s...