From 95e2dd079e8bece6ae5cc7202aafa2674580f425 Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Thu, 14 Feb 2013 18:11:08 +0100
Subject: [PATCH] reporting (WIP)

---
 matlab/reporting/@objArray/addObj.m     |  1 +
 matlab/reporting/@objArray/getObjs.m    |  1 +
 matlab/reporting/@page/addSection.m     | 13 +--------
 matlab/reporting/@page/display.m        | 36 +++++++++++++++++++++++++
 matlab/reporting/@page/subsasgn.m       |  2 +-
 matlab/reporting/@pages/display.m       | 36 +++++++++++++++++++++++++
 matlab/reporting/@report/addPage.m      |  2 +-
 matlab/reporting/@report/display.m      | 21 ++++++++-------
 matlab/reporting/@report/subsasgn.m     |  2 +-
 matlab/reporting/@report/subsref.m      |  4 +--
 matlab/reporting/@section/display.m     | 34 +++++++++++++++++++++++
 matlab/reporting/@sections/addSection.m |  5 ++++
 matlab/reporting/@sections/display.m    | 36 +++++++++++++++++++++++++
 13 files changed, 165 insertions(+), 28 deletions(-)
 create mode 100644 matlab/reporting/@page/display.m
 create mode 100644 matlab/reporting/@pages/display.m
 create mode 100644 matlab/reporting/@section/display.m
 create mode 100644 matlab/reporting/@sections/display.m

diff --git a/matlab/reporting/@objArray/addObj.m b/matlab/reporting/@objArray/addObj.m
index c190b403b7..3f2bd1f083 100644
--- a/matlab/reporting/@objArray/addObj.m
+++ b/matlab/reporting/@objArray/addObj.m
@@ -29,4 +29,5 @@ if nargin == 2
     oa.objs{end+1} = varargin{1};
 elseif nargin == 3
     oa.objs{varargin{2}} = varargin{1};
+end
 end
\ No newline at end of file
diff --git a/matlab/reporting/@objArray/getObjs.m b/matlab/reporting/@objArray/getObjs.m
index 5074710827..6c7dcbeae9 100644
--- a/matlab/reporting/@objArray/getObjs.m
+++ b/matlab/reporting/@objArray/getObjs.m
@@ -22,6 +22,7 @@ switch nargin
     case 1
         e = oa.objs;
     case 2
+        assert(isnumeric(varargin{1}));
         e = oa.objs{varargin{1}};
     otherwise
         error('objArray getObjs: invalid number of arguments');
