comparison scripts/general/private/__isequal__.m @ 11459:990c9cb52e5f

__isequal__: compare objects as if they are structures
author John W. Eaton <jwe@octave.org>
date Fri, 07 Jan 2011 14:48:55 -0500
parents 01ddaedd6ad5
children caf1fd72f587
comparison
equal deleted inserted replaced
11458:93a039fe681e 11459:990c9cb52e5f
57 ## Generic tests. 57 ## Generic tests.
58 58
59 ## All arguments must either be of the same class or they must be 59 ## All arguments must either be of the same class or they must be
60 ## numeric values. 60 ## numeric values.
61 t = (all (strcmp (class(x), 61 t = (all (strcmp (class(x),
62 cellfun (@class, varargin, "uniformoutput", false))) 62 cellfun (@class, varargin, "uniformoutput", false)))
63 || ((isnumeric (x) || islogical (x)) 63 || ((isnumeric (x) || islogical (x))
64 && all (cellfun (@isnumeric, varargin) 64 && all (cellfun (@isnumeric, varargin)
65 | cellfun (@islogical, varargin)))); 65 | cellfun (@islogical, varargin))));
66 66
67 if (t) 67 if (t)
79 idx = 0; 79 idx = 0;
80 while (t && idx < l_x) 80 while (t && idx < l_x)
81 idx++; 81 idx++;
82 t = all (s_x(idx) == s_v(idx,:)); 82 t = all (s_x(idx) == s_v(idx,:));
83 endwhile 83 endwhile
84 endif
85
86 ## From here on, compare objects as if they were structures.
87 if (isobject (x))
88 x = struct (x);
89 varargin = cellfun (@struct, varargin, "uniformoutput", false);
84 endif 90 endif
85 91
86 if (t) 92 if (t)
87 ## Check individual classes. 93 ## Check individual classes.
88 if (isstruct (x)) 94 if (isstruct (x))