#include <params.h>
|
static bool | ReadParamsFile (const char *file, SetParamConstraint constraint, ParamsVectors *member_params) |
|
static bool | ReadParamsFromFp (SetParamConstraint constraint, TFile *fp, ParamsVectors *member_params) |
|
static bool | SetParam (const char *name, const char *value, SetParamConstraint constraint, ParamsVectors *member_params) |
|
template<class T > |
static T * | FindParam (const char *name, const GenericVector< T * > &global_vec, const GenericVector< T * > &member_vec) |
|
template<class T > |
static void | RemoveParam (T *param_ptr, GenericVector< T * > *vec) |
|
static bool | GetParamAsString (const char *name, const ParamsVectors *member_params, STRING *value) |
|
static void | PrintParams (FILE *fp, const ParamsVectors *member_params) |
|
static void | ResetToDefaults (ParamsVectors *member_params) |
|
Definition at line 64 of file params.h.
◆ FindParam()
template<class T >
static T* tesseract::ParamUtils::FindParam |
( |
const char * |
name, |
|
|
const GenericVector< T * > & |
global_vec, |
|
|
const GenericVector< T * > & |
member_vec |
|
) |
| |
|
inlinestatic |
Definition at line 88 of file params.h.
89 if ((*vec)[i] == param_ptr) {
98 const ParamsVectors* member_params,
◆ GetParamAsString()
bool tesseract::ParamUtils::GetParamAsString |
( |
const char * |
name, |
|
|
const ParamsVectors * |
member_params, |
|
|
STRING * |
value |
|
) |
| |
|
static |
Definition at line 129 of file params.cpp.
133 auto *sp = FindParam<StringParam>(name,
GlobalParams()->string_params,
136 *value = sp->
c_str();
140 auto *ip = FindParam<IntParam>(name,
GlobalParams()->int_params,
144 snprintf(buf,
sizeof(buf),
"%d", int32_t(*ip));
149 auto *bp = FindParam<BoolParam>(name,
GlobalParams()->bool_params,
152 *value = bool(*bp) ?
"1":
"0";
156 auto *dp = FindParam<DoubleParam>(name,
GlobalParams()->double_params,
159 std::ostringstream stream;
160 stream.imbue(std::locale::classic());
161 stream << double(*dp);
162 *value = stream.str().
c_str();
◆ PrintParams()
void tesseract::ParamUtils::PrintParams |
( |
FILE * |
fp, |
|
|
const ParamsVectors * |
member_params |
|
) |
| |
|
static |
Definition at line 168 of file params.cpp.
169 int num_iterations = (member_params ==
nullptr) ? 1 : 2;
170 std::ostringstream stream;
171 stream.imbue(std::locale::classic());
172 for (
int v = 0; v < num_iterations; ++v) {
173 const ParamsVectors *vec = (v == 0) ?
GlobalParams() : member_params;
174 for (
int i = 0; i < vec->int_params.size(); ++i) {
175 stream << vec->
int_params[i]->name_str() <<
'\t' <<
176 (int32_t)(*vec->int_params[i]) <<
'\t' <<
177 vec->int_params[i]->info_str() <<
'\n';
179 for (
int i = 0; i < vec->bool_params.size(); ++i) {
180 stream << vec->bool_params[i]->name_str() <<
'\t' <<
181 bool(*vec->bool_params[i]) <<
'\t' <<
182 vec->bool_params[i]->info_str() <<
'\n';
184 for (
int i = 0; i < vec->string_params.size(); ++i) {
185 stream << vec->string_params[i]->name_str() <<
'\t' <<
186 vec->string_params[i]->c_str() <<
'\t' <<
187 vec->string_params[i]->info_str() <<
'\n';
189 for (
int i = 0; i < vec->double_params.size(); ++i) {
190 stream << vec->double_params[i]->name_str() <<
'\t' <<
191 (double)(*vec->double_params[i]) <<
'\t' <<
192 vec->double_params[i]->info_str() <<
'\n';
195 fprintf(fp,
"%s", stream.str().c_str());
◆ ReadParamsFile()
◆ ReadParamsFromFp()
Definition at line 50 of file params.cpp.
57 while (fp->FGets(line,
MAX_PATH) !=
nullptr) {
58 if (line[0] !=
'\r' && line[0] !=
'\n' && line[0] !=
'#') {
60 for (valptr = line; *valptr && *valptr !=
' ' && *valptr !=
'\t';
66 while (*valptr ==
' ' || *valptr ==
'\t');
68 foundit =
SetParam(line, valptr, constraint, member_params);
72 tprintf(
"Warning: Parameter not found: %s\n", line);
◆ RemoveParam()
template<class T >
static void tesseract::ParamUtils::RemoveParam |
( |
T * |
param_ptr, |
|
|
GenericVector< T * > * |
vec |
|
) |
| |
|
inlinestatic |
◆ ResetToDefaults()
void tesseract::ParamUtils::ResetToDefaults |
( |
ParamsVectors * |
member_params | ) |
|
|
static |
Definition at line 199 of file params.cpp.
201 int num_iterations = (member_params ==
nullptr) ? 1 : 2;
202 for (v = 0; v < num_iterations; ++v) {
203 ParamsVectors *vec = (v == 0) ?
GlobalParams() : member_params;
204 for (i = 0; i < vec->int_params.size(); ++i) {
207 for (i = 0; i < vec->bool_params.size(); ++i) {
208 vec->bool_params[i]->ResetToDefault();
210 for (
int i = 0; i < vec->string_params.size(); ++i) {
211 vec->string_params[i]->ResetToDefault();
213 for (
int i = 0; i < vec->double_params.size(); ++i) {
214 vec->double_params[i]->ResetToDefault();
◆ SetParam()
Definition at line 79 of file params.cpp.
83 auto *sp = FindParam<StringParam>(name,
GlobalParams()->string_params,
85 if (sp !=
nullptr && sp->constraint_ok(constraint)) sp->set_value(value);
86 if (*value ==
'\0')
return (sp !=
nullptr);
89 auto *ip = FindParam<IntParam>(name,
GlobalParams()->int_params,
91 if (ip && ip->constraint_ok(constraint)) {
93 std::stringstream stream(value);
94 stream.imbue(std::locale::classic());
96 if (intval != INT_MIN) {
97 ip->set_value(intval);
102 auto *bp = FindParam<BoolParam>(name,
GlobalParams()->bool_params,
104 if (bp !=
nullptr && bp->constraint_ok(constraint)) {
105 if (*value ==
'T' || *value ==
't' ||
106 *value ==
'Y' || *value ==
'y' || *value ==
'1') {
108 }
else if (*value ==
'F' || *value ==
'f' ||
109 *value ==
'N' || *value ==
'n' || *value ==
'0') {
110 bp->set_value(
false);
115 auto *dp = FindParam<DoubleParam>(name,
GlobalParams()->double_params,
117 if (dp !=
nullptr && dp->constraint_ok(constraint)) {
118 double doubleval = NAN;
119 std::stringstream stream(value);
120 stream.imbue(std::locale::classic());
122 if (!std::isnan(doubleval)) {
123 dp->set_value(doubleval);
126 return (sp || ip || bp || dp);
The documentation for this class was generated from the following files: