Commit f8497d4d authored by Houtan Bastani's avatar Houtan Bastani
Browse files

reporting: add new Paragraph class

parent afcbcece
function display(o)
%function display(o)
% Display a Paragraph object
%
% INPUTS
% o [paragraph] paragraph object
%
% OUTPUTS
% none
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 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/>.
display_reporting_object(o);
end
\ No newline at end of file
function o = paragraph(varargin)
%function o = paragraph(varargin)
% Instantiates a paragraph object
% Copyright (C) 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/>.
o = struct;
o.balancedCols = false;
o.cols = 1;
o.heading = '';
o.indent = true;
o.text = '';
if nargin == 1
assert(isa(varargin{1}, 'paragraph'),['With one arg to Paragraph constructor, ' ...
'you must pass a paragraph object']);
o = varargin{1};
return;
elseif nargin > 1
if round(nargin/2) ~= nargin/2
error(['@paragraph.paragraph: options must be supplied in name/value ' ...
'pairs.']);
end
optNames = fieldnames(o);
% overwrite default values
for pair = reshape(varargin, 2, [])
ind = find(strcmpi(optNames, pair{1}));
assert(isempty(ind) || length(ind) == 1);
if ~isempty(ind)
o.(optNames{ind}) = pair{2};
else
error('@paragraph.paragraph: %s is not a recognized option.', pair{1});
end
end
end
assert(islogical(o.indent), '@paragraph.paragraph: indent must be either true or false');
assert(islogical(o.balancedCols), '@paragraph.paragraph: balancedCols must be either true or false');
assert(isint(o.cols), '@paragraph.paragraph: cols must be an integer');
assert(ischar(o.text), '@paragraph.paragraph: text must be a string');
assert(ischar(o.heading), '@paragraph.paragraph: heading must be a string');
% Create paragraph object
o = class(o, 'paragraph');
end
function B = subsasgn(A, S, V)
% function B = subsasgn(A, S, V)
% Copyright (C) 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/>.
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.elements{index} = V;
case '{}'
index = S.subs{:};
assert(isnumeric(index));
B{index} = V;
case '.'
switch S.subs
case fieldnames(A)
B.(S.subs) = V;
otherwise
error(['@paragraph.subsasgn: field ' S.subs 'does not exist']);
end
otherwise
error('@paragraph.subsasgn: syntax error');
end
end
\ No newline at end of file
function A = subsref(A, S)
%function A = subsref(A, S)
% Copyright (C) 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(['@paragraph.subsref: unknown field or method: ' S(1).subs]);
end
case '()'
A = A.elements{S(1).subs{:}};
case '{}'
error(['@paragraph.subsref: ' S(1).type ' indexing not supported.']);
otherwise
error('@paragraph.subsref: impossible case')
end
S = shiftS(S,1);
if length(S) >= 1
A = subsref(A, S);
end
end
function o = write(o, fid)
%function o = write(o, fid)
% Write Paragraph object
%
% INPUTS
% o [paragraph] paragraph object
% fid [integer] file id
%
% OUTPUTS
% o [paragraph] paragraph object
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 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, '%% Paragraph Object\n\\multicolumn{1}{p{\\textwidth}}{%%\n');
if o.cols ~= 1
bc = '';
if o.balancedCols
bc = '*';
end
fprintf(fid, '\\begin{multicols%s}{%d}%%\n', bc, o.cols);
end
if ~isempty(o.heading)
if o.cols ~= 1
fprintf(fid, '[%s\n]\n', o.heading);
else
fprintf(fid, '%s\\newline \\newline\n', o.heading);
end
end
if o.indent
fprintf(fid, '\\hspace{4ex}');
end
fprintf(fid, '%s', o.text);
if o.cols ~= 1
fprintf(fid, '\\end{multicols%s}\n', bc);
end
fprintf(fid, '}\n%% End Paragraph Object\n\n');
end
%\multicolumn{1}{p{\textwidth}}
%{\begin{multicols}{2}
%Hello, here is some text without a meaning. This text should show what
%a printed text will look like at this place.
%\columnbreak
%If you read this text, you will get no information. Really? Is there
%no information? Is there...
%\end{multicols}}\\
\ No newline at end of file
function o = addParagraph(o, varargin)
%function o = addParagraph(o, varargin)
% Add a paragraph to the current section of the current page in the report
%
% INPUTS
% o [report] report object
% varargin arguments to @section/addGraph.m
%
% OUTPUTS
% o [report] updated report 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/>.
o.pages{end}.sections{end} = ...
o.pages{end}.sections{end}.addParagraph(varargin{:});
end
......@@ -41,7 +41,7 @@ if strcmpi(o.orientation, 'landscape')
fprintf(fid, ',landscape');
end
fprintf(fid, ']{geometry}\n');
fprintf(fid, '\\usepackage{pdflscape, booktabs, pgfplots, colortbl, adjustbox}\n');
fprintf(fid, '\\usepackage{pdflscape, booktabs, pgfplots, colortbl, adjustbox, multicol}\n');
fprintf(fid, '\\pgfplotsset{compat=1.5.1}');
fprintf(fid, ['\\makeatletter\n' ...
'\\def\\blfootnote{\\gdef\\@thefnmark{}\\@footnotetext}\n' ...
......
......@@ -30,5 +30,9 @@ 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/>.
for i=1:length(o.elements)
assert(~isa(o.elements{i}, 'paragraph'), ...
'@addGraph: A Section that contains a Paragraph cannot contain a Graph');
end
o.elements{end+1} = graph(varargin{:});
end
function o = addParagraph(o, varargin)
%function o = addParagraph(o, varargin)
% Add a paragraph to the Cell Array of elements in this section
%
% INPUTS
% 1 args => add empty paragraph
% 2 args => add given paragraph
% 3 args => add paragraph at index
%
% OUTPUTS
% updated page object
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 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(o.cols == 1, ...
['@addParagraph: you can only add a paragraph to a Section that ' ...
'contains one column']);
for i=1:length(o.elements)
assert(isa(o.elements{i}, 'paragraph'), ...
['@addParagraph: you can only add a paragraph to a Section that ' ...
'contains only paragraphs']);
end
o.elements{end+1} = paragraph(varargin{:});
end
......@@ -30,5 +30,9 @@ 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/>.
for i=1:length(o.elements)
assert(~isa(o.elements{i}, 'paragraph'), ...
'@addTable: A Section that contains a Paratable cannot contain a Table');
end
o.elements{end+1} = report_table(varargin{:});
end
......@@ -29,5 +29,9 @@ 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/>.
for i=1:length(o.elements)
assert(~isa(o.elements{i}, 'paragraph'), ...
'@addVspace: A Section that contains a Paragraph cannot contain a Vspace');
end
o.elements{end+1} = vspace(varargin{:});
end
......@@ -33,6 +33,7 @@ function o = write(o, fid, pg, sec)
assert(fid ~= -1);
fprintf(fid, '%% Section Object\n');
if ~isempty(o.height)
fprintf(fid, '\\setlength\\sectionheight{%s}%%\n', o.height);
end
......@@ -45,9 +46,16 @@ end
fprintf(fid, '}{%%\n');
fprintf(fid, '\\begin{tabular}[t]{');
for i=1:o.cols
fprintf(fid, 'c');
if ~isa(o.elements{1}, 'paragraph')
% if one element is a paragraph, they all are
% due to check in add*.m functions
fprintf(fid, 'l');
else
fprintf(fid, 'c');
end
end
fprintf(fid, '}\n');
ne = numElements(o);
row = 1;
col = 1;
......@@ -61,7 +69,11 @@ for i=1:ne
return;
end
else
o.elements{i}.write(fid, pg, sec, row, col);
if isa(o.elements{i}, 'paragraph')
o.elements{i}.write(fid);
else
o.elements{i}.write(fid, pg, sec, row, col);
end
if col ~= o.cols
fprintf(fid, ' & ');
col = col + 1;
......
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