www.gusucode.com > mbcexpr 工具箱 matlab 源码程序 > mbcexpr/@cgexprconstraint/getEvalDependencies.m

    function [pInp, Funcs] = getEvalDependencies(obj, op)
%GETEVALDEPENDENCIES Get input requirements for an evaluation operation
%
%  [PINP, FUNCS] = GETEVALDEPENDENCIES(OBJ, OP) returns a list of input
%  pointers and the function that should be called on each one in order to
%  generate the inputs for the specified evaluation operation.  OP should
%  be either a string or function handle to an expression method that
%  accepts a cell array of input values and operates on them to produce an
%  output, for example evalAtInputs, cevalAtInputs or pevevalAtInputs.
%
%  For cgexprconstraint objects, the inputs may require a pev, constraint
%  or normal evaluation.

%  Copyright 2005-2007 The MathWorks, Inc. and Ford Global Technologies, Inc.


if isa(op, 'function_handle')
    funcinfo = functions(op);
    op = funcinfo.function;
end

if strcmpi(op, 'lhsevalAtInputs')
    pInp = getlhsexpr(obj);
    [unused, EvalType] = getevaluationmode(obj, 'left');
    Funcs = {i_EvalCodeToFunc(EvalType)};
    
elseif strcmpi(op, 'rhsevalAtInputs')
    pInp = getrhsexpr(obj);
    if ~isnull(pInp)
        [unused, EvalType] = getevaluationmode(obj, 'right');
        Funcs = {i_EvalCodeToFunc(EvalType)};
    else
        % No right-hand expression
        pInp = mbcpointer(1,0);
        Funcs = {};
    end
    
else
    [unused, code] = getvaluemode(obj);
    if ~code || obj.ExprEvalFunc==1
        pInp = getlhsexpr(obj);
    else
        pInp = [getlhsexpr(obj), getrhsexpr(obj)];
    end
    
    Funcs = cell(size(pInp));
    if strcmpi(op, 'natevalAtInputs') || strcmpi(op, 'evalAtInputs') || strcmpi(op, 'cevalAtInputs')
        [unused, EvalType] = getevaluationmode(obj, 'left');
        Funcs{1} = i_EvalCodeToFunc(EvalType);
        if length(Funcs)>1
            [unused, EvalType] = getevaluationmode(obj, 'right');
            Funcs{2} = i_EvalCodeToFunc(EvalType);
        end
    else
        Funcs = repmat({@evalAtInputs}, size(pInp));
    end
end



function hFunc = i_EvalCodeToFunc(Code)
switch Code
    case 0
        hFunc = @evalAtInputs;
    case 1
        hFunc = @cevalAtInputs;
    case 2
        hFunc = @pevevalAtInputs;
end