#include <params.h>
List of all members.
Static Public Member Functions |
static bool | ReadParamsFile (const char *file, SetParamConstraint constraint, ParamsVectors *member_params) |
static bool | ReadParamsFromFp (FILE *fp, inT64 end_offset, SetParamConstraint constraint, 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) |
Detailed Description
Definition at line 51 of file params.h.
Member Function Documentation
template<class T >
static T* tesseract::ParamUtils::FindParam |
( |
const char * |
name, |
|
|
const GenericVector< T * > & |
global_vec, |
|
|
const GenericVector< T * > & |
member_vec |
|
) |
| [inline, static] |
Definition at line 77 of file params.h.
{
int i;
for (i = 0; i < global_vec.size(); ++i) {
if (strcmp(global_vec[i]->name_str(), name) == 0) return global_vec[i];
}
for (i = 0; i < member_vec.size(); ++i) {
if (strcmp(member_vec[i]->name_str(), name) == 0) return member_vec[i];
}
return NULL;
}
bool tesseract::ParamUtils::GetParamAsString |
( |
const char * |
name, |
|
|
const ParamsVectors * |
member_params, |
|
|
STRING * |
value |
|
) |
| [static] |
Definition at line 150 of file params.cpp.
{
StringParam *sp = FindParam<StringParam>(name, GlobalParams()->string_params,
member_params->string_params);
if (sp) {
*value = sp->string();
return true;
}
IntParam *ip = FindParam<IntParam>(name, GlobalParams()->int_params,
member_params->int_params);
if (ip) {
char buf[128];
snprintf(buf, sizeof(buf), "%d", inT32(*ip));
*value = buf;
return true;
}
BoolParam *bp = FindParam<BoolParam>(name, GlobalParams()->bool_params,
member_params->bool_params);
if (bp != NULL) {
*value = BOOL8(*bp) ? "1": "0";
return true;
}
DoubleParam *dp = FindParam<DoubleParam>(name, GlobalParams()->double_params,
member_params->double_params);
if (dp != NULL) {
char buf[128];
snprintf(buf, sizeof(buf), "%g", double(*dp));
*value = buf;
return true;
}
return false;
}
void tesseract::ParamUtils::PrintParams |
( |
FILE * |
fp, |
|
|
const ParamsVectors * |
member_params |
|
) |
| [static] |
Definition at line 188 of file params.cpp.
{
int v, i;
int num_iterations = (member_params == NULL) ? 1 : 2;
for (v = 0; v < num_iterations; ++v) {
const ParamsVectors *vec = (v == 0) ? GlobalParams() : member_params;
for (i = 0; i < vec->int_params.size(); ++i) {
fprintf(fp, "%s\t%d\n", vec->int_params[i]->name_str(),
(inT32)(*vec->int_params[i]));
}
for (i = 0; i < vec->bool_params.size(); ++i) {
fprintf(fp, "%s\t%d\n", vec->bool_params[i]->name_str(),
(BOOL8)(*vec->bool_params[i]));
}
for (int i = 0; i < vec->string_params.size(); ++i) {
fprintf(fp, "%s\t%s\n", vec->string_params[i]->name_str(),
vec->string_params[i]->string());
}
for (int i = 0; i < vec->double_params.size(); ++i) {
fprintf(fp, "%s\t%g\n", vec->double_params[i]->name_str(),
(double)(*vec->double_params[i]));
}
}
}
Definition at line 43 of file params.cpp.
{
char flag;
inT16 nameoffset;
FILE *fp;
if (*file == PLUS) {
flag = PLUS;
nameoffset = 1;
} else if (*file == MINUS) {
flag = MINUS;
nameoffset = 1;
} else {
flag = EQUAL;
nameoffset = 0;
}
fp = fopen(file + nameoffset, "rb");
if (fp == NULL) {
tprintf("read_params_file: Can't open %s\n", file + nameoffset);
return true;
}
return ReadParamsFromFp(fp, -1, constraint, member_params);
fclose(fp);
}
Definition at line 71 of file params.cpp.
{
char line[MAX_PATH];
bool anyerr = false;
bool foundit;
inT16 length;
char *valptr;
while ((end_offset < 0 || ftell(fp) < end_offset) &&
fgets(line, MAX_PATH, fp)) {
if (line[0] != '\n' && line[0] != '#') {
length = strlen (line);
if (line[length - 1] == '\n')
line[length - 1] = '\0';
for (valptr = line; *valptr && *valptr != ' ' && *valptr != '\t';
valptr++);
if (*valptr) {
*valptr = '\0';
do
valptr++;
while (*valptr == ' ' || *valptr == '\t');
}
foundit = SetParam(line, valptr, constraint, member_params);
if (!foundit) {
anyerr = true;
tprintf("read_params_file: parameter not found: %s\n", line);
exit(1);
}
}
}
return anyerr;
}
template<class T >
static void tesseract::ParamUtils::RemoveParam |
( |
T * |
param_ptr, |
|
|
GenericVector< T * > * |
vec |
|
) |
| [inline, static] |
Definition at line 91 of file params.h.
{
for (int i = 0; i < vec->size(); ++i) {
if ((*vec)[i] == param_ptr) {
vec->remove(i);
return;
}
}
}
Definition at line 106 of file params.cpp.
{
StringParam *sp = FindParam<StringParam>(name, GlobalParams()->string_params,
member_params->string_params);
if (sp != NULL && sp->constraint_ok(constraint)) sp->set_value(value);
if (*value == '\0') return (sp != NULL);
int intval;
IntParam *ip = FindParam<IntParam>(name, GlobalParams()->int_params,
member_params->int_params);
if (ip && ip->constraint_ok(constraint) &&
sscanf(value, INT32FORMAT, &intval) == 1) ip->set_value(intval);
BoolParam *bp = FindParam<BoolParam>(name, GlobalParams()->bool_params,
member_params->bool_params);
if (bp != NULL && bp->constraint_ok(constraint)) {
if (*value == 'T' || *value == 't' ||
*value == 'Y' || *value == 'y' || *value == '1') {
bp->set_value(true);
} else if (*value == 'F' || *value == 'f' ||
*value == 'N' || *value == 'n' || *value == '0') {
bp->set_value(false);
}
}
double doubleval;
DoubleParam *dp = FindParam<DoubleParam>(name, GlobalParams()->double_params,
member_params->double_params);
if (dp != NULL && dp->constraint_ok(constraint)) {
#ifdef EMBEDDED
doubleval = strtofloat(value);
#else
if (sscanf(value, "%lf", &doubleval) == 1)
#endif
dp->set_value(doubleval);
}
return (sp || ip || bp || dp);
}
The documentation for this class was generated from the following files: