Home > m > helper > generic_class_fcn > generic_eq.m

generic_eq

PURPOSE ^

EQ overloads the == operator for general objects.

SYNOPSIS ^

function result = generic_eq(obj1, obj2, varargin, DEFAULT_PLIST, VERSION, CATEGORY)

DESCRIPTION ^

 EQ overloads the == operator for general objects.

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

 DESCRIPTION: EQ overloads the == operator for general 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, '<class>/name')

 INPUTS:      obj1, obj2 - Input objects
              exc_list   - Exception list
                           List of properties which are not checked.

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

 VERSION:     $Id: generic_eq.html,v 1.4 2008/03/31 10:27:45 hewitson Exp $

 HISTORY:     18-02-2008 Diepholz
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % EQ overloads the == operator for general objects.
0002 %
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 % DESCRIPTION: EQ overloads the == operator for general objects.
0006 %
0007 %              All fields are checked.
0008 %
0009 % CALL:        result = eq(c1,c2)
0010 %              result = eq(c1,c2,  exc_list)
0011 %              result = eq(c1,c2, 'property1', 'property2')
0012 %              result = eq(c1,c2, '<class>/property', '<class>/property')
0013 %
0014 % EXAMPLES:    result = eq(c1,c2, 'name', 'created')
0015 %              result = eq(c1,c2, '<class>/name')
0016 %
0017 % INPUTS:      obj1, obj2 - Input objects
0018 %              exc_list   - Exception list
0019 %                           List of properties which are not checked.
0020 %
0021 % OUTPUTS:     If the two analysis objects are considered equal,
0022 %              result == 1, otherwise, result == 0.
0023 %
0024 % VERSION:     $Id: generic_eq.html,v 1.4 2008/03/31 10:27:45 hewitson Exp $
0025 %
0026 % HISTORY:     18-02-2008 Diepholz
0027 %                 Creation
0028 %
0029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0030 function result = generic_eq(obj1, obj2, varargin, DEFAULT_PLIST, VERSION, CATEGORY)
0031 
0032 % Check if this is a call for parameters or for the cvs-version number
0033 if isobject(obj1) && ischar(obj2)
0034   in = char(obj2);
0035   if strcmp(in, 'Params')
0036     result = DEFAULT_PLIST;
0037     return
0038   elseif strcmp(in, 'Version')
0039     result = VERSION;
0040     return
0041   elseif strcmp(in, 'Category')
0042     result = CATEGORY;
0043     return
0044   end
0045 end
0046 
0047 %% Check class
0048 if ~strcmp(class(obj1), class(obj2))
0049   disp(sprintf('\nNOT EQUAL: The objects are not from the same class. [%s] <-> [%s]', class(obj1), class(obj2)));
0050   result = 0;
0051   return
0052 end
0053 
0054 %% Check length of obj1 and obj2
0055 if numel(obj1) ~= numel(obj2)
0056   disp(sprintf('\nNOT EQUAL: The size of the %s-object''s. [%d] <-> [%d]', class(obj1), numel(obj1), numel(obj2)));
0057   result = 0;
0058   return
0059 end
0060 
0061 exception_list = varargin;
0062 
0063 %% Convert a potential existing plist into a exception
0064 if ~isempty(exception_list) && isa(exception_list{1}, 'plist')
0065   exception_list = find(exception_list{1}, 'Exceptions');
0066   if isempty(exception_list)
0067     exception_list = cell(0);
0068   elseif ~iscell(exception_list)
0069     exception_list = cellstr(exception_list);
0070   end
0071 end
0072 
0073 %% for each element in obj1 and obj2
0074 for jj = 1:numel(obj1)
0075 
0076   result = 1;
0077 
0078   fields = fieldnames(obj1(jj));
0079 
0080   for ii = 1:length(fields)
0081     field   = fields{ii};
0082 
0083     %% Creates the exception list for the current field.
0084     %% For example: {'name', 'ao/name'}
0085     ck_field = {field, sprintf('%s/%s', class(obj1), field)};
0086 
0087     % Special case (for the ao- and history-class):
0088     % Is the field = 'hist', 'inhists' then add 'history' to the exception list.
0089     %% For example: {'history', 'ao/history'}
0090     if ismember(field, {'hist', 'inhists'})
0091       ck_field{end+1} = 'history';
0092       ck_field{end+1} = sprintf('%s/history', class(obj1));
0093     elseif strcmp(field, 'val')
0094       ck_field{end+1} = 'value';
0095       ck_field{end+1} = sprintf('%s/value', class(obj1));
0096     end
0097 
0098     %% Check field if it is not in the exception list
0099     if ~(any(ismember(ck_field, exception_list)))
0100 
0101       %% Is the property an object
0102       if isobject(obj1(jj).(field))
0103 
0104         %% Check the length of the property
0105         if length(obj1(jj).(field)) ~= length(obj2(jj).(field))
0106           disp(sprintf('\nNOT EQUAL: The property [%s] of the object [%s] have not the same size', field, class(obj1)));
0107           result = 0;
0108           return
0109         end
0110 
0111         %% For each element of the property
0112         for kk = 1:numel(obj1(jj).(field))
0113           if ~eq(obj1(jj).(field)(kk), obj2(jj).(field)(kk), exception_list{:})
0114             result = 0;
0115             if numel(obj1(jj).(field)) > 1
0116               disp(sprintf('\nNOT EQUAL: %s.%s (%d. element)', class(obj1(jj)), field, kk));
0117             else
0118               disp(sprintf('\nNOT EQUAL: %s.%s', class(obj1(jj)), field));
0119             end
0120             return
0121           end
0122         end
0123       else
0124         if ~isequalwithequalnans(obj1(jj).(field), obj2(jj).(field))
0125           result = 0;
0126           if numel(obj1(jj)) > 1
0127             disp(sprintf('\nNOT EQUAL: %s.%s (%d. object)', class(obj1(jj)), field, jj));
0128           else
0129             disp(sprintf('\nNOT EQUAL: %s.%s', class(obj1(jj)), field));
0130           end
0131           return
0132         end
0133       end
0134 
0135     end
0136   end
0137 
0138 end
0139

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003