![]() |
Leptonica
1.83.1
Image processing and image analysis suite
|
Go to the source code of this file.
Data Structures | |
struct | L_GenAssoc |
Macros | |
#define | TEMPLATE1 "stringtemplate1.txt" /* for assembling autogen.*.c */ |
#define | TEMPLATE2 "stringtemplate2.txt" /* for assembling autogen.*.h */ |
Functions | |
static l_int32 | l_getIndexFromType (const char *type, l_int32 *pindex) |
static l_int32 | l_getIndexFromStructname (const char *sn, l_int32 *pindex) |
static l_int32 | l_getIndexFromFile (const char *filename, l_int32 *pindex) |
static char * | l_genDataString (const char *filein, l_int32 ifunc) |
static char * | l_genCaseString (l_int32 ifunc, l_int32 itype) |
static char * | l_genDescrString (const char *filein, l_int32 ifunc, l_int32 itype) |
L_STRCODE * | strcodeCreate (l_int32 fileno) |
static void | strcodeDestroy (L_STRCODE **pstrcode) |
l_ok | strcodeCreateFromFile (const char *filein, l_int32 fileno, const char *outdir) |
l_ok | strcodeGenerate (L_STRCODE *strcode, const char *filein, const char *type) |
l_int32 | strcodeFinalize (L_STRCODE **pstrcode, const char *outdir) |
l_int32 | l_getStructStrFromFile (const char *filename, l_int32 field, char **pstr) |
Variables | |
static const l_int32 | l_ntypes = 19 |
static const struct L_GenAssoc | l_assoc [] |
Generation of code for storing and extracting serializable leptonica objects (such as pixa, recog, ...). The input is a set of files with serialized data. The output is two files, that must be compiled and linked: ~ autogen.*.c: code for base64 unencoding the strings and deserializing the result. ~ autogen.*.h: function prototypes and base64 encoded strings of the input data This should work for any data structures in leptonica that have *Write() and *Read() serialization functions. An array of 20 of these, including the Pix, is given below. (The Pix is a special case, because it is serialized by standardized compression techniques, instead of a file format determined by leptonica.) Each time the generator function is invoked, three sets of strings are produced, which are written into their respective string arrays: ~ string of serialized, gzipped and base 64 encoded data ~ case string for base64 decoding, gunzipping and deserialization, to return the data struct in memory ~ description string for selecting which struct to return To create the two output files, a finalize function is invoked. There are two ways to do this, both shown in prog/autogentest1.c. ~ Explicitly call strcodeGenerate() for each file with the serialized data structure, followed by strcodeFinalize(). ~ Put the filenames of the serialized data structures in a file, and call strcodeCreateFromFile(). The generated code in autogen.X.c and autogen.X.h (where X is an integer supplied to strcodeCreate()) is then compiled, and the original data can be regenerated using the function l_autodecode_X(). A test example is found in the two prog files: prog/autogentest1.c -- generates autogen.137.c, autogen.137.h prog/autogentest2.c -- uses autogen.137.c, autogen.137.h In general, the generator (e.g., autogentest1) would be compiled and run before compiling and running the application (e.g., autogentest2). L_STRCODE *strcodeCreate() static void strcodeDestroy() (called as part of finalize) void strcodeCreateFromFile() l_int32 strcodeGenerate() l_int32 strcodeFinalize() l_int32 l_getStructStrFromFile() (useful externally) Static helpers static l_int32 l_getIndexFromType() static l_int32 l_getIndexFromStructname() static l_int32 l_getIndexFromFile() static char *l_genDataString() static char *l_genCaseString() static char *l_genDescrString()
Definition in file stringcode.c.
|
static |
[in] | ifunc | index into set of functions in generated file |
[in] | itype | index into type of function to be used |
Notes: (1) ifunc and itype have been validated, so no error can occur
Definition at line 734 of file stringcode.c.
References l_assoc, and stringJoinIP().
Referenced by strcodeGenerate().
|
static |
[in] | filein | input file of serialized data |
[in] | ifunc | index into set of functions in output file |
Definition at line 685 of file stringcode.c.
References l_binaryRead(), L_COPY, L_INSERT, sarrayAddString(), sarrayCreate(), sarrayDestroy(), sarrayToString(), and zlibCompress().
Referenced by strcodeGenerate().
|
static |
[in] | filein | input file of serialized data |
[in] | ifunc | index into set of functions in generated file |
[in] | itype | index into type of function to be used |
Definition at line 768 of file stringcode.c.
References l_assoc, splitPathAtDirectory(), and stringNew().
Referenced by strcodeGenerate().
|
static |
[in] | filename | |
[out] | pindex | found index |
Definition at line 632 of file stringcode.c.
References findFileFormat(), fopenReadStream(), l_getIndexFromStructname(), L_NOCOPY, sarrayCreateWordsFromString(), sarrayDestroy(), and sarrayGetString().
Referenced by l_getStructStrFromFile(), and strcodeCreateFromFile().
|
static |
[in] | sn | structname e.g., "Pixa" |
[out] | pindex | found index |
Notes: (1) This is used to identify the type of serialized file; the first word in the file is the structname. (2) For valid structname, found == true and index > 0.
Definition at line 601 of file stringcode.c.
References l_assoc, and l_ntypes.
Referenced by l_getIndexFromFile().
|
static |
[in] | type | e.g., "PIXA" |
[out] | pindex | found index |
Notes: (1) For valid type, found == true and index > 0.
Definition at line 563 of file stringcode.c.
References l_assoc, and l_ntypes.
Referenced by strcodeGenerate().
l_int32 l_getStructStrFromFile | ( | const char * | filename, |
l_int32 | field, | ||
char ** | pstr | ||
) |
[in] | filename | |
[in] | field | (L_STR_TYPE, L_STR_NAME, L_STR_READER, L_STR_MEMREADER) |
[out] | pstr | struct string for this file |
Notes: (1) For example, if field == L_STR_NAME, and the file is a serialized pixa, this will return "Pixa", the name of the struct. (2) Caller must free the returned string.
Definition at line 518 of file stringcode.c.
References l_assoc, l_getIndexFromFile(), L_STR_MEMREADER, L_STR_NAME, L_STR_READER, L_STR_TYPE, and stringNew().
Referenced by pixaReadBoth().
L_STRCODE* strcodeCreate | ( | l_int32 | fileno | ) |
[in] | fileno | integer that labels the two output files |
Notes: (1) This struct exists to build two files containing code for any number of data objects. The two files are named autogen.[fileno].c autogen.[fileno].h
Definition at line 159 of file stringcode.c.
References L_StrCode::data, L_StrCode::descr, L_StrCode::fileno, L_StrCode::function, lept_mkdir(), and sarrayCreate().
Referenced by strcodeCreateFromFile().
l_ok strcodeCreateFromFile | ( | const char * | filein, |
l_int32 | fileno, | ||
const char * | outdir | ||
) |
[in] | filein | containing filenames of serialized data |
[in] | fileno | integer that labels the two output files |
[in] | outdir | [optional] if null, files are made in /tmp/lept/auto |
Notes: (1) The filein has one filename on each line. Comment lines begin with "#". (2) The output is 2 files: autogen.[fileno].c autogen.[fileno].h
Definition at line 221 of file stringcode.c.
References l_assoc, l_binaryRead(), l_getIndexFromFile(), L_NOCOPY, sarrayCreateLinesFromString(), sarrayDestroy(), sarrayGetCount(), sarrayGetString(), strcodeCreate(), strcodeFinalize(), and strcodeGenerate().
|
static |
[out] | pstrcode | will be set to null after destroying the sarrays |
Definition at line 183 of file stringcode.c.
References L_StrCode::data, L_StrCode::descr, L_StrCode::function, and sarrayDestroy().
l_int32 strcodeFinalize | ( | L_STRCODE ** | pstrcode, |
const char * | outdir | ||
) |
[in,out] | pstrcode | destroys and sets to null after .c and .h files have been generated |
[in] | outdir | [optional] if NULL, make files in /tmp/lept/auto |
Definition at line 331 of file stringcode.c.
References l_binaryRead(), lept_mkdir(), and stringNew().
Referenced by strcodeCreateFromFile().
l_ok strcodeGenerate | ( | L_STRCODE * | strcode, |
const char * | filein, | ||
const char * | type | ||
) |
[in] | strcode | for accumulating data |
[in] | filein | input file with serialized data |
[in] | type | of data; use the typedef string |
Notes: (1) The generated function name is l_autodecode_[fileno]() where [fileno] is the index label for the pair of output files. (2) To deserialize this data, the function is called with the argument 'ifunc', which increments each time strcodeGenerate() is called.
Definition at line 285 of file stringcode.c.
References L_StrCode::data, L_StrCode::descr, L_StrCode::function, L_StrCode::ifunc, l_genCaseString(), l_genDataString(), l_genDescrString(), l_getIndexFromType(), L_INSERT, L_StrCode::n, and sarrayAddString().
Referenced by strcodeCreateFromFile().
|
static |
Serializable data types
Definition at line 109 of file stringcode.c.
Referenced by l_genCaseString(), l_genDescrString(), l_getIndexFromStructname(), l_getIndexFromType(), l_getStructStrFromFile(), and strcodeCreateFromFile().
|
static |
Number of serializable data types
Definition at line 109 of file stringcode.c.
Referenced by l_getIndexFromStructname(), and l_getIndexFromType().