ccutil/clst.h

Go to the documentation of this file.
00001 
00050 #ifndef CLST_H
00051 #define CLST_H
00052 
00053 #include <stdio.h>
00054 #include "host.h"
00055 #include "serialis.h"
00056 #include "lsterr.h"
00057 
00058 class CLIST_ITERATOR;
00059 
00069 class DLLSYM CLIST_LINK
00070 {
00071   friend class CLIST_ITERATOR;
00072   friend class CLIST;
00073 
00074   CLIST_LINK *next;
00075   void *data;
00076 
00077   public:
00078     CLIST_LINK() {  //constructor
00079       data = next = NULL;
00080     }
00081 
00082     CLIST_LINK(                       //copy constructor
00083                const CLIST_LINK &) {  //dont copy link
00084       data = next = NULL;
00085     }
00086 
00087     void operator= (             //dont copy links
00088     const CLIST_LINK &) {
00089       data = next = NULL;
00090     }
00091 
00092     NEWDELETE2 (CLIST_LINK)
00093     /*
00094    None of the serialise member functions are required for
00095     CLIST_LINKS as they are never serialised.
00096    */
00097 };
00098 
00104 class DLLSYM CLIST
00105 {
00106   friend class CLIST_ITERATOR;
00107 
00108   CLIST_LINK *last;              //End of list
00109   //(Points to head)
00110   CLIST_LINK *First() {  // return first
00111     return last != NULL ? last->next : NULL;
00112   }
00113 
00114   public:
00115     CLIST() {  //constructor
00116       last = NULL;
00117     }
00118 
00119     ~CLIST () {                  //destructor
00120       shallow_clear();
00121     }
00122 
00123     void internal_deep_clear (   //destroy all links
00124       void (*zapper) (void *));  //ptr to zapper functn
00125 
00126     void shallow_clear();  //clear list but dont
00127     //delete data elements
00128 
00129     BOOL8 empty() {  //is list empty?
00130       return !last;
00131     }
00132 
00133     BOOL8 singleton() {
00134       return last != NULL ? (last == last->next) : FALSE;
00135     }
00136 
00137     void shallow_copy(                     //dangerous!!
00138                       CLIST *from_list) {  //beware destructors!!
00139       last = from_list->last;
00140     }
00141 
00142                                  //ptr to copier functn
00143     void internal_deep_copy (void *(*copier) (void *),
00144       const CLIST * list);       //list being copied
00145 
00146     void assign_to_sublist(                           //to this list
00147                            CLIST_ITERATOR *start_it,  //from list start
00148                            CLIST_ITERATOR *end_it);   //from list end
00149 
00150     INT32 length();  //# elements in list
00151 
00152     void sort (                  //sort elements
00153       int comparator (           //comparison routine
00154       const void *, const void *));
00155 
00156     void internal_dump (         //serialise each elem
00157       FILE * f,                  //to this file
00158       void element_serialiser (  //using this function
00159       FILE *, void *));
00160 
00161     void internal_de_dump (      //de_serial each elem
00162       FILE * f,                  //from this file
00163       void *element_de_serialiser (//using this function
00164       FILE *));
00165 
00166     void prep_serialise();  //change last to count
00167 
00168     /* Note that dump() and de_dump() are not required as calls to
00169      dump/de_dump a list class should be handled by a class derived from this.
00170       make_serialise is not required for a similar reason.
00171     */
00172 };
00173 
00179 class DLLSYM CLIST_ITERATOR
00180 {
00181   friend void CLIST::assign_to_sublist(CLIST_ITERATOR *, CLIST_ITERATOR *);
00182 
00183   CLIST *list;                   //List being iterated
00184   CLIST_LINK *prev;              //prev element
00185   CLIST_LINK *current;           //current element
00186   CLIST_LINK *next;              //next element
00187   BOOL8 ex_current_was_last;     //current extracted
00188   //was end of list
00189   BOOL8 ex_current_was_cycle_pt; //current extracted
00190   //was cycle point
00191   CLIST_LINK *cycle_pt;          //point we are cycling
00192   //the list to.
00193   BOOL8 started_cycling;         //Have we moved off
00194   //the start?
00195 
00196   CLIST_LINK *extract_sublist(                            //from this current...
00197                               CLIST_ITERATOR *other_it);  //to other current
00198 
00199   public:
00200     CLIST_ITERATOR() {  //constructor
00201       list = NULL;
00202     }                            //unassigned list
00203 
00204     CLIST_ITERATOR(  //constructor
00205                    CLIST *list_to_iterate);
00206 
00207     void set_to_list(  //change list
00208                      CLIST *list_to_iterate);
00209 
00210     void add_after_then_move(                  //add after current &
00211                              void *new_data);  //move to new
00212 
00213     void add_after_stay_put(                  //add after current &
00214                             void *new_data);  //stay at current
00215 
00216     void add_before_then_move(                  //add before current &
00217                               void *new_data);  //move to new
00218 
00219     void add_before_stay_put(                  //add before current &
00220                              void *new_data);  //stay at current
00221 
00222     void add_list_after(                      //add a list &
00223                         CLIST *list_to_add);  //stay at current
00224 
00225     void add_list_before(                      //add a list &
00226                          CLIST *list_to_add);  //move to it 1st item
00227 
00228     void *data() {  //get current data
00229     #ifdef _DEBUG
00230       if (!list)
00231         NO_LIST.error ("CLIST_ITERATOR::data", ABORT, NULL);
00232       if (!current)
00233         NULL_DATA.error ("CLIST_ITERATOR::data", ABORT, NULL);
00234     #endif
00235       return current->data;
00236     }
00237 
00238     void *data_relative(               //get data + or - ...
00239                         INT8 offset);  //offset from current
00240 
00241     void *forward();  //move to next element
00242 
00243     void *extract();  //remove from list
00244 
00245     void *move_to_first();  //go to start of list
00246 
00247     void *move_to_last();  //go to end of list
00248 
00249     void mark_cycle_pt();  //remember current
00250 
00251     BOOL8 empty() {  //is list empty?
00252     #ifdef _DEBUG
00253       if (!list)
00254         NO_LIST.error ("CLIST_ITERATOR::empty", ABORT, NULL);
00255     #endif
00256       return list->empty ();
00257     }
00258 
00259     BOOL8 current_extracted() {  //current extracted?
00260       return !current;
00261     }
00262 
00263     BOOL8 at_first();  //Current is first?
00264 
00265     BOOL8 at_last();  //Current is last?
00266 
00267     BOOL8 cycled_list();  //Completed a cycle?
00268 
00269     void add_to_end(                  //add at end &
00270                     void *new_data);  //dont move
00271 
00272     void exchange(                            //positions of 2 links
00273                   CLIST_ITERATOR *other_it);  //other iterator
00274 
00275     INT32 length();  //# elements in list
00276 
00277     void sort (                  //sort elements
00278       int comparator (           //comparison routine
00279       const void *, const void *));
00280 
00281 };
00282 
00286 inline void CLIST_ITERATOR::set_to_list(  //change list
00287                                         CLIST *list_to_iterate) {
00288   #ifdef _DEBUG
00289   if (!this)
00290     NULL_OBJECT.error ("CLIST_ITERATOR::set_to_list", ABORT, NULL);
00291   if (!list_to_iterate)
00292     BAD_PARAMETER.error ("CLIST_ITERATOR::set_to_list", ABORT,
00293       "list_to_iterate is NULL");
00294   #endif
00295 
00296   list = list_to_iterate;
00297   prev = list->last;
00298   current = list->First ();
00299   next = current != NULL ? current->next : NULL;
00300   cycle_pt = NULL;               //await explicit set
00301   started_cycling = FALSE;
00302   ex_current_was_last = FALSE;
00303   ex_current_was_cycle_pt = FALSE;
00304 }
00305 
00306 
00310 inline CLIST_ITERATOR::CLIST_ITERATOR(CLIST *list_to_iterate) {
00311   set_to_list(list_to_iterate);
00312 }
00313 
00314 
00319 inline void CLIST_ITERATOR::add_after_then_move(  // element to add
00320                                                 void *new_data) {
00321   CLIST_LINK *new_element;
00322 
00323   #ifdef _DEBUG
00324   if (!this)
00325     NULL_OBJECT.error ("CLIST_ITERATOR::add_after_then_move", ABORT, NULL);
00326   if (!list)
00327     NO_LIST.error ("CLIST_ITERATOR::add_after_then_move", ABORT, NULL);
00328   if (!new_data)
00329     BAD_PARAMETER.error ("CLIST_ITERATOR::add_after_then_move", ABORT,
00330       "new_data is NULL");
00331   #endif
00332 
00333   new_element = new CLIST_LINK;
00334   new_element->data = new_data;
00335 
00336   if (list->empty ()) {
00337     new_element->next = new_element;
00338     list->last = new_element;
00339     prev = next = new_element;
00340   }
00341   else {
00342     new_element->next = next;
00343 
00344     if (current) {               //not extracted
00345       current->next = new_element;
00346       prev = current;
00347       if (current == list->last)
00348         list->last = new_element;
00349     }
00350     else {                       //current extracted
00351       prev->next = new_element;
00352       if (ex_current_was_last)
00353         list->last = new_element;
00354       if (ex_current_was_cycle_pt)
00355         cycle_pt = new_element;
00356     }
00357   }
00358   current = new_element;
00359 }
00360 
00361 
00366 inline void CLIST_ITERATOR::add_after_stay_put(  // element to add
00367                                                void *new_data) {
00368   CLIST_LINK *new_element;
00369 
00370   #ifdef _DEBUG
00371   if (!this)
00372     NULL_OBJECT.error ("CLIST_ITERATOR::add_after_stay_put", ABORT, NULL);
00373   if (!list)
00374     NO_LIST.error ("CLIST_ITERATOR::add_after_stay_put", ABORT, NULL);
00375   if (!new_data)
00376     BAD_PARAMETER.error ("CLIST_ITERATOR::add_after_stay_put", ABORT,
00377       "new_data is NULL");
00378   #endif
00379 
00380   new_element = new CLIST_LINK;
00381   new_element->data = new_data;
00382 
00383   if (list->empty ()) {
00384     new_element->next = new_element;
00385     list->last = new_element;
00386     prev = next = new_element;
00387     ex_current_was_last = FALSE;
00388     current = NULL;
00389   }
00390   else {
00391     new_element->next = next;
00392 
00393     if (current) {               //not extracted
00394       current->next = new_element;
00395       if (prev == current)
00396         prev = new_element;
00397       if (current == list->last)
00398         list->last = new_element;
00399     }
00400     else {                       //current extracted
00401       prev->next = new_element;
00402       if (ex_current_was_last) {
00403         list->last = new_element;
00404         ex_current_was_last = FALSE;
00405       }
00406     }
00407     next = new_element;
00408   }
00409 }
00410 
00411 
00416 inline void CLIST_ITERATOR::add_before_then_move(  // element to add
00417                                                  void *new_data) {
00418   CLIST_LINK *new_element;
00419 
00420   #ifdef _DEBUG
00421   if (!this)
00422     NULL_OBJECT.error ("CLIST_ITERATOR::add_before_then_move", ABORT, NULL);
00423   if (!list)
00424     NO_LIST.error ("CLIST_ITERATOR::add_before_then_move", ABORT, NULL);
00425   if (!new_data)
00426     BAD_PARAMETER.error ("CLIST_ITERATOR::add_before_then_move", ABORT,
00427       "new_data is NULL");
00428   #endif
00429 
00430   new_element = new CLIST_LINK;
00431   new_element->data = new_data;
00432 
00433   if (list->empty ()) {
00434     new_element->next = new_element;
00435     list->last = new_element;
00436     prev = next = new_element;
00437   }
00438   else {
00439     prev->next = new_element;
00440     if (current) {               //not extracted
00441       new_element->next = current;
00442       next = current;
00443     }
00444     else {                       //current extracted
00445       new_element->next = next;
00446       if (ex_current_was_last)
00447         list->last = new_element;
00448       if (ex_current_was_cycle_pt)
00449         cycle_pt = new_element;
00450     }
00451   }
00452   current = new_element;
00453 }
00454 
00455 
00460 inline void CLIST_ITERATOR::add_before_stay_put(  // element to add
00461                                                 void *new_data) {
00462   CLIST_LINK *new_element;
00463 
00464   #ifdef _DEBUG
00465   if (!this)
00466     NULL_OBJECT.error ("CLIST_ITERATOR::add_before_stay_put", ABORT, NULL);
00467   if (!list)
00468     NO_LIST.error ("CLIST_ITERATOR::add_before_stay_put", ABORT, NULL);
00469   if (!new_data)
00470     BAD_PARAMETER.error ("CLIST_ITERATOR::add_before_stay_put", ABORT,
00471       "new_data is NULL");
00472   #endif
00473 
00474   new_element = new CLIST_LINK;
00475   new_element->data = new_data;
00476 
00477   if (list->empty ()) {
00478     new_element->next = new_element;
00479     list->last = new_element;
00480     prev = next = new_element;
00481     ex_current_was_last = TRUE;
00482     current = NULL;
00483   }
00484   else {
00485     prev->next = new_element;
00486     if (current) {               //not extracted
00487       new_element->next = current;
00488       if (next == current)
00489         next = new_element;
00490     }
00491     else {                       //current extracted
00492       new_element->next = next;
00493       if (ex_current_was_last)
00494         list->last = new_element;
00495     }
00496     prev = new_element;
00497   }
00498 }
00499 
00500 
00505 inline void CLIST_ITERATOR::add_list_after(CLIST *list_to_add) {
00506   #ifdef _DEBUG
00507   if (!this)
00508     NULL_OBJECT.error ("CLIST_ITERATOR::add_list_after", ABORT, NULL);
00509   if (!list)
00510     NO_LIST.error ("CLIST_ITERATOR::add_list_after", ABORT, NULL);
00511   if (!list_to_add)
00512     BAD_PARAMETER.error ("CLIST_ITERATOR::add_list_after", ABORT,
00513       "list_to_add is NULL");
00514   #endif
00515 
00516   if (!list_to_add->empty ()) {
00517     if (list->empty ()) {
00518       list->last = list_to_add->last;
00519       prev = list->last;
00520       next = list->First ();
00521       ex_current_was_last = TRUE;
00522       current = NULL;
00523     }
00524     else {
00525       if (current) {             //not extracted
00526         current->next = list_to_add->First ();
00527         if (current == list->last)
00528           list->last = list_to_add->last;
00529         list_to_add->last->next = next;
00530         next = current->next;
00531       }
00532       else {                     //current extracted
00533         prev->next = list_to_add->First ();
00534         if (ex_current_was_last) {
00535           list->last = list_to_add->last;
00536           ex_current_was_last = FALSE;
00537         }
00538         list_to_add->last->next = next;
00539         next = prev->next;
00540       }
00541     }
00542     list_to_add->last = NULL;
00543   }
00544 }
00545 
00546 
00552 inline void CLIST_ITERATOR::add_list_before(CLIST *list_to_add) {
00553   #ifdef _DEBUG
00554   if (!this)
00555     NULL_OBJECT.error ("CLIST_ITERATOR::add_list_before", ABORT, NULL);
00556   if (!list)
00557     NO_LIST.error ("CLIST_ITERATOR::add_list_before", ABORT, NULL);
00558   if (!list_to_add)
00559     BAD_PARAMETER.error ("CLIST_ITERATOR::add_list_before", ABORT,
00560       "list_to_add is NULL");
00561   #endif
00562 
00563   if (!list_to_add->empty ()) {
00564     if (list->empty ()) {
00565       list->last = list_to_add->last;
00566       prev = list->last;
00567       current = list->First ();
00568       next = current->next;
00569       ex_current_was_last = FALSE;
00570     }
00571     else {
00572       prev->next = list_to_add->First ();
00573       if (current) {             //not extracted
00574         list_to_add->last->next = current;
00575       }
00576       else {                     //current extracted
00577         list_to_add->last->next = next;
00578         if (ex_current_was_last)
00579           list->last = list_to_add->last;
00580         if (ex_current_was_cycle_pt)
00581           cycle_pt = prev->next;
00582       }
00583       current = prev->next;
00584       next = current->next;
00585     }
00586     list_to_add->last = NULL;
00587   }
00588 }
00589 
00590 
00599 inline void *CLIST_ITERATOR::extract() {
00600   void *extracted_data;
00601 
00602   #ifdef _DEBUG
00603   if (!this)
00604     NULL_OBJECT.error ("CLIST_ITERATOR::extract", ABORT, NULL);
00605   if (!list)
00606     NO_LIST.error ("CLIST_ITERATOR::extract", ABORT, NULL);
00607   if (!current)                  //list empty or
00608                                  //element extracted
00609     NULL_CURRENT.error ("CLIST_ITERATOR::extract",
00610       ABORT, NULL);
00611   #endif
00612 
00613   if (list->singleton ())        //special case where
00614                                  //we do need to
00615     prev = next = list->last = NULL;
00616   //      change the iterator
00617   else {
00618     prev->next = next;           //remove from list
00619 
00620     if (current == list->last) {
00621       list->last = prev;
00622       ex_current_was_last = TRUE;
00623     }
00624     else
00625       ex_current_was_last = FALSE;
00626 
00627     ex_current_was_cycle_pt = (current == cycle_pt) ? TRUE : FALSE;
00628 
00629   }
00630   extracted_data = current->data;
00631   delete(current);  //destroy CONS cell
00632   current = NULL;
00633   return extracted_data;
00634 }
00635 
00636 
00642 inline void *CLIST_ITERATOR::move_to_first() {
00643   #ifdef _DEBUG
00644   if (!this)
00645     NULL_OBJECT.error ("CLIST_ITERATOR::move_to_first", ABORT, NULL);
00646   if (!list)
00647     NO_LIST.error ("CLIST_ITERATOR::move_to_first", ABORT, NULL);
00648   #endif
00649 
00650   current = list->First ();
00651   prev = list->last;
00652   next = current != NULL ? current->next : NULL;
00653   return current->data;
00654 }
00655 
00656 
00666 inline void CLIST_ITERATOR::mark_cycle_pt() {
00667   #ifdef _DEBUG
00668   if (!this)
00669     NULL_OBJECT.error ("CLIST_ITERATOR::mark_cycle_pt", ABORT, NULL);
00670   if (!list)
00671     NO_LIST.error ("CLIST_ITERATOR::mark_cycle_pt", ABORT, NULL);
00672   #endif
00673 
00674   if (current)
00675     cycle_pt = current;
00676   else
00677     ex_current_was_cycle_pt = TRUE;
00678   started_cycling = FALSE;
00679 }
00680 
00681 
00685 inline BOOL8 CLIST_ITERATOR::at_first() {
00686   #ifdef _DEBUG
00687   if (!this)
00688     NULL_OBJECT.error ("CLIST_ITERATOR::at_first", ABORT, NULL);
00689   if (!list)
00690     NO_LIST.error ("CLIST_ITERATOR::at_first", ABORT, NULL);
00691   #endif
00692 
00693                                  //we're at a deleted
00694   return ((list->empty ()) || (current == list->First ()) || ((current == NULL) &&
00695     (prev == list->last) &&      //NON-last pt between
00696     !ex_current_was_last));      //first and last
00697 }
00698 
00699 
00703 inline BOOL8 CLIST_ITERATOR::at_last() {
00704   #ifdef _DEBUG
00705   if (!this)
00706     NULL_OBJECT.error ("CLIST_ITERATOR::at_last", ABORT, NULL);
00707   if (!list)
00708     NO_LIST.error ("CLIST_ITERATOR::at_last", ABORT, NULL);
00709   #endif
00710 
00711                                  //we're at a deleted
00712   return ((list->empty ()) || (current == list->last) || ((current == NULL) &&
00713     (prev == list->last) &&      //last point between
00714     ex_current_was_last));       //first and last
00715 }
00716 
00717 
00721 inline BOOL8 CLIST_ITERATOR::cycled_list() {
00722   #ifdef _DEBUG
00723   if (!this)
00724     NULL_OBJECT.error ("CLIST_ITERATOR::cycled_list", ABORT, NULL);
00725   if (!list)
00726     NO_LIST.error ("CLIST_ITERATOR::cycled_list", ABORT, NULL);
00727   #endif
00728 
00729   return ((list->empty ()) || ((current == cycle_pt) && started_cycling));
00730 
00731 }
00732 
00733 
00737 inline INT32 CLIST_ITERATOR::length() {
00738   #ifdef _DEBUG
00739   if (!this)
00740     NULL_OBJECT.error ("CLIST_ITERATOR::length", ABORT, NULL);
00741   if (!list)
00742     NO_LIST.error ("CLIST_ITERATOR::length", ABORT, NULL);
00743   #endif
00744 
00745   return list->length ();
00746 }
00747 
00748 
00752 inline void
00753 CLIST_ITERATOR::sort (           //sort elements
00754 int comparator (                 //comparison routine
00755 const void *, const void *)) {
00756   #ifdef _DEBUG
00757   if (!this)
00758     NULL_OBJECT.error ("CLIST_ITERATOR::sort", ABORT, NULL);
00759   if (!list)
00760     NO_LIST.error ("CLIST_ITERATOR::sort", ABORT, NULL);
00761   #endif
00762 
00763   list->sort (comparator);
00764   move_to_first();
00765 }
00766 
00767 
00775 inline void CLIST_ITERATOR::add_to_end(  // element to add
00776                                        void *new_data) {
00777   CLIST_LINK *new_element;
00778 
00779   #ifdef _DEBUG
00780   if (!this)
00781     NULL_OBJECT.error ("CLIST_ITERATOR::add_to_end", ABORT, NULL);
00782   if (!list)
00783     NO_LIST.error ("CLIST_ITERATOR::add_to_end", ABORT, NULL);
00784   if (!new_data)
00785     BAD_PARAMETER.error ("CLIST_ITERATOR::add_to_end", ABORT,
00786       "new_data is NULL");
00787   #endif
00788 
00789   if (this->at_last ()) {
00790     this->add_after_stay_put (new_data);
00791   }
00792   else {
00793     if (this->at_first ()) {
00794       this->add_before_stay_put (new_data);
00795       list->last = prev;
00796     }
00797     else {                       //Iteratr is elsewhere
00798       new_element = new CLIST_LINK;
00799       new_element->data = new_data;
00800 
00801       new_element->next = list->last->next;
00802       list->last->next = new_element;
00803       list->last = new_element;
00804     }
00805   }
00806 }
00807 
00808 
00812 #define QUOTE_IT( parm ) #parm
00813 
00822 #define CLISTIZEH_A( CLASSNAME )                                  \
00823                                                             \
00824 extern DLLSYM void         CLASSNAME##_c1_zapper(     /*delete a link*/    \
00825 void*                link);                  /*link to delete*/      \
00826                                                             \
00827 extern DLLSYM void*        CLASSNAME##_c1_copier(     /*deep copy a link*/ \
00828 void*                old_element);   /*source link */
00829 
00830 #define CLISTIZEH_B( CLASSNAME )                                  \
00831                                                             \
00832 /***********************************************************************      \
00833 *                    CLASS - CLASSNAME##_CLIST                    \
00834 *                                                           \
00835 *                    List class for class CLASSNAME                  \
00836 *                                                           \
00837 **********************************************************************/       \
00838                                                             \
00839 class DLLSYM            CLASSNAME##_CLIST : public CLIST             \
00840 {                                                           \
00841 public:                                                        \
00842                      CLASSNAME##_CLIST():CLIST() {}                  \
00843                                           /* constructor */    \
00844                                                             \
00845                      CLASSNAME##_CLIST(   /* dont construct */       \
00846    const CLASSNAME##_CLIST&)                    /*by initial assign*/   \
00847    { DONT_CONSTRUCT_LIST_BY_COPY.error( QUOTE_IT( CLASSNAME##_CLIST ),        \
00848                                           ABORT, NULL ); }     \
00849                                                             \
00850 void                 deep_clear()            /* delete elements */   \
00851    { CLIST::internal_deep_clear( &CLASSNAME##_c1_zapper ); }               \
00852                                                             \
00853 void                 deep_copy(              /* become a deep */     \
00854    const CLASSNAME##_CLIST*list)                /* copy of src list*/   \
00855    { CLIST::internal_deep_copy( &CLASSNAME##_c1_copier, list ); }          \
00856                                                             \
00857 void                 operator=(              /* prevent assign */ \
00858    const CLASSNAME##_CLIST&)                                      \
00859    { DONT_ASSIGN_LISTS.error( QUOTE_IT( CLASSNAME##_CLIST ),               \
00860                                  ABORT, NULL ); }
00861 
00862 #define CLISTIZEH_C( CLASSNAME )                                  \
00863                                                             \
00864 };                                                          \
00865                                                             \
00866                                                             \
00867                                                             \
00868 /***********************************************************************      \
00869 *                    CLASS - CLASSNAME##_C_IT                     \
00870 *                                                           \
00871 *                    Iterator class for class CLASSNAME##_CLIST         \
00872 *                                                           \
00873 *  Note: We don't need to coerce pointers to member functions input           \
00874 *  parameters as these are automatically converted to the type of the base    \
00875 *  type. ("A ptr to a class may be converted to a pointer to a public base    \
00876 *  class of that class")                                          \
00877 **********************************************************************/       \
00878                                                             \
00879 class DLLSYM            CLASSNAME##_C_IT : public CLIST_ITERATOR        \
00880 {                                                           \
00881 public:                                                        \
00882                      CLASSNAME##_C_IT():CLIST_ITERATOR(){}           \
00883                                                             \
00884                      CLASSNAME##_C_IT(                         \
00885    CLASSNAME##_CLIST*      list):CLIST_ITERATOR(list){}                 \
00886                                                             \
00887    CLASSNAME*        data()                                    \
00888       { return (CLASSNAME*) CLIST_ITERATOR::data(); }                \
00889                                                             \
00890    CLASSNAME*        data_relative(                            \
00891    INT8              offset)                                   \
00892       { return (CLASSNAME*) CLIST_ITERATOR::data_relative( offset ); }     \
00893                                                             \
00894    CLASSNAME*        forward()                                 \
00895       { return (CLASSNAME*) CLIST_ITERATOR::forward(); }             \
00896                                                             \
00897    CLASSNAME*        extract()                                 \
00898       { return (CLASSNAME*) CLIST_ITERATOR::extract(); }             \
00899                                                             \
00900    CLASSNAME*        move_to_first()                              \
00901       { return (CLASSNAME*) CLIST_ITERATOR::move_to_first(); }          \
00902                                                             \
00903    CLASSNAME*        move_to_last()                            \
00904       { return (CLASSNAME*) CLIST_ITERATOR::move_to_last(); }           \
00905 };
00906 
00907 #define CLISTIZEH( CLASSNAME )                                       \
00908                                                             \
00909 CLISTIZEH_A( CLASSNAME )                                          \
00910                                                             \
00911 CLISTIZEH_B( CLASSNAME )                                          \
00912                                                             \
00913 CLISTIZEH_C( CLASSNAME )
00914 
00915 #define CLISTIZEH_S( CLASSNAME )                                  \
00916                                                             \
00917 CLISTIZEH_A( CLASSNAME )                                          \
00918                                                             \
00919 extern DLLSYM void         CLASSNAME##_c1_serialiser(                   \
00920 FILE*                f,                                     \
00921 void*                element);                                 \
00922                                                             \
00923 extern DLLSYM void*        CLASSNAME##_c1_de_serialiser(                \
00924 FILE*                f);                                       \
00925                                                             \
00926 CLISTIZEH_B( CLASSNAME )                                          \
00927                                                             \
00928    void              dump(                /* dump to file */      \
00929    FILE*             f)                                     \
00930    { CLIST::internal_dump( f, &CLASSNAME##_c1_serialiser );}               \
00931                                                             \
00932    void              de_dump(             /* get from file */     \
00933    FILE*             f)                                     \
00934    { CLIST::internal_de_dump( f, &CLASSNAME##_c1_de_serialiser );}            \
00935                                                             \
00936 make_serialise( CLASSNAME##_CLIST )                                  \
00937                                                             \
00938 CLISTIZEH_C( CLASSNAME )
00939 
00945 #define CLISTIZE( CLASSNAME )                                     \
00946                                                             \
00947 /***********************************************************************      \
00948 *                    CLASSNAME##_c1_zapper                        \
00949 *                                                           \
00950 *  A function which can delete a CLASSNAME element.  This is passed to the    \
00951 *  generic deep_clear list member function so that when a list is cleared the \
00952 *  elements on the list are properly destroyed from the base class, even      \
00953 *  though we dont use a virtual destructor function.                    \
00954 **********************************************************************/       \
00955                                                             \
00956 DLLSYM void             CLASSNAME##_c1_zapper(     /*delete a link*/    \
00957 void*                link)                /*link to delete*/      \
00958 {                                                           \
00959 delete (CLASSNAME *) link;                                        \
00960 }                                                           \
00961                                                             \
00962                                                             \
00963                                                             \
00964 /***********************************************************************      \
00965 *                    CLASSNAME##_c1_copier                        \
00966 *                                                           \
00967 *  A function which can generate a new, deep copy of a CLASSNAME element.     \
00968 *  This is passed to the generic deep copy list member function so that when  \
00969 *  a list is copied the elements on the list are properly copied from the     \
00970 *  base class, even though we dont use a virtual function.                 \
00971 *                                                           \
00972 **********************************************************************/       \
00973                                                             \
00974 DLLSYM void*            CLASSNAME##_c1_copier(     /*deep copy a link*/ \
00975 void*                old_element)            /*source link*/         \
00976 {                                                           \
00977    CLASSNAME*        new_element;                              \
00978                                                             \
00979 new_element = new CLASSNAME;                                      \
00980 *new_element = *((CLASSNAME*) old_element);                          \
00981 return (void*) new_element;                                          \
00982 }
00983 
00984 #define CLISTIZE_S( CLASSNAME )                                      \
00985                                                             \
00986 CLISTIZE( CLASSNAME )                                             \
00987                                                             \
00988 /***********************************************************************      \
00989 *                    CLASSNAME##_c1_serialiser                    \
00990 *                                                           \
00991 *  A function which can serialise an element                         \
00992 *  This is passed to the generic dump member function so that when a list is  \
00993 *  serialised the elements on the list are properly serialised.               \
00994 **********************************************************************/       \
00995                                                             \
00996 DLLSYM void             CLASSNAME##_c1_serialiser(                   \
00997 FILE*                f,                                     \
00998 void*                element)                               \
00999 {                                                           \
01000 ((CLASSNAME*) element)->serialise( f );                              \
01001 }                                                           \
01002                                                             \
01003                                                             \
01004                                                             \
01005 /***********************************************************************      \
01006 *                    CLASSNAME##_c1_de_serialiser                 \
01007 *                                                           \
01008 *  A function which can de-serialise an element                         \
01009 *  This is passed to the generic de-dump member function so that when a list  \
01010 *  is de-serialised the elements on the list are properly de-serialised.      \
01011 **********************************************************************/       \
01012                                                             \
01013 DLLSYM void*            CLASSNAME##_c1_de_serialiser(                \
01014 FILE*                f)                                     \
01015 {                                                           \
01016 return CLASSNAME::de_serialise( f );                                 \
01017 }
01018 #endif

Generated on Wed Feb 28 19:49:09 2007 for Tesseract by  doxygen 1.5.1