43 #if ! defined(__EST_CHUNK_H__) 
   44 #define __EST_CHUNK_H__ 
   46 #define HAVE_WALLOC_H (1) 
   51 #include <sys/types.h> 
   58 #if defined(__INCULDE_CHUNK_WARNINGS__) 
   59 #    define CHUNK_WARN(WHAT) do { cerr << "chunk: " <<WHAT << "\n";} while (0) 
   61 #    define CHUNK_WARN(WHAT) // empty 
   64 #define __CHUNK_INLINE_AGGRESSIVELY__ (1) 
   66 #if defined(__CHUNK_INLINE_AGGRESSIVELY__) 
   67 #    define CII(BODY) BODY 
   72 #define __CHUNK_USE_WALLOC__ (1) 
   74 #if __CHUNK_USE_WALLOC__ 
   78 # include "EST_walloc.h" 
   82 #    define walloc(T,N) ((T *)malloc(sizeof(T)*(N))) 
   83 #    define wfree(P) free(P) 
   84 #    define wrealloc(P,T,N) ((T *)realloc((P),sizeof(T)*(N))) 
  107     typedef  unsigned short use_counter;
 
  108 #       define MAX_CHUNK_COUNT (USHRT_MAX) 
  109     typedef  int EST_chunk_size;
 
  110 #       define MAX_CHUNK_SIZE  (INT_MAX) 
  122     void *
operator new (
size_t size, 
int bytes);
 
  123     void operator delete (
void *it);
 
  126         CII({
if (count < MAX_CHUNK_COUNT) ++count; });
 
  129         CII({
if (count < MAX_CHUNK_COUNT) 
if (--count == 0) 
delete this;});
 
  135     friend EST_ChunkPtr chunk_allocate(
int bytes, 
const char *initial, 
int initial_len);
 
  138     friend void cp_make_updatable(
EST_ChunkPtr &shared, EST_chunk_size inuse);
 
  141     friend void grow_chunk(
EST_ChunkPtr &shared, EST_chunk_size inuse, EST_chunk_size newsize);
 
  142     friend void grow_chunk(
EST_ChunkPtr &shared, EST_chunk_size newsize);
 
  144     friend ostream &operator << (ostream &s, 
const EST_Chunk &chp);
 
  145     friend void tester(
void);
 
  177     int size(
void)
 const { 
return ptr?ptr->size:0; };
 
  178     int shareing(
void)
 const { 
return ptr?(ptr->count >1):0; };
 
  179     int count(
void)
 const { 
return ptr?(ptr->count):-1; };
 
  206     operator char*() CII({
 
  207       if (ptr && ptr->count > 1) 
 
  209       CHUNK_WARN(
"getting writable version of shared chunk\n");
 
  210       cp_make_updatable(*
this);
 
  212       return ptr?&(ptr->memory[0]):(
char *)NULL;
 
  214     operator const char*() 
const CII({
 
  215       return ptr?&(ptr->memory[0]):(
const char *)NULL;
 
  217     operator const char*() CII({
 
  218       return ptr?&(ptr->memory[0]):(
const char *)NULL;
 
  222     const char operator [] (
int i)
 const { 
return ptr->memory[i]; };
 
  223     char &operator () (
int i) CII({ 
 
  226       CHUNK_WARN(
"getting writable version of shared chunk\n");
 
  227       cp_make_updatable(*
this); 
 
  229       return ptr->memory[i]; 
 
  234     friend EST_ChunkPtr chunk_allocate(
int bytes, 
const char *initial, 
int initial_len);
 
  238     friend void cp_make_updatable(
EST_ChunkPtr &shared, EST_Chunk::EST_chunk_size inuse);
 
  242     friend void grow_chunk(
EST_ChunkPtr &shared, EST_Chunk::EST_chunk_size inuse, EST_Chunk::EST_chunk_size newsize);
 
  243     friend void grow_chunk(
EST_ChunkPtr &shared, EST_Chunk::EST_chunk_size newsize);
 
  246     friend ostream &operator << (ostream &s, 
const EST_ChunkPtr &cp) { 
return (s<< *cp.ptr); };
 
  248     friend void tester(
void);