Removed serialize and NEWDELETE macros

git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@529 d0cd1f9f-072b-0410-8dd7-cf729c803f20
This commit is contained in:
theraysmith 2010-11-30 00:53:31 +00:00
parent f07d5723f2
commit 4c4d036ee4
19 changed files with 94 additions and 818 deletions

View File

@ -248,6 +248,7 @@ libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
lt_ECHO = @lt_ECHO@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@

View File

@ -288,83 +288,6 @@ void CLIST::set_subtract(int comparator(const void*, const void*),
}
}
/***********************************************************************
* CLIST::prep_serialise
*
* Replace the last member with a count of elements for serialisation.
* This is used on list objects which are members of objects being
* serialised. The containing object has been shallow copied and this member
* function is invoked on the COPY.
**********************************************************************/
void CLIST::prep_serialise() {
CLIST_ITERATOR this_it(this);
inT32 count = 0;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("CLIST::prep_serialise", ABORT, NULL);
#endif
count = 0;
if (!empty ())
for (this_it.mark_cycle_pt ();
!this_it.cycled_list (); this_it.forward ())
count++;
last = (CLIST_LINK *) count;
}
/***********************************************************************
* CLIST::internal_dump
*
* Cause each element on the list to be serialised by walking the list and
* calling the element_serialiser function for each element. The
* element_serialiser simply does the appropriate coercion of the element to
* its real type and then invokes the elements serialise function
**********************************************************************/
void
CLIST::internal_dump (FILE * f, void element_serialiser (FILE *, void *)) {
CLIST_ITERATOR this_it(this);
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("CLIST::internal_dump", ABORT, NULL);
#endif
if (!empty ())
for (this_it.mark_cycle_pt ();
!this_it.cycled_list (); this_it.forward ())
element_serialiser (f, this_it.data ());
}
/***********************************************************************
* CLIST::internal_de_dump
*
* Cause each element on the list to be de_serialised by extracting the count
* of elements on the list, (held in the last member of the dumped version of
* the list object), and then de-serialising that number of list elements,
* adding each to the end of the reconstructed list.
**********************************************************************/
void
CLIST::internal_de_dump (FILE * f, void *element_de_serialiser (FILE *)) {
inT32 count = (ptrdiff_t) last;
CLIST_ITERATOR this_it;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("CLIST::internal_de_dump", ABORT, NULL);
#endif
last = NULL;
this_it.set_to_list (this);
for (; count > 0; count--)
this_it.add_to_end (element_de_serialiser (f));
}
/***********************************************************************
* MEMBER FUNCTIONS OF CLASS: CLIST_ITERATOR

View File

@ -59,10 +59,6 @@ class DLLSYM CLIST_LINK
const CLIST_LINK &) {
data = next = NULL;
}
NEWDELETE2 (CLIST_LINK)
/* NOTE that none of the serialise member functions are required for
CLIST_LINKS as they are never serialised. */
};
/**********************************************************************
@ -141,23 +137,6 @@ class DLLSYM CLIST
void set_subtract(int comparator(const void*, const void*), bool unique,
CLIST* minuend, CLIST* subtrahend);
void internal_dump ( //serialise each elem
FILE * f, //to this file
void element_serialiser ( //using this function
FILE *, void *));
void internal_de_dump ( //de_serial each elem
FILE * f, //from this file
void *element_de_serialiser (//using this function
FILE *));
void prep_serialise(); //change last to count
/* Note that dump() and de_dump() are not required as calls to dump/de_dump a
list class should be handled by a class derived from this.
make_serialise is not required for a similar reason.
*/
};
/***********************************************************************
@ -868,8 +847,6 @@ The macro generates:
- An element deletion function: CLASSNAME##_c1_zapper
- An element copier function:
CLASSNAME##_c1_copier
- An element serialiser function" CLASSNAME##_c1_serialiser
- An element de-serialiser function" CLASSNAME##_c1_de_serialiser
- A CLIST subclass: CLASSNAME##_CLIST
- A CLIST_ITERATOR subclass:
CLASSNAME##_C_IT
@ -877,22 +854,16 @@ The macro generates:
NOTE: Generated names do NOT clash with those generated by ELISTIZE,
ELIST2ISE and CLIST2IZE
Four macros are provided: CLISTIZE, CLISTIZE_S, CLISTIZEH and CLISTIZEH_S
Two macros are provided: CLISTIZE and CLISTIZEH
The ...IZEH macros just define the class names for use in .h files
The ...IZE macros define the code use in .c files
The _S versions define lists which can be serialised. They assume that the
make_serialise() macro is used in the list element class to define
serialise() and de_serialise() members for the list elements.
This, in turn, assumes that the list element class has prep_serialise()
dump() and de_dump() member functions.
***********************************************************************/
/***********************************************************************
CLISTIZEH( CLASSNAME ) and CLISTIZEH_S( CLASSNAME ) MACROS
CLISTIZEH( CLASSNAME ) MACRO
These macros are constructed from 3 fragments CLISTIZEH_A, CLISTIZEH_B and
CLISTIZEH_C. CLISTIZEH is simply a concatenation of these parts.
CLISTIZEH_S has some additional bits thrown in the gaps.
CLISTIZEH is a concatenation of 3 fragments CLISTIZEH_A, CLISTIZEH_B and
CLISTIZEH_C.
***********************************************************************/
#define CLISTIZEH_A( CLASSNAME ) \
@ -980,42 +951,16 @@ public: \
{ return (CLASSNAME*) CLIST_ITERATOR::move_to_last(); } \
};
#define CLISTIZEH( CLASSNAME ) \
\
CLISTIZEH_A( CLASSNAME ) \
\
CLISTIZEH_B( CLASSNAME ) \
\
CLISTIZEH_C( CLASSNAME )
#define CLISTIZEH_S( CLASSNAME ) \
\
CLISTIZEH_A( CLASSNAME ) \
\
extern DLLSYM void CLASSNAME##_c1_serialiser( \
FILE* f, \
void* element); \
\
extern DLLSYM void* CLASSNAME##_c1_de_serialiser( \
FILE* f); \
\
CLISTIZEH_B( CLASSNAME ) \
\
void dump( /* dump to file */ \
FILE* f) \
{ CLIST::internal_dump( f, &CLASSNAME##_c1_serialiser );} \
\
void de_dump( /* get from file */ \
FILE* f) \
{ CLIST::internal_de_dump( f, &CLASSNAME##_c1_de_serialiser );} \
\
make_serialise( CLASSNAME##_CLIST ) \
\
#define CLISTIZEH( CLASSNAME ) \
\
CLISTIZEH_A( CLASSNAME ) \
\
CLISTIZEH_B( CLASSNAME ) \
\
CLISTIZEH_C( CLASSNAME )
/***********************************************************************
CLISTIZE( CLASSNAME ) and CLISTIZE_S( CLASSNAME ) MACROS
CLISTIZE_S is a simple extension to CLISTIZE
CLISTIZE( CLASSNAME ) MACRO
***********************************************************************/
#define CLISTIZE( CLASSNAME ) \
@ -1057,38 +1002,4 @@ new_element = new CLASSNAME; \
return (void*) new_element; \
}
#define CLISTIZE_S( CLASSNAME ) \
\
CLISTIZE( CLASSNAME ) \
\
/*********************************************************************** \
* CLASSNAME##_c1_serialiser \
* \
* A function which can serialise an element \
* This is passed to the generic dump member function so that when a list is \
* serialised the elements on the list are properly serialised. \
**********************************************************************/ \
\
DLLSYM void CLASSNAME##_c1_serialiser( \
FILE* f, \
void* element) \
{ \
((CLASSNAME*) element)->serialise( f ); \
} \
\
\
\
/*********************************************************************** \
* CLASSNAME##_c1_de_serialiser \
* \
* A function which can de-serialise an element \
* This is passed to the generic de-dump member function so that when a list \
* is de-serialised the elements on the list are properly de-serialised. \
**********************************************************************/ \
\
DLLSYM void* CLASSNAME##_c1_de_serialiser( \
FILE* f) \
{ \
return CLASSNAME::de_serialise( f ); \
}
#endif

View File

@ -21,31 +21,6 @@
#include <stdlib.h>
#include "elst.h"
/***********************************************************************
* MEMBER FUNCTIONS OF CLASS: ELIST_LINK
* =====================================
**********************************************************************/
/***********************************************************************
* ELIST_LINK::serialise_asc
*
* Generates an error as it should never be called.
**********************************************************************/
void ELIST_LINK::serialise_asc( //default serialise
FILE *f) {
SERIALISE_LINKS.error ("ELIST_LINK::serialise_asc", ABORT,
"Don't call this, override!");
}
void ELIST_LINK::de_serialise_asc( //default de_serialise
FILE *f) {
SERIALISE_LINKS.error ("ELIST_LINK::de_serialise_asc", ABORT,
"Don't call this, override!");
}
/***********************************************************************
* MEMBER FUNCTIONS OF CLASS: ELIST
* ================================
@ -227,91 +202,6 @@ ELIST_LINK *ELIST::add_sorted_and_find(
return new_link;
}
/***********************************************************************
* ELIST::prep_serialise
*
* Replace the last member with a count of elements for serialisation.
* This is used on list objects which are members of objects being
* serialised. The containing object has been shallow copied and this member
* function is invoked on the COPY.
**********************************************************************/
void ELIST::prep_serialise() {
ELIST_ITERATOR this_it(this);
inT32 count = 0;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST::prep_serialise", ABORT, NULL);
#endif
count = 0;
if (!empty ())
for (this_it.mark_cycle_pt ();
!this_it.cycled_list (); this_it.forward ())
count++;
last = (ELIST_LINK *) count;
}
/***********************************************************************
* ELIST::internal_dump
*
* Cause each element on the list to be serialised by walking the list and
* calling the element_serialiser function for each element. The
* element_serialiser simply does the appropriate coercion of the element to
* its real type and then invokes the elements serialise function
**********************************************************************/
void
ELIST::internal_dump (FILE * f,
void element_serialiser (FILE *, ELIST_LINK *)) {
ELIST_ITERATOR this_it(this);
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST::internal_dump", ABORT, NULL);
#endif
if (!empty ())
for (this_it.mark_cycle_pt ();
!this_it.cycled_list (); this_it.forward ())
element_serialiser (f, this_it.data ());
}
/***********************************************************************
* ELIST::internal_de_dump
*
* Cause each element on the list to be de_serialised by extracting the count
* of elements on the list, (held in the last member of the dumped version of
* the list object), and then de-serialising that number of list elements,
* adding each to the end of the reconstructed list.
**********************************************************************/
void
ELIST::internal_de_dump (FILE * f,
ELIST_LINK * element_de_serialiser (FILE *)) {
inT32 count = (ptrdiff_t) last;
ELIST_ITERATOR this_it;
ELIST_LINK *de_serialised_element;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST::internal_de_dump", ABORT, NULL);
#endif
last = NULL;
this_it.set_to_list (this);
for (; count > 0; count--) {
de_serialised_element = element_de_serialiser (f);
//ignore old ptr
de_serialised_element->next = NULL;
this_it.add_to_end (de_serialised_element);
}
}
/***********************************************************************
* MEMBER FUNCTIONS OF CLASS: ELIST_ITERATOR
* =========================================

View File

@ -103,17 +103,6 @@ class DLLSYM ELIST_LINK
const ELIST_LINK &) {
next = NULL;
}
void serialise_asc( //serialise to ascii
FILE *f);
void de_serialise_asc( //de-serialise from ascii
FILE *f);
/* NOTE that none of the serialise member functions are required for
ELIST_LINKS as they are never serialised. (We demand that the derived
class terminates recursion - just to make sure that it defines the member
functions anyway.)
*/
};
/**********************************************************************
@ -188,24 +177,6 @@ class DLLSYM ELIST
return (add_sorted_and_find(comparator, unique, new_link) == new_link);
}
void internal_dump ( //serialise each elem
FILE * f, //to this file
void element_serialiser ( //using this function
FILE *, ELIST_LINK *));
void internal_de_dump ( //de_serial each elem
FILE * f, //from this file
//using this function
ELIST_LINK * element_de_serialiser (
FILE *));
void prep_serialise(); //change last to count
/* Note that dump() and de_dump() are not required as calls to dump/de_dump a
list class should be handled by a class derived from this.
make_serialise is not required for a similar reason.
*/
};
/***********************************************************************
@ -893,7 +864,7 @@ Replace <parm> with "<parm>". <parm> may be an arbitrary number of tokens
#define QUOTE_IT( parm ) #parm
/***********************************************************************
ELISTIZE( CLASSNAME ) MACROS
ELISTIZE( CLASSNAME ) MACRO
============================
CLASSNAME is assumed to be the name of a class which has a baseclass of
@ -904,29 +875,22 @@ will NOT work correctly for classes derived from this.
The macros generate:
- An element deletion function: CLASSNAME##_zapper
- An element serialiser function" CLASSNAME##_serialiser
- An element de-serialiser function" CLASSNAME##_de_serialiser
- An E_LIST subclass: CLASSNAME##_LIST
- An E_LIST_ITERATOR subclass: CLASSNAME##_IT
NOTE: Generated names are DELIBERATELY designed to clash with those for
ELIST2IZE but NOT with those for CLISTIZE and CLIST2IZE
Four macros are provided: ELISTIZE, ELISTIZE_S, ELISTIZEH and ELISTIZEH_S
Two macros are provided: ELISTIZE and ELISTIZEH.
The ...IZEH macros just define the class names for use in .h files
The ...IZE macros define the code use in .c files
The _S versions define lists which can be serialised. They assume that
the make_serialise() macro is used in the list element class derived from
ELIST_LINK to define serialise() and de_serialise() members for the list
elements.
***********************************************************************/
/***********************************************************************
ELISTIZEH( CLASSNAME ) and ELISTIZEH_S( CLASSNAME ) MACROS
ELISTIZEH( CLASSNAME ) MACRO
These macros are constructed from 3 fragments ELISTIZEH_A, ELISTIZEH_B and
ELISTIZEH_C. ELISTIZEH is simply a concatenation of these parts.
ELISTIZEH_S has some additional bits thrown in the gaps.
ELISTIZEH is a concatenation of 3 fragments ELISTIZEH_A, ELISTIZEH_B and
ELISTIZEH_C.
***********************************************************************/
#define ELISTIZEH_A(CLASSNAME) \
@ -1020,39 +984,9 @@ ELISTIZEH_B( CLASSNAME )
\
ELISTIZEH_C( CLASSNAME )
#define ELISTIZEH_S( CLASSNAME ) \
\
ELISTIZEH_A( CLASSNAME ) \
\
extern DLLSYM void CLASSNAME##_serialiser( \
FILE* f, \
ELIST_LINK* element); \
\
extern DLLSYM ELIST_LINK* CLASSNAME##_de_serialiser( \
FILE* f); \
\
ELISTIZEH_B( CLASSNAME ) \
\
void dump( /* dump to file */ \
FILE* f) \
{ ELIST::internal_dump( f, &CLASSNAME##_serialiser );} \
\
void de_dump( /* get from file */ \
FILE* f) \
{ ELIST::internal_de_dump( f, &CLASSNAME##_de_serialiser );} \
\
void serialise_asc( /*dump to ascii*/ \
FILE* f); \
void de_serialise_asc( /*de-dump from ascii*/\
FILE* f); \
\
make_serialise( CLASSNAME##_LIST ) \
\
ELISTIZEH_C( CLASSNAME )
/***********************************************************************
ELISTIZE( CLASSNAME ) and ELISTIZE_S( CLASSNAME ) MACROS
ELISTIZE_S is a simple extension to ELISTIZE
ELISTIZE( CLASSNAME ) MACRO
***********************************************************************/
#define ELISTIZE(CLASSNAME) \
@ -1081,57 +1015,4 @@ void CLASSNAME##_LIST::deep_copy(const CLASSNAME##_LIST* src_list, \
to_it.add_after_then_move((*copier)(from_it.data())); \
}
#define ELISTIZE_S(CLASSNAME) \
\
ELISTIZE(CLASSNAME) \
\
void CLASSNAME##_LIST::serialise_asc(FILE* f) { \
CLASSNAME##_IT it(this); \
\
serialise_INT32(f, length()); \
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) \
it.data()->serialise_asc(f); /*serialise the list*/ \
} \
\
void CLASSNAME##_LIST::de_serialise_asc(FILE* f) { \
inT32 len; /*length to retrive*/ \
CLASSNAME##_IT it; \
CLASSNAME* new_elt = NULL; /*list element*/ \
\
len = de_serialise_INT32(f); \
it.set_to_list(this); \
for (; len > 0; len--) { \
new_elt = new CLASSNAME; \
new_elt->de_serialise_asc(f); \
it.add_to_end(new_elt); /*put on the list*/ \
} \
return; \
} \
\
\
/*********************************************************************** \
* CLASSNAME##_serialiser \
* \
* A function which can serialise an element \
* This is passed to the generic dump member function so that when a list is \
* serialised the elements on the list are properly serialised. \
**********************************************************************/ \
\
DLLSYM void CLASSNAME##_serialiser(FILE* f, ELIST_LINK* element) { \
reinterpret_cast<CLASSNAME*>(element)->serialise(f); \
} \
\
\
\
/*********************************************************************** \
* CLASSNAME##_de_serialiser \
* \
* A function which can de-serialise an element \
* This is passed to the generic de-dump member function so that when a list \
* is de-serialised the elements on the list are properly de-serialised. \
**********************************************************************/ \
\
DLLSYM ELIST_LINK* CLASSNAME##_de_serialiser(FILE* f) { \
return (ELIST_LINK*) CLASSNAME::de_serialise(f); \
}
#endif

