Home > classes > @param > eq.m

eq

PURPOSE ^

EQ overloads the == operator for param objects.

SYNOPSIS ^

function result = eq(c1,c2, varargin)

DESCRIPTION ^

 EQ overloads the == operator for param objects.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: EQ overloads the == operator for param objects.

              All fields are checked.

 CALL:        result = eq(c1,c2)
              result = eq(c1,c2,  exc_list)
              result = eq(c1,c2, 'property1', 'property2')
              result = eq(c1,c2, 'class/property', 'class/property')

 EXAMPLES:    result = eq(c1,c2, 'name', 'created')
              result = eq(c1,c2, 'ao/name')

 INPUTS:      c1,c2    - input param objects
              exc_list - exception list
                         List of properties which are not checked.

 OUTPUTS:     If the two param objects are considered equal, result == 1,
              otherwise, result == 0.

 VERSION:     $Id$

 HISTORY:     29-08-2007 M Hewitson
                 Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function result = eq(c1,c2, varargin)
0002 
0003 % EQ overloads the == operator for param objects.
0004 %
0005 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0006 %
0007 % DESCRIPTION: EQ overloads the == operator for param objects.
0008 %
0009 %              All fields are checked.
0010 %
0011 % CALL:        result = eq(c1,c2)
0012 %              result = eq(c1,c2,  exc_list)
0013 %              result = eq(c1,c2, 'property1', 'property2')
0014 %              result = eq(c1,c2, 'class/property', 'class/property')
0015 %
0016 % EXAMPLES:    result = eq(c1,c2, 'name', 'created')
0017 %              result = eq(c1,c2, 'ao/name')
0018 %
0019 % INPUTS:      c1,c2    - input param objects
0020 %              exc_list - exception list
0021 %                         List of properties which are not checked.
0022 %
0023 % OUTPUTS:     If the two param objects are considered equal, result == 1,
0024 %              otherwise, result == 0.
0025 %
0026 % VERSION:     $Id$
0027 %
0028 % HISTORY:     29-08-2007 M Hewitson
0029 %                 Creation
0030 %
0031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0032 
0033 result = 1;
0034 
0035 %% Check class
0036 if ~strcmp(class(c1), class(c2))
0037   result = 0;
0038   return
0039 end
0040 
0041 fields = fieldnames(c1);
0042 
0043 for ii = 1:length(fields)
0044   field   = fields{ii};
0045 
0046   ck_field = {field, ['param/' field]};
0047 
0048   %% Check tag
0049   if ~(any(ismember(ck_field, varargin)))
0050 
0051     if isobject(c1.(field))
0052       if ~eq(c1.(field), c2.(field), varargin{:})
0053         result = 0;
0054         disp(sprintf('\nNOT EQUAL: %s.%s', class(c1), field));
0055         return
0056       end
0057     else
0058       if ~isequalwithequalnans(c1.(field), c2.(field))
0059         result = 0;
0060         disp(sprintf('\nNOT EQUAL: %s.%s', class(c1), field));
0061         return
0062       end
0063     end
0064 
0065   end
0066 end
0067 
0068 
0069 % function result = eq(p1,p2, varargin)
0070 %
0071 % % EQ overloads the == operator for param objects.
0072 % %
0073 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0074 % %
0075 % % DESCRIPTION: EQ overloads the == operator for param objects.
0076 % %
0077 % %              The 'key' and 'val' fields are checked.
0078 % %
0079 % % CALL:        result = eq(p1,p2)
0080 % %
0081 % % INPUTS:      p1,p2 - input param objects
0082 % %
0083 % % OUTPUTS:     If the two param objects are considered equal, result == 1,
0084 % %              otherwise, result == 0.
0085 % %
0086 % % VERSION:     $Id: param.m,v 1.7 2007/08/17 11:22:11 ingo Exp $
0087 % %
0088 % % HISTORY:     29-08-2007 M Hewitson
0089 % %                 Creation
0090 % %
0091 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0092 %
0093 % % Assume equality to begin with
0094 % result = 1;
0095 %
0096 % %% check key
0097 % if ~ismember('key', varargin)
0098 %   if ~strcmp(p1.key, p2.key)
0099 %     result = 0;
0100 %     return
0101 %   end
0102 % end
0103 %
0104 % %% check created
0105 % if ~ismember('created', varargin)
0106 %   if ~eq(p1.created, p2.created)
0107 %     result = 0;
0108 %     return
0109 %   end
0110 % end
0111 %
0112 % %% check name
0113 % if ~ismember('name', varargin)
0114 %   if ~strcmp(p1.name, p2.name)
0115 %     result = 0;
0116 %     return
0117 %   end
0118 % end
0119 %
0120 % %% check value
0121 %
0122 % % do we have objects to compare?
0123 % if ~ismember('val', varargin)
0124 %   if isobject(p1.val) || isobject(p2.val)
0125 %     if ~isobject(p2.val) || ~isobject(p2.val)
0126 %       result = 0;
0127 %       return
0128 %     else
0129 %       if ~eq(p1.val, p2.val)
0130 %         result = 0;
0131 %         return
0132 %       end
0133 %     end
0134 %   else
0135 %     % normal comparison
0136 %     if ischar(p1.val) || ischar(p2.val)
0137 %       if ~ischar(p1.val) || ~ischar(p2.val)
0138 %         result = 0;
0139 %         return
0140 %       else
0141 %         if ~strcmp(p1.val, p2.val)
0142 %           result = 0;
0143 %           return
0144 %         end
0145 %       end
0146 %       % cell comparison
0147 %     elseif iscell(p1.val) || iscell(p2.val)
0148 %       if ~iscell(p1.val) || ~iscell(p2.val)
0149 %         result = 0;
0150 %         return
0151 %       else
0152 %         if ~(cell2mat(p1.val) == cell2mat(p2.val))
0153 %           result = 0;
0154 %           return
0155 %         end
0156 %       end
0157 %     else
0158 %       if p1.val ~= p2.val
0159 %         result = 0;
0160 %         return
0161 %       end
0162 %     end
0163 %   end
0164 % end

Generated on Fri 02-Nov-2007 19:39:27 by m2html © 2003