2013-02-15 16:52:35 +01:00
|
|
|
function o = page(varargin)
|
|
|
|
%function o = page(varargin)
|
2013-02-12 14:23:41 +01:00
|
|
|
% Page Class Constructor
|
|
|
|
%
|
|
|
|
% INPUTS
|
|
|
|
% 0 args => empty page
|
|
|
|
% 1 arg (page class) => copy 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/>.
|
|
|
|
|
2013-02-15 16:52:35 +01:00
|
|
|
o = struct;
|
2013-02-19 15:48:47 +01:00
|
|
|
o.paper = '';
|
2013-03-19 11:57:20 +01:00
|
|
|
o.title = {};
|
2013-05-13 17:06:48 +02:00
|
|
|
o.titleFormat = {};
|
2013-02-19 15:48:47 +01:00
|
|
|
o.orientation = '';
|
2013-03-19 11:57:20 +01:00
|
|
|
o.footnote = {};
|
2013-02-15 16:52:35 +01:00
|
|
|
o.sections = sections();
|
2013-02-12 14:23:41 +01:00
|
|
|
|
2013-02-15 16:52:35 +01:00
|
|
|
if nargin == 1
|
2013-03-08 19:25:24 +01:00
|
|
|
assert(isa(varargin{1}, 'page'), ['@page.page: with one arg to Page ' ...
|
|
|
|
'constructor, you must pass a page object']);
|
2013-02-15 16:52:35 +01:00
|
|
|
o = varargin{1};
|
|
|
|
return;
|
|
|
|
elseif nargin > 1
|
|
|
|
if round(nargin/2) ~= nargin/2
|
2013-03-08 19:25:24 +01:00
|
|
|
error(['@page.page: options must be supplied in name/value ' ...
|
2013-02-15 16:52:35 +01:00
|
|
|
'pairs.']);
|
|
|
|
end
|
|
|
|
|
2013-05-13 17:47:11 +02:00
|
|
|
optNames = fieldnames(o);
|
2013-02-15 16:52:35 +01:00
|
|
|
|
|
|
|
% overwrite default values
|
|
|
|
for pair = reshape(varargin, 2, [])
|
2013-05-14 17:22:24 +02:00
|
|
|
ind = strmatch(lower(pair{1}), lower(optNames), 'exact');
|
2013-05-13 17:47:11 +02:00
|
|
|
assert(isempty(ind) || length(ind) == 1);
|
|
|
|
if ~isempty(ind)
|
|
|
|
o.(optNames{ind}) = pair{2};
|
2013-02-15 16:52:35 +01:00
|
|
|
else
|
2013-05-14 17:22:24 +02:00
|
|
|
error('@page.page: %s is not a recognized option.', pair{1});
|
2013-02-15 16:52:35 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-15 17:20:07 +01:00
|
|
|
% Check options provided by user
|
2013-03-19 11:57:20 +01:00
|
|
|
if ischar(o.title)
|
2013-04-04 07:35:54 +02:00
|
|
|
o.title = {o.title};
|
2013-03-19 11:57:20 +01:00
|
|
|
end
|
2013-05-13 17:06:48 +02:00
|
|
|
if ischar(o.titleFormat)
|
|
|
|
o.titleFormat = {o.titleFormat};
|
2013-03-19 11:57:20 +01:00
|
|
|
end
|
|
|
|
assert(iscellstr(o.title), ...
|
|
|
|
'@page.page: title must be a cell array of strings');
|
2013-05-13 17:06:48 +02:00
|
|
|
assert(iscellstr(o.titleFormat), ...
|
|
|
|
'@page.page: titleFormat must be a cell array of strings');
|
|
|
|
assert(length(o.title)==length(o.titleFormat), ...
|
|
|
|
'@page.page: title and titleFormat must be of the same length');
|
2013-03-15 17:20:07 +01:00
|
|
|
|
|
|
|
valid_paper = {'a4', 'letter'};
|
|
|
|
assert(any(strcmp(o.paper, valid_paper)), ...
|
|
|
|
['@page.page: paper must be one of ' strjoin(valid_paper, ' ')]);
|
|
|
|
|
|
|
|
valid_orientation = {'portrait', 'landscape'};
|
|
|
|
assert(any(strcmp(o.orientation, valid_orientation)), ...
|
|
|
|
['@page.page: orientation must be one of ' strjoin(valid_orientation, ' ')]);
|
|
|
|
|
2013-03-19 11:57:20 +01:00
|
|
|
if ischar(o.footnote)
|
2013-04-04 07:35:54 +02:00
|
|
|
o.footnote = {o.footnote};
|
2013-03-15 17:20:07 +01:00
|
|
|
end
|
2013-03-19 11:57:20 +01:00
|
|
|
assert(iscellstr(o.footnote), ...
|
|
|
|
'@page.page: footnote must be a cell array of string(s)');
|
2013-03-15 17:20:07 +01:00
|
|
|
|
2013-02-15 16:52:35 +01:00
|
|
|
% Create page object
|
|
|
|
o = class(o, 'page');
|
2013-02-12 14:23:41 +01:00
|
|
|
end
|