View File

@ -195,93 +195,6 @@ void ELIST2::add_sorted(int comparator(const void*, const void*),
}
}
/***********************************************************************
* ELIST2::prep_serialise
*
* Replace the last member with a count of elements for serialisation.
* This is used on list objects which are members of objects being
* serialised. The containing object has been shallow copied and this member
* function is invoked on the COPY.
**********************************************************************/
void ELIST2::prep_serialise() {
ELIST2_ITERATOR this_it(this);
inT32 count = 0;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2::prep_serialise", ABORT, NULL);
#endif
count = 0;
if (!empty ())
for (this_it.mark_cycle_pt ();
!this_it.cycled_list (); this_it.forward ())
count++;
last = (ELIST2_LINK *) count;
}
/***********************************************************************
* ELIST2::internal_dump
*
* Cause each element on the list to be serialised by walking the list and
* calling the element_serialiser function for each element. The
* element_serialiser simply does the appropriate coercion of the element to
* its real type and then invokes the elements serialise function
**********************************************************************/
void
ELIST2::internal_dump (FILE * f,
void element_serialiser (FILE *, ELIST2_LINK *)) {
ELIST2_ITERATOR this_it(this);
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2::internal_dump", ABORT, NULL);
#endif
if (!empty ())
for (this_it.mark_cycle_pt ();
!this_it.cycled_list (); this_it.forward ())
element_serialiser (f, this_it.data ());
}
/***********************************************************************
* ELIST2::internal_de_dump
*
* Cause each element on the list to be de_serialised by extracting the count
* of elements on the list, (held in the last member of the dumped version of
* the list object), and then de-serialising that number of list elements,
* adding each to the end of the reconstructed list.
**********************************************************************/
void
ELIST2::internal_de_dump (FILE * f,
ELIST2_LINK * element_de_serialiser (FILE *)) {
inT32 count = (ptrdiff_t) last;
ELIST2_ITERATOR this_it;
ELIST2_LINK *de_serialised_element;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2::internal_de_dump", ABORT, NULL);
#endif
last = NULL;
this_it.set_to_list (this);
for (; count > 0; count--) {
de_serialised_element = element_de_serialiser (f);
//ignore old ptr
de_serialised_element->next = NULL;
//ignore old ptr
de_serialised_element->prev = NULL;
this_it.add_to_end (de_serialised_element);
}
}
/***********************************************************************
* MEMBER FUNCTIONS OF CLASS: ELIST2_ITERATOR
* ==========================================

View File

@ -77,12 +77,6 @@ class DLLSYM ELIST2_LINK
const ELIST2_LINK &) {
prev = next = NULL;
}
/* NOTE that none of the serialise member functions are required for
ELIST2_LINKs as they are never serialised. (We demand that the derived
class terminates recursion - just to make sure that it defines the member
functions anyway.)
*/
};
/**********************************************************************
@ -145,24 +139,6 @@ class DLLSYM ELIST2
void add_sorted(int comparator(const void*, const void*),
ELIST2_LINK* new_link);
void internal_dump ( //serialise each elem
FILE * f, //to this file
void element_serialiser ( //using this function
FILE *, ELIST2_LINK *));
void internal_de_dump ( //de_serial each elem
FILE * f, //from this file
//using this function
ELIST2_LINK * element_de_serialiser (
FILE *));
void prep_serialise(); //change last to count
/* Note that dump() and de_dump() are not required as calls to dump/de_dump a
list class should be handled by a class derived from this.
make_serialise is not required for a similar reason.
*/
};
/***********************************************************************
@ -912,8 +888,6 @@ will NOT work correctly for classes derived from this.
The macro generates:
- An element deletion function: CLASSNAME##_zapper
- An element serialiser function" CLASSNAME##_serialiser
- An element de-serialiser function" CLASSNAME##_de_serialiser
- An E_LIST2 subclass: CLASSNAME##_LIST
- An E_LIST2_ITERATOR subclass:
CLASSNAME##_IT
@ -921,21 +895,16 @@ The macro generates:
NOTE: Generated names are DELIBERATELY designed to clash with those for
ELISTIZE but NOT with those for CLISTIZE and CLIST2IZE
Four macros are provided: ELIST2IZE, ELIST2IZE_S, ELIST2IZEH and ELIST2IZEH_S
Two macros are provided: ELIST2IZE and ELIST2IZEH
The ...IZEH macros just define the class names for use in .h files
The ...IZE macros define the code use in .c files
The _S versions define lists which can be serialised. They assume that
the make_serialise() macro is used in the list element class derived from
ELIST2_LINK to define serialise() and de_serialise() members for the list
elements.
***********************************************************************/
/***********************************************************************
ELIST2IZEH( CLASSNAME ) and ELIST2IZEH_S( CLASSNAME ) MACROS
ELIST2IZEH( CLASSNAME ) MACRO
These macros are constructed from 3 fragments ELIST2IZEH_A, ELIST2IZEH_B and
ELIST2IZEH_C. ELIST2IZEH is simply a concatenation of these parts.
ELIST2IZEH_S has some additional bits thrown in the gaps.
ELIST2IZEH is a concatenation of 3 fragments ELIST2IZEH_A, ELIST2IZEH_B and
ELIST2IZEH_C.
***********************************************************************/
#define ELIST2IZEH_A( CLASSNAME ) \
@ -1033,34 +1002,9 @@ ELIST2IZEH_B( CLASSNAME ) \
\
ELIST2IZEH_C( CLASSNAME )
#define ELIST2IZEH_S( CLASSNAME ) \
\
ELIST2IZEH_A( CLASSNAME ) \
\
extern DLLSYM void CLASSNAME##_serialiser( \
FILE* f, \
ELIST2_LINK* element); \
\
extern DLLSYM ELIST2_LINK* CLASSNAME##_de_serialiser( \
FILE* f); \
\
ELIST2IZEH_B( CLASSNAME ) \
\
void dump( /* dump to file */ \
FILE* f) \
{ ELIST2::internal_dump( f, &CLASSNAME##_serialiser );} \
\
void de_dump( /* get from file */ \
FILE* f) \
{ ELIST2::internal_de_dump( f, &CLASSNAME##_de_serialiser );} \
\
make_serialise( CLASSNAME##_LIST ) \
\
ELIST2IZEH_C( CLASSNAME )
/***********************************************************************
ELIST2IZE( CLASSNAME ) and ELIST2IZE_S( CLASSNAME ) MACROS
ELIST2IZE_S is a simple extension to ELIST2IZE
ELIST2IZE( CLASSNAME ) MACRO
***********************************************************************/
#define ELIST2IZE( CLASSNAME ) \
@ -1091,31 +1035,4 @@ void CLASSNAME##_LIST::deep_copy(const CLASSNAME##_LIST* src_list, \
to_it.add_after_then_move((*copier)(from_it.data())); \
}
#define ELIST2IZE_S(CLASSNAME) \
\
ELIST2IZE(CLASSNAME) \
\
/*********************************************************************** \
* CLASSNAME##_serialiser \
* \
* A function which can serialise an element \
* This is passed to the generic dump member function so that when a list is \
* serialised the elements on the list are properly serialised. \
**********************************************************************/ \
\
DLLSYM void CLASSNAME##_serialiser(FILE* f, ELIST2_LINK* element) { \
reinterpret_cast<CLASSNAME*>(element)->serialise(f); \
} \
\
/*********************************************************************** \
* CLASSNAME##_de_serialiser \
* \
* A function which can de-serialise an element \
* This is passed to the generic de-dump member function so that when a list \
* is de-serialised the elements on the list are properly de-serialised. \
**********************************************************************/ \
\
DLLSYM ELIST2_LINK* CLASSNAME##_de_serialiser(FILE* f) { \
return reinterpret_cast<ELIST2_LINK*>(CLASSNAME::de_serialise(f)); \
}
#endif

View File

@ -104,6 +104,11 @@ inline int DivRounded(int a, int b) {
return a >= 0 ? (a + b / 2) / b : (a - b / 2) / b;
}
// Return a double cast to int with rounding.
inline int IntCastRounded(double x) {
return x >= 0.0 ? static_cast<int>(x + 0.5) : -static_cast<int>(-x + 0.5);
}
// Reverse the order of bytes in a n byte quantity for big/little-endian switch.
inline void ReverseN(void* ptr, int num_bytes) {
char *cptr = reinterpret_cast<char *>(ptr);

View File

@ -27,75 +27,6 @@
#define MEMCHECKS 1 /*report totals */
#define FULLMEMCHECKS 2 /*report on all blocks */
#ifdef __MSW32__
#define NEWDELETE /*replace new & delete*/\
void *operator new( /*fast allocator*/\
size_t size, /*size of object*/\
const char* file=NULL, /*filename*/\
inT32 line=0) /*line number*/\
{\
return alloc_struct(size); /*simple to do*/\
}\
\
void operator delete( /*fast destructor*/\
void *deadstruct, /*thing to free*/\
size_t size) /*sizeof struct*/\
{\
free_struct(deadstruct,size); /*free it*/\
}\
#define NEWDELETE2(name) /*replace new & delete*/\
void *operator new( /*fast allocator*/\
size_t size, /*size of object*/\
const char* file=NULL, /*filename*/\
inT32 line=0) /*line number*/\
{\
return alloc_struct(size,#name); /*simple to do*/\
}\
\
void operator delete( /*fast destructor*/\
void *deadstruct, /*thing to free*/\
size_t size) /*sizeof struct*/\
{\
free_struct(deadstruct,size,#name); /*free it*/\
}\
#undef NEWDELETE
#define NEWDELETE
#undef NEWDELETE2
#define NEWDELETE2(name)
#else
#define NEWDELETE /*replace new & delete*/\
void *operator new( /*fast allocator*/\
size_t size) /*size of object*/\
{\
return alloc_struct(size); /*simple to do*/\
}\
\
void operator delete( /*fast destructor*/\
void *deadstruct, /*thing to free*/\
size_t size) /*sizeof struct*/\
{\
free_struct(deadstruct,size); /*free it*/\
}\
#define NEWDELETE2(name) /*replace new & delete*/\
void *operator new( /*fast allocator*/\
size_t size) /*size of object*/\
{\
return alloc_struct(size,#name); /*simple to do*/\
}\
\
void operator delete( /*fast destructor*/\
void *deadstruct, /*thing to free*/\
size_t size) /*sizeof struct*/\
{\
free_struct(deadstruct,size,#name); /*free it*/\
}\
#endif
/**********************************************************************
* ALLOC_2D_ARRAY
*

View File

@ -144,6 +144,44 @@ bool ParamUtils::SetParam(const char *name, const char* value,
return (sp || ip || bp || dp);
}
bool ParamUtils::GetParamAsString(const char *name,
const ParamsVectors* member_params,
STRING *value) {
// Look for the parameter among string parameters.
StringParam *sp = FindParam<StringParam>(name, GlobalParams()->string_params,
member_params->string_params);
if (sp) {
*value = sp->string();
return true;
}
// Look for the parameter among int parameters.
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;
}
// Look for the parameter among bool parameters.
BoolParam *bp = FindParam<BoolParam>(name, GlobalParams()->bool_params,
member_params->bool_params);
if (bp != NULL) {
*value = BOOL8(*bp) ? "1": "0";
return true;
}
// Look for the parameter among double parameters.
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 ParamUtils::PrintParams(FILE *fp, const ParamsVectors *member_params) {
int v, i;
int num_iterations = (member_params == NULL) ? 1 : 2;

View File

@ -87,6 +87,11 @@ class ParamUtils {
}
}
}
// Fetches the value of the named param as a STRING. Returns false if not
// found.
static bool GetParamAsString(const char *name,
const ParamsVectors* member_params,
STRING *value);
// Print parameters to the given file.
static void PrintParams(FILE *fp, const ParamsVectors *member_params);

View File

@ -21,69 +21,6 @@
#include "serialis.h"
#include "scanutils.h"
/* **************************************************************************
These are the only routines that write/read data to/from the serialisation.
"serialise_bytes" and "de_serialise_bytes" are used to serialise NON class
items. The "make_serialise" macro generates "serialise" and "de_serialise"
member functions for the class name specified in the macro parameter.
************************************************************************** */
DLLSYM void *de_serialise_bytes(FILE *f, int size) {
void *ptr;
ptr = alloc_mem (size);
/*
printf( "De_serialising bytes\n" );
printf( " Addr: %d Size: %d\n", int(ptr), size );
*/
if (fread (ptr, size, 1, f) != 1)
READFAILED.error ("de_serialise_bytes", ABORT, NULL);
return ptr;
}
DLLSYM void serialise_bytes(FILE *f, void *ptr, int size) {
/*
printf( "Serialising bytes\n" );
printf( " Addr: %d Size: %d\n", int(ptr), size );
*/
if (fwrite (ptr, size, 1, f) != 1)
WRITEFAILED.error ("serialise_bytes", ABORT, NULL);
}
DLLSYM void serialise_INT32(FILE *f, inT32 the_int) {
if (fprintf (f, INT32FORMAT "\n", the_int) < 0)
WRITEFAILED.error ("serialise_INT32", ABORT, NULL);
}
DLLSYM inT32 de_serialise_INT32(FILE *f) {
inT32 the_int;
if (fscanf (f, INT32FORMAT, &the_int) != 1)
READFAILED.error ("de_serialise_INT32", ABORT, NULL);
return the_int;
}
DLLSYM void serialise_FLOAT64(FILE *f, double the_float) {
if (fprintf (f, "%g\n", the_float) < 0)
WRITEFAILED.error ("serialise_FLOAT64", ABORT, NULL);
}
DLLSYM double de_serialise_FLOAT64(FILE *f) {
double the_float;
if (fscanf (f, "%lg", &the_float) != 1)
READFAILED.error ("de_serialise_FLOAT64", ABORT, NULL);
return the_float;
}
// Byte swap an inT64 or uinT64.
DLLSYM uinT64 reverse64(uinT64 num) {
return ((uinT64)reverse32((uinT32)(num & 0xffffffff)) << 32)

View File

@ -27,22 +27,6 @@
#include "errcode.h"
#include "fileerr.h"
/* **************************************************************************
These are the only routines that write/read data to/from the serialisation.
"serialise_bytes" and "de_serialise_bytes" are used to serialise NON class
items. The "make_serialise" macro generates "serialise" and "de_serialise"
member functions for the class name specified in the macro parameter.
************************************************************************** */
extern DLLSYM void *de_serialise_bytes(FILE *f, int size);
extern DLLSYM void serialise_bytes(FILE *f, void *ptr, int size);
extern DLLSYM void serialise_INT32(FILE *f, inT32 the_int);
extern DLLSYM inT32 de_serialise_INT32(FILE *f);
extern DLLSYM void serialise_FLOAT64(FILE *f, double the_float);
extern DLLSYM double de_serialise_FLOAT64(FILE *f);
// Switch endinan.
extern DLLSYM uinT64 reverse64(uinT64);
extern DLLSYM uinT32 reverse32(uinT32);
@ -56,38 +40,4 @@ Replace <parm> with "<parm>". <parm> may be an arbitrary number of tokens
#define QUOTE_IT( parm ) #parm
#define make_serialise( CLASSNAME ) \
\
NEWDELETE2(CLASSNAME) \
\
void serialise( \
FILE* f) \
{ \
CLASSNAME* shallow_copy; \
\
shallow_copy = (CLASSNAME*) alloc_struct( sizeof( *this ) ); \
memmove( shallow_copy, this, sizeof( *this ) ); \
\
shallow_copy->prep_serialise(); \
if (fwrite( (char*) shallow_copy, sizeof( *shallow_copy ), 1, f ) != 1) \
WRITEFAILED.error( QUOTE_IT( CLASSNAME::serialise ), \
ABORT, NULL ); \
\
free_struct( shallow_copy, sizeof( *this ) ); \
this->dump( f ); \
} \
\
static CLASSNAME* de_serialise( \
FILE* f) \
{ \
CLASSNAME* restored; \
\
restored = (CLASSNAME*) alloc_struct( sizeof( CLASSNAME ) ); \
if (fread( (char*) restored, sizeof( CLASSNAME ), 1, f ) != 1) \
READFAILED.error( QUOTE_IT( CLASSNAME::de_serialise ), \
ABORT, NULL ); \
\
restored->de_dump( f ); \
return restored; \
}
#endif

View File

@ -299,37 +299,6 @@ void STRING::add_str_int(const char* str, int number) {
*this += num_buffer;
}
void STRING::prep_serialise() {
// WARNING
// This method should only be called on a shallow bitwise copy
// by the serialise() method (see serialis.h).
FixHeader();
data_ = (STRING_HEADER *)GetHeader()->used_;
}
void STRING::dump(FILE* f) {
FixHeader();
serialise_bytes (f, data_, GetHeader()->used_);
}
void STRING::de_dump(FILE* f) {
char *instring; //input from read
fprintf(stderr, "de_dump\n");
instring = (char *)de_serialise_bytes(f, (ptrdiff_t)data_);
int len = strlen(instring) + 1;
char* this_cstr = AllocData(len, len);
STRING_HEADER* this_header = GetHeader();
memcpy(this_cstr, instring, len);
this_header->used_ = len;
free_mem(instring);
assert(InvariantOk());
}
STRING & STRING::operator=(const char* cstr) {
STRING_HEADER* this_header = GetHeader();
if (cstr) {

View File

@ -76,16 +76,6 @@ class DLLSYM STRING
// anyway.
void add_str_int(const char* str, int number);
// WARNING
// This method leaks the underlying pointer,
// but that is what the original implementation did
void prep_serialise();
void dump(FILE *f);
void de_dump(FILE *f);
make_serialise (STRING)
// ensure capcaity but keep pointer encapsulated
inline void ensure(inT32 min_capacity) { ensure_cstr(min_capacity); }

View File

@ -32,13 +32,13 @@
namespace tesseract {
void TessdataManager::Init(const char *data_file_name, int debug_level) {
bool TessdataManager::Init(const char *data_file_name, int debug_level) {
int i;
debug_level_ = debug_level;
data_file_ = fopen(data_file_name, "rb");
if (data_file_ == NULL) {
tprintf("Error opening data file %s\n", data_file_name);
exit(1);
return false;
}
fread(&actual_tessdata_num_entries_, sizeof(inT32), 1, data_file_);
bool swap = (actual_tessdata_num_entries_ > kMaxNumTessdataEntries);
@ -60,6 +60,7 @@ void TessdataManager::Init(const char *data_file_name, int debug_level) {
tprintf("Offset for type %d is %lld\n", i, offset_table_[i]);
}
}
return true;
}
void TessdataManager::CopyFile(FILE *input_file, FILE *output_file,

View File

@ -124,8 +124,11 @@ class TessdataManager {
~TessdataManager() {}
int DebugLevel() { return debug_level_; }
/** Opens the given data file and reads the offset table. */
void Init(const char *data_file_name, int debug_level);
/**
* Opens the given data file and reads the offset table.
* Returns true on success.
*/
bool Init(const char *data_file_name, int debug_level);
/** Returns data file pointer. */
inline FILE *GetDataFilePtr() const { return data_file_; }

View File

@ -286,7 +286,7 @@ bool UNICHARSET::save_to_file(FILE *file) const {
return true;
}
bool UNICHARSET::load_from_file(FILE *file) {
bool UNICHARSET::load_from_file(FILE *file, bool skip_fragments) {
int unicharset_size;
char buffer[256];
@ -317,6 +317,13 @@ bool UNICHARSET::load_from_file(FILE *file) {
sscanf(buffer, "%s %x", unichar, &properties) != 2)) {
return false;
}
// Skip fragments if needed.
CHAR_FRAGMENT *frag = NULL;
if (skip_fragments && (frag = CHAR_FRAGMENT::parse_from_string(unichar))) {
delete frag;
continue;
}
// Insert unichar into unicharset and set its properties.
if (strcmp(unichar, "NULL") == 0)
this->unichar_insert(" ");
else

View File

@ -240,17 +240,21 @@ class UNICHARSET {
// Opens the file indicated by filename and loads the UNICHARSET
// from the given file. The previous data is lost.
// Returns true if the operation is successful.
bool load_from_file(const char* const filename) {
bool load_from_file(const char* const filename, bool skip_fragments) {
FILE* file = fopen(filename, "r");
if (file == NULL) return false;
bool result = load_from_file(file);
bool result = load_from_file(file, skip_fragments);
fclose(file);
return result;
}
bool load_from_file(const char* const filename) {
return load_from_file(filename, false);
}
// Loads the UNICHARSET from the given file. The previous data is lost.
// Returns true if the operation is successful.
bool load_from_file(FILE *file);
bool load_from_file(FILE *file, bool skip_fragments);
bool load_from_file(FILE *file) { return load_from_file(file, false); }
// Sets up internal data after loading the file, based on the char
// properties. Called from load_from_file, but also needs to be run