reporting: simplify code

remove-priordens
Houtan Bastani 2014-02-06 17:29:24 +01:00
parent ae92cca4a2
commit 5e96706727
21 changed files with 45 additions and 369 deletions

View File

@ -1,34 +0,0 @@
function o = addPage(o, varargin)
% function o = addPage(o, varargin)
% Sections Class Constructor
%
% INPUTS
% o [pages] pages object
% varargin options to @page.page
%
% OUTPUTS
% o [pages] pages object
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
fprintf(1, '\nAdding Page: %d', numPages(o)+1);
o.objArray = o.objArray.addObj(page(varargin{:}));
end

View File

@ -1,32 +0,0 @@
function display(o)
%function display(o)
% Display a Pages object
%
% INPUTS
% o [pages] pages object
%
% OUTPUTS
% none
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
reporting_object_display(o);
end

View File

@ -1,35 +0,0 @@
function lastIndex = end(o, k, n)
% function lastIndex = end(o, k, n)
% End keyword
%
% INPUTS
% o [pages] pages object
% k [integer] index where end appears
% n [integer] number of indices
%
% OUTPUTS
% lastIndex [integer] last pages index
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(k==1 && n==1, '@pages/end: pages only has one dimension');
lastIndex = numPages(o);
end

View File

@ -1,33 +0,0 @@
function e = getPages(ps, varargin)
% function e = getPages(ps, varargin)
% Sections Class Constructor
%
% INPUTS
% ps [pages] pages object
% varargin options to @objArray.getObjs
%
% OUTPUTS
% ps [pages] array of page objects
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
e = ps.objArray.getObjs(varargin{:});
end

View File

@ -1,31 +0,0 @@
function n = numPages(o)
% function n = numPages(o)
%
% INPUTS
% o [page] pages object
%
% OUTPUTS
% n [integer] number of pages in o
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
n = o.objArray.numObjArray();
end

View File

@ -1,43 +0,0 @@
function ps = pages(varargin)
%function ps = pages(varargin)
% Pages Class Constructor
%
% INPUTS
% varargin 0 args : empty pages object
% 1 arg : must be pages object (return a copy of arg)
%
% OUTPUTS
% ps [pages] pages object
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
switch nargin
case 0
ps = class(struct, 'pages', objArray());
case 1
assert(isa(varargin{1}, 'pages'), ...
['@pages.pages: With one arg to pages constructor, you must ' ...
'pass an pages object or a char.']);
ps = varargin{1};
otherwise
error('@pages.pages: invalid number of arguments');
end
end

View File

@ -1,39 +0,0 @@
function B = subsasgn(A, S, V)
% function B = subsasgn(A, S, V)
% Copyright (C) 2013 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
B = A;
if length(S) > 1
for i=1:(length(S)-1)
B = subsref(B, S(i));
end
B = subsasgn(B, S(end), V);
B = subsasgn(A, S(1:(end-1)), B);
return
end
switch S.type
case '()'
index = S.subs{:};
assert(isnumeric(index));
B.objArray(index) = V;
otherwise
error('@pages.subsasgn: syntax error');
end
end

View File

@ -1,48 +0,0 @@
function A = subsref(A, S)
%function A = subsref(A, S)
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
switch S(1).type
case '.'
switch S(1).subs
case fieldnames(A)
A = A.(S(1).subs);
case methods(A)
if areParensNext(S)
A = feval(S(1).subs, A, S(2).subs{:});
S = shiftS(S,1);
else
A = feval(S(1).subs, A);
end
otherwise
error(['@pages.subsref: unknown field or method: ' S(1).subs]);
end
case '()'
A = getPages(A, S(1).subs{:});
case '{}'
error(['@pages.subsref: ' S(1).type ' indexing not supported.']);
otherwise
error('@pages.subsref: impossible case')
end
S = shiftS(S,1);
if length(S) >= 1
A = subsref(A, S);
end
end

View File

@ -1,40 +0,0 @@
function o = write(o, fid)
%function o = write(o, fid)
% Write Pages object
%
% INPUTS
% o [pages] pages object
% fid [integer] file id
%
% OUTPUTS
% o [pages] pages object
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(fid ~= -1);
fprintf(fid, '\n%% Pages Object\n');
nps = numPages(o);
for i=1:nps
fprintf(1, '\nWriting Page: %d', i);
o.objArray(i).write(fid);
end
fprintf(fid, '%% End Pages Object\n\n');
end

View File

@ -12,7 +12,7 @@ function o = addGraph(o, varargin)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
@ -29,6 +29,6 @@ function o = addGraph(o, varargin)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
o.pages(end).sections(end) = ...
o.pages(end).sections(end).addGraph(varargin{:});
o.pages{end}.sections(end) = ...
o.pages{end}.sections(end).addGraph(varargin{:});
end

View File

