report_data.m 2.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
classdef report_data < handle
    % report_data Class to write a page to the report
    %
    % Copyright (C) 2019 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/>.
    properties (SetAccess = private)
        data = ''
        tableAlignRight = false
        tableRowColor = 'white'
        tableRowIndent = 0
        tableNaNSymb = 'NaN'
        tablePrecision = ''
        zeroTol = 1e-6
28
    end
29 30 31
    properties
        column_names = ''
    end
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    methods
        function o = report_data(varargin)
            %function o = report_data(varargin)
            % report_data Class Constructor
            %
            % INPUTS
            %   varargin        0 args  : empty report_data object
            %                   1 arg   : must be report_data object (return a copy of arg)
            %                   > 1 args: option/value pairs (see structure below for options)
            %
            % OUTPUTS
            %   o     [report_data]  report_data object
            %
            % SPECIAL REQUIREMENTS
            %   none
            if nargin == 0
                return
            elseif nargin == 1
                assert(isa(varargin{1}, 'report_data'), ...
                    '@report_data.report_data: with one arg you must pass a report_data object');
                o = varargin{1};
                return
            end
            if round(nargin/2) ~= nargin/2
                error('@report_data.report_data: options must be supplied in name/value pairs.');
            end
58

59 60 61 62
            % Octave 5.1.0 has not implemented `properties` and issues a warning when using `fieldnames`
            warning('off')
            optNames = fieldnames(o);
            warning('on')
63

64 65 66 67 68 69 70 71 72 73
            % 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('@report_data.report_data: %s is not a recognized option.', pair{1});
                end
            end
74 75
        end
    end
76
    methods (Hidden = true)
77 78
        writeDataForTable(o, fid, precision)
    end
79
end