diff --git a/matlab/reporting/@page/addSection.m b/matlab/reporting/@page/addSection.m
index 3b02c922ec..4ad61a26bc 100644
--- a/matlab/reporting/@page/addSection.m
+++ b/matlab/reporting/@page/addSection.m
@@ -30,20 +30,9 @@ function p = addSection(p, 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(nargin >= 1 && nargin <= 3, ['incorrect number of arguments passed ' ...
-    'to addSection']);
 assert(isa(p, 'page'), 'First argument must be a page object');
-if nargin > 1
-    assert(isa(varargin{1},'section'), ['Optional 2nd arg to addSection must be a ' ...
-        'Section']);
-    if nargin > 2
-        assert(isnumeric(varargin{2}), ['Optional 3rd arg to addSection must be ' ...
-            'an index']);
-    end
-end
-
 if nargin == 1
-    p.sections = p.sections.addSection(section());
+    p.sections = p.sections.addSection();
 elseif nargin == 2 || nargin == 3
     p.sections = p.sections.addSection(varargin{:});
 end
diff --git a/matlab/reporting/@page/display.m b/matlab/reporting/@page/display.m
new file mode 100644
index 0000000000..b7ae6c66c7
--- /dev/null
+++ b/matlab/reporting/@page/display.m
@@ -0,0 +1,36 @@
+function display(o)
+%function display(o)
+% Display a Page object
+%
+% INPUTS
+%   none
+%
+% 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/>.
+
+name = 'report.page';
+disp(' ');
+disp([name '.sections = ']);
+disp(' ');
+disp(o.sections());
+end
\ No newline at end of file
diff --git a/matlab/reporting/@page/subsasgn.m b/matlab/reporting/@page/subsasgn.m
index 385309030c..ede173bfbf 100644
--- a/matlab/reporting/@page/subsasgn.m
+++ b/matlab/reporting/@page/subsasgn.m
@@ -35,7 +35,7 @@ switch S.type
         B{index} = V;
     case '.'
         switch S.subs
-            case fields(A)
+            case fieldnames(A)
                 B.(S.subs) = V;
             otherwise
                 error(['field ' S.subs 'does not exist in the page class'])
diff --git a/matlab/reporting/@pages/display.m b/matlab/reporting/@pages/display.m
new file mode 100644
index 0000000000..89eb1b9779
--- /dev/null
+++ b/matlab/reporting/@pages/display.m
@@ -0,0 +1,36 @@
+function display(o)
+%function display(o)
+% Display a Pages object
+%
+% INPUTS
+%   none
+%
+% 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/>.
+
+name = 'report.pages';
+disp(' ');
+disp([name ' = ']);
+disp(' ');
+disp(getPages(o));
+end
\ No newline at end of file
diff --git a/matlab/reporting/@report/addPage.m b/matlab/reporting/@report/addPage.m
index 9421d2886d..8299f973d6 100644
--- a/matlab/reporting/@report/addPage.m
+++ b/matlab/reporting/@report/addPage.m
@@ -43,7 +43,7 @@ if nargin > 1
 end
 
 if nargin == 1
-    r.pages = r.pages.addPage(page());
+    r.pages = r.pages.addPage();
 elseif nargin == 2 || nargin == 3
     r.pages = r.pages.addPage(varargin{:});
 end
diff --git a/matlab/reporting/@report/display.m b/matlab/reporting/@report/display.m
index e1080fa0f6..9ed363cede 100644
--- a/matlab/reporting/@report/display.m
+++ b/matlab/reporting/@report/display.m
@@ -1,5 +1,5 @@
-function display(r)
-%function display(r)
+function display(o)
+%function display(o)
 % Display a Report object
 %
 % INPUTS
@@ -28,20 +28,21 @@ function display(r)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
+name = 'report';
 disp(' ');
-disp([inputname(1) '.title = ']);
+disp([name '.title = ']);
 disp(' ');
-disp(['     ''' r.title '''']);
+disp(['     ''' o.title '''']);
 disp(' ')
-disp([inputname(1) '.orientation = ']);
+disp([name '.orientation = ']);
 disp(' ');
-disp(['     ''' r.orientation '''']);
+disp(['     ''' o.orientation '''']);
 disp(' ')
-disp([inputname(1) '.numPages() = ']);
+disp([name '.numPages() = ']);
 disp(' ');
-disp(['     ' num2str(numPages(r))]);
+disp(['     ' num2str(numPages(o))]);
 disp(' ');
-disp([inputname(1) '.pages = ']);
+disp([name '.pages = ']);
 disp(' ');
-disp(r.pages.getPages());
+disp(o.pages.getPages());
 end
\ No newline at end of file
diff --git a/matlab/reporting/@report/subsasgn.m b/matlab/reporting/@report/subsasgn.m
index da1c92e44b..527e6c9059 100644
--- a/matlab/reporting/@report/subsasgn.m
+++ b/matlab/reporting/@report/subsasgn.m
@@ -35,7 +35,7 @@ switch S.type
         B.pages(index) = V;
     case '.'
         switch S.subs
-            case fields(A)
+            case fieldnames(A)
                 B.(S.subs) = V;
             otherwise
                 error(['field ' S.subs 'does not exist in the report class']);
diff --git a/matlab/reporting/@report/subsref.m b/matlab/reporting/@report/subsref.m
index 8d5fbab47d..9559393fe6 100644
--- a/matlab/reporting/@report/subsref.m
+++ b/matlab/reporting/@report/subsref.m
@@ -34,9 +34,7 @@ switch S(1).type
                 error(['Report Class: unknown field or method: ' S(1).subs]);
         end
     case '()'
-        index = S(1).subs{:};
-        assert(isnumeric(index));
-        A = A(index);
+        A = A.pages.getPages(S(1).subs{:});
     case '{}'
         error(['Report Class: ' S(1).type ' indexing not supported.']);
     otherwise
diff --git a/matlab/reporting/@section/display.m b/matlab/reporting/@section/display.m
new file mode 100644
index 0000000000..e34ede9348
--- /dev/null
+++ b/matlab/reporting/@section/display.m
@@ -0,0 +1,34 @@
+function display(o)
+%function display(o)
+% Display a Section object
+%
+% INPUTS
+%   none
+%
+% 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/>.
+
+name = 'report.page.section';
+disp(' ');
+disp([name '.x = ']);
+end
\ No newline at end of file
diff --git a/matlab/reporting/@sections/addSection.m b/matlab/reporting/@sections/addSection.m
index fab549127d..af412a412a 100644
--- a/matlab/reporting/@sections/addSection.m
+++ b/matlab/reporting/@sections/addSection.m
@@ -19,6 +19,11 @@ function ss = addSection(ss, varargin)
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
 assert(nargin >= 1 && nargin <= 3)
+if nargin > 1
+    assert(isa(varargin{1},'section'), ['Optional 2nd arg to addSection ' ...
+                        'must be a Section']);
+end
+
 if nargin == 1
     ss.objArray = ss.objArray.addObj(section());
 else
diff --git a/matlab/reporting/@sections/display.m b/matlab/reporting/@sections/display.m
new file mode 100644
index 0000000000..908bd38973
--- /dev/null
+++ b/matlab/reporting/@sections/display.m
@@ -0,0 +1,36 @@
+function display(o)
+%function display(o)
+% Display a Sections object
+%
+% INPUTS
+%   none
+%
+% 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/>.
+
+name = 'reports.page';
+disp(' ');
+disp([name '.sections = ']);
+disp(' ');
+disp(getSections(o));
+end
\ No newline at end of file
-- 
GitLab