@ -12,7 +12,7 @@ function o = addPage(o, varargin)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
@ -29,6 +29,7 @@ function o = addPage(o, varargin)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
o.pages = o.pages.addPage('orientation', o.orientation, 'paper', o.paper, ...
varargin{:});
np = length(o.pages) + 1;
fprintf(1, '\nAdding Page: %d', np);
o.pages{np} = page('orientation', o.orientation, 'paper', o.paper, varargin{:});
end

View File

@ -12,7 +12,7 @@ function o = addSection(o, varargin)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
@ -29,5 +29,5 @@ function o = addSection(o, varargin)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
o.pages(end) = o.pages(end).addSection(varargin{:});
o.pages{end} = o.pages{end}.addSection(varargin{:});
end

View File

@ -12,7 +12,7 @@ function o = addSeries(o, varargin)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
@ -29,10 +29,10 @@ function o = addSeries(o, varargin)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(isa(o.pages(end).sections(end).elements(end), 'graph') || ...
isa(o.pages(end).sections(end).elements(end), 'report_table'), ...
assert(isa(o.pages{end}.sections(end).elements(end), 'graph') || ...
isa(o.pages{end}.sections(end).elements(end), 'report_table'), ...
'@report.addSeries: you can only add a series to a report_table or graph object');
o.pages(end).sections(end).elements(end) = ...
o.pages(end).sections(end).elements(end).addSeries(varargin{:});
o.pages{end}.sections(end).elements(end) = ...
o.pages{end}.sections(end).elements(end).addSeries(varargin{:});
end

View File

@ -12,7 +12,7 @@ function o = addTable(o, varargin)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
@ -29,6 +29,6 @@ function o = addTable(o, varargin)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
o.pages(end).sections(end) = ...
o.pages(end).sections(end).addTable(varargin{:});
o.pages{end}.sections(end) = ...
o.pages{end}.sections(end).addTable(varargin{:});
end

View File

@ -12,7 +12,7 @@ function o = addVspace(o, varargin)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
@ -29,6 +29,6 @@ function o = addVspace(o, varargin)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
o.pages(end).sections(end) = ...
o.pages(end).sections(end).addVspace(varargin{:});
o.pages{end}.sections(end) = ...
o.pages{end}.sections(end).addVspace(varargin{:});
end

View File

@ -11,7 +11,7 @@ function n = numPages(o)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
@ -28,5 +28,5 @@ function n = numPages(o)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
n = o.pages.numPages();
n = length(o.pages);
end

View File

@ -13,7 +13,7 @@ function o = report(varargin)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
@ -37,7 +37,7 @@ o.orientation = 'portrait';
o.paper = 'a4';
o.margin = 2.5;
o.marginUnit = 'cm';
o.pages = pages();
o.pages = {};
o.filename = 'report.tex';
o.showDate = true;
o.compiler = '';

View File

@ -1,7 +1,7 @@
function B = subsasgn(A, S, V)
% function B = subsasgn(A, S, V)
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
@ -32,7 +32,7 @@ switch S.type
case '()'
index = S.subs{:};
assert(isnumeric(index));
B.pages(index) = V;
B.pages{index} = V;
case '.'
switch S.subs
case fieldnames(A)

View File

@ -34,7 +34,7 @@ switch S(1).type
error(['@report.subsasgn: unknown field or method: ' S(1).subs]);
end
case '()'
A = A.pages.getPages(S(1).subs{:});
A = A.pages{S(1).subs{:}};
case '{}'
error(['@report.subsasgn: ' S(1).type ' indexing not supported.']);
otherwise

View File

@ -76,7 +76,11 @@ fprintf(fid, '\\newlength\\sectionheight\n');
fprintf(fid, '\\begin{document}\n');
fprintf(fid, '\\centering\n');
o.pages.write(fid);
nps = length(o.pages);
for i=1:nps
fprintf(1, '\nWriting Page: %d', i);
o.pages{i}.write(fid);
end
fprintf(fid, '\\end{document}\n');
fprintf(fid, '%% End Report Object\n');

View File

@ -5,7 +5,6 @@ function reporting_object_display(o)
% graph
% objArray
% page
% pages
% report
% section
% sections
@ -23,7 +22,7 @@ function reporting_object_display(o)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
@ -48,10 +47,18 @@ for i=1:length(fields)
if iscell(val)
fprintf('{');
for j=1:length(val)
assert(ischar(val{j}));
fprintf('''%s''', val{j});
if j~=length(val)
fprintf(', ');
if ischar(val{j});
fprintf('''%s''', val{j});
if j~=length(val)
fprintf(', ');
end
else
if fields{i} == 'pages'
fprintf('%d', length(val));
break;
else
fprintf('fix this');
end
end
end
fprintf('}');
@ -80,7 +87,6 @@ for i=1:length(fields)
fprintf('%d', val.(['num' upper(cl(1)) cl(2:end)]));
end
else
keyboard
fprintf('fix this');
end
fprintf('\n');