only allow addData to be used once per table

remove-priordens
Houtan Bastani 2019-10-24 11:28:03 +02:00
parent 7e47f128d9
commit a717cc2ad4
3 changed files with 7 additions and 22 deletions

View File

@ -19,7 +19,6 @@ classdef report_data < handle
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
properties (SetAccess = private)
data = ''
tableSubSectionHeader = ''
tableAlignRight = false
tableRowColor = 'white'
tableRowIndent = 0

View File

@ -32,12 +32,6 @@ function writeDataForTable(o, fid, precision)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
%% Validate options provided by user
assert(ischar(o.tableSubSectionHeader), '@report_data.writeDataForTable: tableSubSectionHeader must be a string');
if isempty(o.tableSubSectionHeader)
assert(~isempty(o.data) && iscell(o.data), ...
'@report_data.writeDataForTable: must provide data as a cell');
end
assert(ischar(o.tableRowColor), '@report_data.writeDataForTable: tableRowColor must be a string');
assert(isint(o.tableRowIndent) && o.tableRowIndent >= 0, ...
'@report_data.writeDataForTable: tableRowIndent must be an integer >= 0');
@ -53,20 +47,9 @@ rounding = 10^precision;
%% Write Output
fprintf(fid, '%% Table Data (report_data)\n');
nrows = length(o.data{1});
ncols = length(o.data);
[nrows, ncols] = size(o.data);
for i = 1:nrows
if ~isempty(o.tableRowColor) && ~strcmpi(o.tableRowColor, 'white')
fprintf(fid, '\\rowcolor{%s}', o.tableRowColor);
else
fprintf(fid, '\\rowcolor{%s}', o.tableRowColor);
end
if ~isempty(o.tableSubSectionHeader)
fprintf(fid, '\\textbf{%s}', o.tableSubSectionHeader);
fprintf(fid, '%s', repmat(' &', 1, ncols-1));
fprintf(fid, '\\\\%%\n');
return
end
fprintf(fid, '\\rowcolor{%s}', o.tableRowColor);
if o.tableAlignRight
fprintf(fid, '\\multicolumn{1}{r}{');
end
@ -81,7 +64,7 @@ for i = 1:nrows
fprintf(fid, '}');
end
for j = 1:ncols
val = o.data{j}(i);
val = o.data(i,j);
if iscell(val)
val = val{:};
end

View File

@ -29,5 +29,8 @@ function o = addData(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.table_data{end+1} = report_data(varargin{:});
if length(o.table_data) >= 1
error('@report_table.addData: You can only use addData once per table')
end
o.table_data{1} = report_data(varargin{:});
end