


EQ overloads the == operator for ltpda objects.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DESCRIPTION: EQ overloads the == operator for ltpda objects.
All fields are checked.
CALL: result = eq(obj1,obj2)
result = eq(obj1,obj2, exc_list)
result = eq(obj1,obj2, 'property1', 'property2')
result = eq(obj1,obj2, '<class>/property', '<class>/property')
EXAMPLES: result = eq(obj1,obj2, 'name', 'created')
result = eq(obj1,obj2, '<class>/name')
INPUTS: obj1, obj2 - Input objects
exc_list - Exception list
List of properties which are not checked.
OUTPUTS: If the two objects are considered equal, result == 1,
otherwise, result == 0.
M-FILE INFO: Get information about this methods by calling
>> ao.getInfo('eq')
Get information about a specified set-plist by calling:
>> ao.getInfo('eq', 'set')
VERSION: $Id: eq.m,v 1.7 2008/08/15 11:45:19 ingo Exp $
HISTORY: 18-02-2008 Diepholz
Creation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


0001 % EQ overloads the == operator for ltpda objects. 0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0003 % 0004 % DESCRIPTION: EQ overloads the == operator for ltpda objects. 0005 % 0006 % All fields are checked. 0007 % 0008 % CALL: result = eq(obj1,obj2) 0009 % result = eq(obj1,obj2, exc_list) 0010 % result = eq(obj1,obj2, 'property1', 'property2') 0011 % result = eq(obj1,obj2, '<class>/property', '<class>/property') 0012 % 0013 % EXAMPLES: result = eq(obj1,obj2, 'name', 'created') 0014 % result = eq(obj1,obj2, '<class>/name') 0015 % 0016 % INPUTS: obj1, obj2 - Input objects 0017 % exc_list - Exception list 0018 % List of properties which are not checked. 0019 % 0020 % OUTPUTS: If the two objects are considered equal, result == 1, 0021 % otherwise, result == 0. 0022 % 0023 % M-FILE INFO: Get information about this methods by calling 0024 % >> ao.getInfo('eq') 0025 % 0026 % Get information about a specified set-plist by calling: 0027 % >> ao.getInfo('eq', 'set') 0028 % 0029 % VERSION: $Id: eq.m,v 1.7 2008/08/15 11:45:19 ingo Exp $ 0030 % 0031 % HISTORY: 18-02-2008 Diepholz 0032 % Creation 0033 % 0034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0035 0036 function result = eq(obj1, obj2, varargin) 0037 0038 % Check if this is a call for parameters 0039 hh = {obj1, obj2, varargin{:}}; 0040 if utils.helper.isinfocall(hh{:}) 0041 result = getInfo(varargin{1}); 0042 return 0043 end 0044 0045 import utils.const.* 0046 0047 %%%%% Check class 0048 if ~strcmp(class(obj1), class(obj2)) 0049 utils.helper.msg(msg.PROC1, 'NOT 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 utils.helper.msg(msg.PROC1, 'NOT 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 if isa(obj1(jj).(field), 'sym') 0102 %%%%%%%%%% The property is a sym-object %%%%%%%%%% 0103 if ~eq(obj1(jj).(field), obj2(jj).(field)) 0104 result = 0; 0105 if numel(obj1(jj)) > 1 0106 utils.helper.msg(msg.PROC1, 'NOT EQUAL: %s.%s (%d. object)', class(obj1(jj)), field, jj); 0107 else 0108 utils.helper.msg(msg.PROC1, 'NOT EQUAL: %s.%s', class(obj1(jj)), field); 0109 end 0110 return 0111 end 0112 0113 elseif isobject(obj1(jj).(field)) 0114 %%%%%%%%%% The property is a ltpda-object %%%%%%%%%% 0115 0116 %%%%% Check the length of the property 0117 if length(obj1(jj).(field)) ~= length(obj2(jj).(field)) 0118 utils.helper.msg(msg.PROC1, 'NOT EQUAL: The property [%s] of the object [%s] have not the same size', field, class(obj1)); 0119 result = 0; 0120 return 0121 end 0122 0123 %%%%% For each element of the property 0124 for kk = 1:numel(obj1(jj).(field)) 0125 if ~eq(obj1(jj).(field)(kk), obj2(jj).(field)(kk), exception_list{:}) 0126 result = 0; 0127 if numel(obj1(jj).(field)) > 1 0128 utils.helper.msg(msg.PROC1, 'NOT EQUAL: %s.%s (%d. element)', class(obj1(jj)), field, kk); 0129 else 0130 utils.helper.msg(msg.PROC1, 'NOT EQUAL: %s.%s', class(obj1(jj)), field); 0131 end 0132 return 0133 end 0134 end 0135 0136 else 0137 %%%%%%%%%% The property is an elemental MATLAB datatype %%%%%%%%%% 0138 if ~isequalwithequalnans(obj1(jj).(field), obj2(jj).(field)) 0139 result = 0; 0140 if numel(obj1(jj)) > 1 0141 utils.helper.msg(msg.PROC1, 'NOT EQUAL: %s.%s (%d. object)', class(obj1(jj)), field, jj); 0142 else 0143 utils.helper.msg(msg.PROC1, 'NOT EQUAL: %s.%s', class(obj1(jj)), field); 0144 end 0145 return 0146 end 0147 end 0148 0149 end 0150 end 0151 0152 end 0153 end 0154 0155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0156 % Local Functions % 0157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0158 0159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0160 % 0161 % FUNCTION: getInfo 0162 % 0163 % DESCRIPTION: Get Info Object 0164 % 0165 % HISTORY: 11-07-07 M Hewitson 0166 % Creation. 0167 % 0168 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0169 0170 function ii = getInfo(varargin) 0171 if nargin == 1 && strcmpi(varargin{1}, 'None') 0172 sets = {}; 0173 pl = []; 0174 else 0175 sets = {'Default'}; 0176 pl = getDefaultPlist; 0177 end 0178 % Build info object 0179 ii = minfo(mfilename, 'ltpda_obj', '', 'Relational Operator', '$Id: eq.m,v 1.7 2008/08/15 11:45:19 ingo Exp $', sets, pl); 0180 end 0181 0182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0183 % 0184 % FUNCTION: getDefaultPlist 0185 % 0186 % DESCRIPTION: Get Default Plist 0187 % 0188 % HISTORY: 11-07-07 M Hewitson 0189 % Creation. 0190 % 0191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0192 0193 function plo = getDefaultPlist() 0194 plo = plist(); 0195 end 0196