99 template <
class Type> 
class Block   106     Block(
int size, 
void (*err_function)(
const char *) = NULL) { first = last = NULL; block_size = size; error_function = err_function; }
   109     ~Block() { 
while (first) { block *next = first -> next; 
delete first; first = next; } }
   118         if (!last || last->current + num > last->last)
   120             if (last && last->next) last = last -> next;
   123                 block *next = (block *) 
new char [
sizeof(block) + (block_size-1)*
sizeof(Type)];
   124                 if (!next) { 
if (error_function) (*error_function)(
"Not enough memory!"); exit(1); }
   125                 if (last) last -> next = next;
   128                 last -> current = & ( last -> data[0] );
   129                 last -> last = last -> current + block_size;
   135         last -> current += num;
   142         for (scan_current_block=first; scan_current_block; scan_current_block = scan_current_block->next)
   144             scan_current_data = & ( scan_current_block -> data[0] );
   145             if (scan_current_data < scan_current_block -> current) 
return scan_current_data ++;
   155         while (scan_current_data >= scan_current_block -> current)
   157             scan_current_block = scan_current_block -> next;
   158             if (!scan_current_block) 
return NULL;
   159             scan_current_data = & ( scan_current_block -> data[0] );
   161         return scan_current_data ++;
   169         for (b=first; ; b=b->next)
   171             b -> current = & ( b -> data[0] );
   172             if (b == last) 
break;
   181     typedef struct block_st
   183         Type                    *current, *last;
   184         struct block_st         *next;
   192     block   *scan_current_block;
   193     Type    *scan_current_data;
   195     void    (*error_function)(
const char *);
   209     DBlock(
int size, 
void (*err_function)(
const char *) = NULL) { first = NULL; first_free = NULL; block_size = size; error_function = err_function; }
   212     ~DBlock() { 
while (first) { block *next = first -> next; 
delete first; first = next; } }
   222             first = (block *) 
new char [
sizeof(block) + (block_size-1)*
sizeof(block_item)];
   223             if (!first) { 
if (error_function) (*error_function)(
"Not enough memory!"); exit(1); }
   224             first_free = & (first -> data[0] );
   225             for (item=first_free; item<first_free+block_size-1; item++)
   226                 item -> next_free = item + 1;
   227             item -> next_free = NULL;
   228             first -> next = next;
   232         first_free = item -> next_free;
   233         return (Type *) item;
   239         ((block_item *) t) -> next_free = first_free;
   240         first_free = (block_item *) t;
   247     typedef union block_item_st
   250         block_item_st   *next_free;
   253     typedef struct block_st
   255         struct block_st         *next;
   261     block_item  *first_free;
   263     void    (*error_function)(
const char *);
 ~Block()
Definition: block.h:109
 
Type * New(int num=1)
Definition: block.h:114
 
~DBlock()
Definition: block.h:212
 
Block(int size, void(*err_function)(const char *)=NULL)
Definition: block.h:106
 
Type * ScanFirst()
Definition: block.h:140
 
DBlock(int size, void(*err_function)(const char *)=NULL)
Definition: block.h:209
 
void Delete(Type *t)
Definition: block.h:237
 
Type * ScanNext()
Definition: block.h:153
 
Type * New()
Definition: block.h:215
 
void Reset()
Definition: block.h:165