tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
commandlineflags.h
1 /**********************************************************************
2  * File: commandlineflags.h
3  * Description: Header file for commandline flag parsing.
4  * Author: Ranjith Unnikrishnan
5  * Created: July 2013
6  *
7  * (C) Copyright 2013, Google Inc.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 #ifndef TESSERACT_TRAINING_COMMANDLINEFLAGS_H_
20 #define TESSERACT_TRAINING_COMMANDLINEFLAGS_H_
21 
22 #ifndef GOOGLE_TESSERACT
23 
24 #include <cstdlib>
25 #include "tprintf.h"
26 #include "params.h"
27 
28 #define INT_PARAM_FLAG(name, val, comment) \
29  INT_VAR(FLAGS_##name, val, comment)
30 #define DECLARE_INT_PARAM_FLAG(name) \
31  extern INT_VAR_H(FLAGS_##name, 0, "")
32 #define DOUBLE_PARAM_FLAG(name, val, comment) \
33  double_VAR(FLAGS_##name, val, comment)
34 #define DECLARE_DOUBLE_PARAM_FLAG(name) \
35  extern double_VAR_H(FLAGS_##name, "", "")
36 #define BOOL_PARAM_FLAG(name, val, comment) \
37  BOOL_VAR(FLAGS_##name, val, comment)
38 #define DECLARE_BOOL_PARAM_FLAG(name) \
39  extern BOOL_VAR_H(FLAGS_##name, 0, "")
40 #define STRING_PARAM_FLAG(name, val, comment) \
41  STRING_VAR(FLAGS_##name, val, comment)
42 #define DECLARE_STRING_PARAM_FLAG(name) \
43  extern STRING_VAR_H(FLAGS_##name, "", "")
44 
45 #else
46 
47 #include "base/commandlineflags.h"
48 #define INT_PARAM_FLAG(name, val, comment) \
49  DEFINE_int32(name, val, comment)
50 #define DECLARE_INT_PARAM_FLAG(name) \
51  DECLARE_int32(name)
52 #define DOUBLE_PARAM_FLAG(name, val, comment) \
53  DEFINE_double(name, val, comment)
54 #define DECLARE_DOUBLE_PARAM_FLAG(name) \
55  DECLARE_double(name)
56 #define BOOL_PARAM_FLAG(name, val, comment) \
57  DEFINE_bool(name, val, comment)
58 #define DECLARE_BOOL_PARAM_FLAG(name) \
59  DECLARE_bool(name)
60 #define STRING_PARAM_FLAG(name, val, comment) \
61  DEFINE_string(name, val, comment)
62 #define DECLARE_STRING_PARAM_FLAG(name) \
63  DECLARE_string(name)
64 
65 #endif
66 
67 namespace tesseract {
68 
69 // Parse commandline flags and values. Prints the usage string and exits on
70 // input of --help or --version.
71 //
72 // If remove_flags is true, the argv pointer is advanced so that (*argv)[1]
73 // points to the first non-flag argument, (*argv)[0] points to the same string
74 // as before, and argc is decremented to reflect the new shorter length of argv.
75 // eg. If the input *argv is
76 // { "program", "--foo=4", "--bar=true", "file1", "file2" } with *argc = 5, the
77 // output *argv is { "program", "file1", "file2" } with *argc = 3
78 void ParseCommandLineFlags(const char* usage, int* argc,
79  char*** argv, const bool remove_flags);
80 
81 }
82 
83 #endif // TESSERACT_TRAINING_COMMANDLINEFLAGS_H_
void ParseCommandLineFlags(const char *usage, int *argc, char ***argv, const bool remove_flags)
Definition: commandlineflags.cpp:154
Definition: baseapi.cpp:94