$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
option_check.hh
1 // Copyright (C) 2011, 2012 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_DEBUG_OPTION_CHECK_HH
28 # define SCRIBO_DEBUG_OPTION_CHECK_HH
29 
30 # include <string.h>
31 # include <cstdlib>
32 # include <vector>
33 # include <iostream>
34 # include <mln/core/contract.hh>
35 # include <scribo/debug/logger.hh>
36 
37 namespace scribo
38 {
39 
40  namespace debug
41  {
42 
43  bool check_xml_format(const std::vector<const char *>& args);
44  bool check_ocr_lang(const std::vector<const char *>& args);
45  bool check_sauvola_first_subsampling(const std::vector<const char *>& args);
46  bool check_sauvola_split_ntrue(const std::vector<const char *>& args);
47  bool check_verbose_mode(const std::vector<const char *>& args);
48 
49 # ifndef MLN_INCLUDE_ONLY
50 
51  inline
52  bool check_xml_format(const std::vector<const char *>& args)
53  {
54  static const char *values[] =
55  {
56  "page",
57  "page-ext",
58  "full",
59  0
60  };
61  mln_assertion(args.size() == 1);
62 
63  for (int i = 0; values[i]; ++i)
64  if (!strcmp(values[i], args[0]))
65  return true;
66 
67  std::cerr << "Error: invalid xml format : " << args[0] << std::endl;
68  return false;
69  }
70 
71 
72  inline
73  bool check_ocr_lang(const std::vector<const char *>& args)
74  {
75  static const char *values[] =
76  {
77  "eng",
78  "fra",
79  "deu",
80  "ita",
81  "nld",
82  "por",
83  "spa",
84  "vie",
85  0
86  };
87  mln_assertion(args.size() == 1);
88 
89  for (int i = 0; values[i]; ++i)
90  if (!strcmp(values[i], args[0]))
91  return true;
92 
93  std::cerr << "Error: invalid OCR language : " << args[0] << std::endl;
94  return false;
95  }
96 
97  inline
98  bool check_sauvola_first_subsampling(const std::vector<const char *>& args)
99  {
100  mln_assertion(args.size() == 1);
101 
102  int ratio = atoi(args[0]);
103 
104  if (ratio == 2 || ratio == 3)
105  return true;
106 
107  std::cerr << "Error: invalid subsampling ratio : " << args[0] << std::endl;
108  return false;
109  }
110 
111 
112  inline
113  bool check_sauvola_split_ntrue(const std::vector<const char *>& args)
114  {
115  mln_assertion(args.size() == 1);
116 
117  int ntrue = atoi(args[0]);
118 
119  if (ntrue == 1 || ntrue == 2 || ntrue == 3)
120  return true;
121 
122  std::cerr << "Error: invalid subsampling ratio : " << args[0] << std::endl;
123  return false;
124  }
125 
126 
127  inline
128  bool check_verbose_mode(const std::vector<const char *>& args)
129  {
130  mln_assertion(args.size() == 1);
131 
133  return true;
134 
135  std::cerr << "Error: Invalid verbose mode " << args[0] << std::endl;
136 
137  return false;
138  }
139 
140 
141 # endif // ! MLN_INCLUDE_ONLY
142 
143  } // end of namespace scribo::debug
144 
145 } // end of namespace scribo
146 
147 #endif // ! SCRIBO_DEBUG_OPTION_CHECK_HH