tesseract
3.03
|
00001 /********************************************************************** 00002 * File: commandlineflags.h 00003 * Description: Header file for commandline flag parsing. 00004 * Author: Ranjith Unnikrishnan 00005 * Created: July 2013 00006 * 00007 * (C) Copyright 2013, Google Inc. 00008 ** Licensed under the Apache License, Version 2.0 (the "License"); 00009 ** you may not use this file except in compliance with the License. 00010 ** You may obtain a copy of the License at 00011 ** http://www.apache.org/licenses/LICENSE-2.0 00012 ** Unless required by applicable law or agreed to in writing, software 00013 ** distributed under the License is distributed on an "AS IS" BASIS, 00014 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 ** See the License for the specific language governing permissions and 00016 ** limitations under the License. 00017 * 00018 **********************************************************************/ 00019 #ifndef TESSERACT_TRAINING_COMMANDLINEFLAGS_H_ 00020 #define TESSERACT_TRAINING_COMMANDLINEFLAGS_H_ 00021 00022 #ifdef USE_STD_NAMESPACE 00023 00024 #include <stdlib.h> 00025 #include "tprintf.h" 00026 #include "params.h" 00027 00028 #define INT_PARAM_FLAG(name, val, comment) \ 00029 INT_VAR(FLAGS_##name, val, comment) 00030 #define DECLARE_INT_PARAM_FLAG(name) \ 00031 extern INT_VAR_H(FLAGS_##name, 0, "") 00032 #define DOUBLE_PARAM_FLAG(name, val, comment) \ 00033 double_VAR(FLAGS_##name, val, comment) 00034 #define DECLARE_DOUBLE_PARAM_FLAG(name) \ 00035 extern double_VAR_H(FLAGS_##name, "", "") 00036 #define BOOL_PARAM_FLAG(name, val, comment) \ 00037 BOOL_VAR(FLAGS_##name, val, comment) 00038 #define DECLARE_BOOL_PARAM_FLAG(name) \ 00039 extern BOOL_VAR_H(FLAGS_##name, 0, "") 00040 #define STRING_PARAM_FLAG(name, val, comment) \ 00041 STRING_VAR(FLAGS_##name, val, comment) 00042 #define DECLARE_STRING_PARAM_FLAG(name) \ 00043 extern STRING_VAR_H(FLAGS_##name, "", "") 00044 00045 #else 00046 00047 #include "base/commandlineflags.h" 00048 #define INT_PARAM_FLAG(name, val, comment) \ 00049 DEFINE_int32(name, val, comment) 00050 #define DECLARE_INT_PARAM_FLAG(name) \ 00051 DECLARE_int32(name) 00052 #define DOUBLE_PARAM_FLAG(name, val, comment) \ 00053 DEFINE_double(name, val, comment) 00054 #define DECLARE_DOUBLE_PARAM_FLAG(name) \ 00055 DECLARE_double(name) 00056 #define BOOL_PARAM_FLAG(name, val, comment) \ 00057 DEFINE_bool(name, val, comment) 00058 #define DECLARE_BOOL_PARAM_FLAG(name) \ 00059 DECLARE_bool(name) 00060 #define STRING_PARAM_FLAG(name, val, comment) \ 00061 DEFINE_string(name, val, comment) 00062 #define DECLARE_STRING_PARAM_FLAG(name) \ 00063 DECLARE_string(name) 00064 00065 #endif 00066 00067 namespace tesseract { 00068 00069 // Parse commandline flags and values. Prints the usage string and exits on 00070 // input of --help or --helpshort. 00071 // 00072 // If remove_flags is true, the argv pointer is advanced so that (*argv)[1] 00073 // points to the first non-flag argument, (*argv)[0] points to the same string 00074 // as before, and argc is decremented to reflect the new shorter length of argv. 00075 // eg. If the input *argv is 00076 // { "program", "--foo=4", "--bar=true", "file1", "file2" } with *argc = 5, the 00077 // output *argv is { "program", "file1", "file2" } with *argc = 3 00078 void ParseCommandLineFlags(const char* usage, int* argc, 00079 char*** argv, const bool remove_flags); 00080 00081 } 00082 00083 #endif // TESSERACT_TRAINING_COMMANDLINEFLAGS_H_