$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
save.hh
1 // Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
2 // (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef SCRIBO_IO_XML_SAVE_HH
28 # define SCRIBO_IO_XML_SAVE_HH
29 
33 
34 # include <libgen.h>
35 # include <fstream>
36 # include <sstream>
37 
38 # include <map>
39 
40 # include <scribo/core/document.hh>
41 
42 # ifdef HAVE_QT
43 # include <scribo/io/xml/internal/full_xml_visitor.hh>
44 # endif // ! HAVE_QT
45 
46 # include <scribo/io/xml/internal/extended_page_xml_visitor.hh>
47 # include <scribo/io/xml/internal/page_xml_visitor.hh>
48 
49 
50 namespace scribo
51 {
52 
53  namespace io
54  {
55 
56  namespace xml
57  {
58 
68  enum Format
69  {
70  Page,
71  PageExtended,
72 
73 # ifdef HAVE_QT
74  Full
75 # endif // ! HAVE_QT
76 
77  //Hocr
78  };
79 
80 
84  template <typename L>
85  void
86  save(const document<L>& doc, const std::string& output_name,
87  Format format);
88 
89 
90 # ifndef MLN_INCLUDE_ONLY
91 
92 
93  namespace internal
94  {
95 
96  template <typename L>
97  void save_page(const document<L>& doc, std::ofstream& output)
98  {
100  doc.accept(f);
101  }
102 
103  template <typename L>
104  void save_page_extended(const document<L>& doc, std::ofstream& output)
105  {
107  doc.accept(f);
108  }
109 
110 # ifdef HAVE_QT
111  template <typename L>
112  void save_full(const document<L>& doc, std::ofstream& output)
113  {
115  doc.accept(f);
116  }
117 # endif // ! HAVE_QT
118 
119  } // end of namespace scribo::io::xml::internal
120 
121 
122 
123  // FACADE
124 
125  template <typename L>
126  void
127  save(const document<L>& doc,
128  const std::string& output_name,
129  Format format)
130  {
131  mln_trace("scribo::io::xml::save");
132 
133  mln_precondition(doc.is_open());
134 
135  // Open file
136  std::ofstream output(output_name.c_str());
137  if (! output)
138  {
139  std::cerr << "scribo::io::xml::save - ERROR: cannot open file '"
140  << doc.filename() << "'!";
141  return;
142  }
143 
144  // Choose saving method.
145  switch (format)
146  {
147  case Page:
148  internal::save_page(doc, output);
149  break;
150 
151  case PageExtended:
152  internal::save_page_extended(doc, output);
153  break;
154 
155 # ifdef HAVE_QT
156  case Full:
157  internal::save_full(doc, output);
158  break;
159 # endif // ! HAVE_QT
160 
161  default:
162  mln_trace_warning("scribo::io::xml::save - "
163  "Invalid XML format! Skip saving...");
164  }
165 
166  output.close();
167  }
168 
169 
170 # endif // ! MLN_INCLUDE_ONLY
171 
172  } // end of namespace scribo::io::xml
173 
174  } // end of namespace scribo::io
175 
176 } // end of namespace scribo
177 
178 
179 #endif // ! SCRIBO_IO_XML_SAVE_HH