Commit 244395c2 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Changed subsref overloaded method in dynDate class.

Allow to populate an empty dynDate object or update a dynDate object. For instance, if we instantiate
the dynDate class as follows:

a = dynDate()

a is an empty dynDate object. We can "populate" this object as follows

a('1938Q4')

Note however that a ins not modified in place (due to a limitation of Octave's class design), a copy
has to be made.
parent 52ebca92
......@@ -51,4 +51,65 @@ function B = subsref(A,S)
% Original author: stephane DOT adjemian AT univ DASH lemans DOT fr
B = builtin('subsref', A, S);
\ No newline at end of file
% Allow to populate an empty dynDate object or update a dynDate object
if isequal(length(S),1) && isequal(S.type,'()') && isequal(length(S.subs),1) && ischar(S.subs{1})
B = dynDate(S.subs{1});
return
end
% Give access to dynDate properties (time and freq).
if isequal(length(S),1) && isequal(S.type,'.') && ( strcmp(S.subs,'time') || strcmp(S.subs,'freq') )
B = builtin('subsref', A, S);
return
end
error('dynDate::subsref: You''re trying to do something wrong!')
%@test:1
%$ t = zeros(3,1);
%$
%$ % Instantiate an empty dynDate object
%$ a = dynDate();
%$ if all(isnan(a.time)) && isnan(a.freq)
%$ t(1) = 1;
%$ end
%$
%$ % Populate the empty dynDate object
%$ try
%$ a = a('1950Q1');
%$ if isequal(a.time,[1950 1]) && isequal(a.freq,4)
%$ t(2) = 1;
%$ end
%$ catch
%$ % Nothing to do here...
%$ end
%$
%$ % "Overwrite" a dynDate object
%$ try
%$ a = a('1945Q3');
%$ if isequal(a.time,[1945 3]) && isequal(a.freq,4)
%$ t(3) = 1;
%$ end
%$ catch
%$ % Nothing to do here...
%$ end
%$
%$ % Check the results.
%$ T = all(t);
%@eof:1
%@test:2
%$ % Instantiate a dynDate object
%$ a = dynDate('1938Q4');
%$
%$ % Try to access a non existent (or forbidden) property
%$ try
%$ a.Time;
%$ t = 0;
%$ catch
%$ t = 1;
%$ end
%$
%$ T = all(t);
%@eof:2
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment