#include <cstdio>
#include "intproto.h"
#include "oldlist.h"
Go to the source code of this file.
◆ ConfigIsPermanent
#define ConfigIsPermanent |
( |
|
Class, |
|
|
|
ConfigId |
|
) |
| (test_bit((Class)->PermConfigs, ConfigId)) |
◆ IncreaseConfidence
#define IncreaseConfidence |
( |
|
TempConfig | ) |
((TempConfig)->NumTimesSeen++) |
◆ IsEmptyAdaptedClass
#define IsEmptyAdaptedClass |
( |
|
Class | ) |
((Class)->NumPermConfigs == 0 && (Class)->TempProtos == NIL_LIST) |
◆ MakeConfigPermanent
#define MakeConfigPermanent |
( |
|
Class, |
|
|
|
ConfigId |
|
) |
| (SET_BIT((Class)->PermConfigs, ConfigId)) |
◆ MakeProtoPermanent
#define MakeProtoPermanent |
( |
|
Class, |
|
|
|
ProtoId |
|
) |
| (SET_BIT((Class)->PermProtos, ProtoId)) |
◆ NumNonEmptyClassesIn
#define NumNonEmptyClassesIn |
( |
|
Template | ) |
((Template)->NumNonEmptyClasses) |
◆ PermConfigFor
#define PermConfigFor |
( |
|
Class, |
|
|
|
ConfigId |
|
) |
| ((Class)->Config[ConfigId].Perm) |
◆ TempConfigFor
#define TempConfigFor |
( |
|
Class, |
|
|
|
ConfigId |
|
) |
| ((Class)->Config[ConfigId].Temp) |
◆ ADAPT_CLASS
◆ ADAPT_TEMPLATES
◆ PERM_CONFIG
◆ TEMP_CONFIG
◆ TEMP_PROTO
◆ AddAdaptedClass()
This routine adds a new adapted class to an existing set of adapted templates.
- Parameters
-
Templates | set of templates to add new class to |
Class | new class to add to templates |
ClassId | class id to associate with new class |
- Note
- Globals: none
Definition at line 45 of file adaptive.cpp.
47 {
49
50 assert (Templates != nullptr);
51 assert (Class != nullptr);
55
58
59 assert (Templates->
Class[ClassId] ==
nullptr);
60 Templates->
Class[ClassId] = Class;
61
62}
void AddIntClass(INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class)
INT_CLASS NewIntClass(int MaxNumProtos, int MaxNumConfigs)
#define UnusedClassIdIn(T, c)
ADAPT_CLASS Class[MAX_NUM_CLASSES]
◆ free_adapted_class()
Definition at line 124 of file adaptive.cpp.
124 {
132 }
137}
void FreeTempConfig(TEMP_CONFIG Config)
void FreeTempProto(void *arg)
#define ConfigIsPermanent(Class, ConfigId)
#define PermConfigFor(Class, ConfigId)
#define TempConfigFor(Class, ConfigId)
void destroy_nodes(LIST list, void_dest destructor)
◆ free_adapted_templates()
Definition at line 182 of file adaptive.cpp.
182 {
183
184 if (templates != nullptr) {
185 for (
int i = 0; i < (templates->
Templates)->NumClasses; i++)
189 }
190}
void free_adapted_class(ADAPT_CLASS adapt_class)
void free_int_templates(INT_TEMPLATES templates)
◆ FreeTempConfig()
This routine frees all memory consumed by a temporary configuration.
- Parameters
-
- Note
- Globals: none
Definition at line 74 of file adaptive.cpp.
74 {
75 assert (
Config !=
nullptr);
76 FreeBitVector (
Config->Protos);
78}
◆ FreeTempProto()
void FreeTempProto |
( |
void * |
arg | ) |
|
Definition at line 81 of file adaptive.cpp.
81 {
82 auto proto =
static_cast<PROTO>(arg);
83
84 free(proto);
85}
◆ NewAdaptedClass()
This operation allocates and initializes a new adapted class data structure and returns a ptr to it.
- Returns
- Ptr to new class data structure.
- Note
- Globals: none
Definition at line 102 of file adaptive.cpp.
102 {
104
109
114
117
118 return (Class);
119
120}
◆ NewTempConfig()
TEMP_CONFIG NewTempConfig |
( |
int |
MaxProtoId, |
|
|
int |
FontinfoId |
|
) |
| |
This routine allocates and returns a new temporary config.
- Parameters
-
MaxProtoId | max id of any proto in new config |
FontinfoId | font information from pre-trained templates |
- Returns
- Ptr to new temp config.
- Note
- Globals: none
Definition at line 203 of file adaptive.cpp.
203 {
204 int NumProtos = MaxProtoId + 1;
205
207 Config->Protos = NewBitVector (NumProtos);
208
210 Config->MaxProtoId = MaxProtoId;
211 Config->ProtoVectorSize = WordsInVectorOfSize (NumProtos);
212 zero_all_bits (
Config->Protos,
Config->ProtoVectorSize);
213 Config->FontinfoId = FontinfoId;
214
216
217}
◆ NewTempProto()
This routine allocates and returns a new temporary proto.
- Returns
- Ptr to new temporary proto.
- Note
- Globals: none
Definition at line 228 of file adaptive.cpp.
◆ ReadAdaptedClass()
Read an adapted class description from file and return a ptr to the adapted class.
- Parameters
-
fp | open file to read adapted class from |
- Returns
- Ptr to new adapted class.
- Note
- Globals: none
Definition at line 281 of file adaptive.cpp.
281 {
282 int NumTempProtos;
283 int NumConfigs;
284 int i;
286
287
290
291
298
299
300 fp->
FRead(&NumTempProtos,
sizeof(
int), 1);
302 for (i = 0; i < NumTempProtos; i++) {
306 }
307
308
309 fp->
FRead(&NumConfigs,
sizeof(
int), 1);
310 for (i = 0; i < NumConfigs; i++)
313 else
315
316 return (Class);
317
318}
PERM_CONFIG ReadPermConfig(TFile *fp)
TEMP_CONFIG ReadTempConfig(TFile *fp)
#define test_bit(array, bit)
LIST push_last(LIST list, void *item)
int FRead(void *buffer, size_t size, int count)
ADAPTED_CONFIG Config[MAX_NUM_CONFIGS]
◆ ReadPermConfig()
Read a permanent configuration description from file and return a ptr to it.
- Parameters
-
fp | open file to read permanent config from |
- Returns
- Ptr to new permanent configuration description.
- Note
- Globals: none
Definition at line 362 of file adaptive.cpp.
362 {
364 uint8_t NumAmbigs;
365 fp->
FRead(&NumAmbigs,
sizeof(NumAmbigs), 1);
368 Config->Ambigs[NumAmbigs] = -1;
370
372
373}
◆ ReadTempConfig()
Read a temporary configuration description from file and return a ptr to it.
- Parameters
-
fp | open file to read temporary config from |
- Returns
- Ptr to new temporary configuration description.
- Note
- Globals: none
Definition at line 386 of file adaptive.cpp.
◆ WriteAdaptedClass()
void WriteAdaptedClass |
( |
FILE * |
File, |
|
|
ADAPT_CLASS |
Class, |
|
|
int |
NumConfigs |
|
) |
| |
This routine writes a binary representation of Class to File.
- Parameters
-
File | open file to write Class to |
Class | adapted class to write to File |
NumConfigs | number of configs in Class |
- Note
- Globals: none
Definition at line 409 of file adaptive.cpp.
409 {
410 int NumTempProtos;
412 int i;
413
414
416
417
422
423
425 fwrite(&NumTempProtos, sizeof(int), 1, File);
430 }
431
432
433 fwrite(&NumConfigs, sizeof(int), 1, File);
434 for (i = 0; i < NumConfigs; i++)
437 else
439
440}
void WritePermConfig(FILE *File, PERM_CONFIG Config)
void WriteTempConfig(FILE *File, TEMP_CONFIG Config)
◆ WritePermConfig()
void WritePermConfig |
( |
FILE * |
File, |
|
|
PERM_CONFIG |
Config |
|
) |
| |
This routine writes a binary representation of a permanent configuration to File.
- Parameters
-
File | open file to write Config to |
Config | permanent config to write to File |
- Note
- Globals: none
Definition at line 481 of file adaptive.cpp.
481 {
482 uint8_t NumAmbigs = 0;
483
484 assert (
Config !=
nullptr);
485 while (
Config->Ambigs[NumAmbigs] > 0) ++NumAmbigs;
486
487 fwrite(&NumAmbigs, sizeof(uint8_t), 1, File);
489 fwrite(&(
Config->FontinfoId),
sizeof(
int), 1, File);
490}
◆ WriteTempConfig()
void WriteTempConfig |
( |
FILE * |
File, |
|
|
TEMP_CONFIG |
Config |
|
) |
| |
This routine writes a binary representation of a temporary configuration to File.
- Parameters
-
File | open file to write Config to |
Config | temporary config to write to File |
- Note
- Globals: none
Definition at line 503 of file adaptive.cpp.
503 {
504 assert (
Config !=
nullptr);
505
507 fwrite(
Config->Protos, sizeof (uint32_t),
Config->ProtoVectorSize, File);
508
509}