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)
121 EST_Chunk *operator & ();
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;});
132 friend class EST_ChunkPtr;
134 friend EST_ChunkPtr chunk_allocate(
int bytes);
135 friend EST_ChunkPtr chunk_allocate(
int bytes,
const char *initial,
int initial_len);
136 friend EST_ChunkPtr chunk_allocate(
int bytes,
const EST_ChunkPtr &initial,
int initial_start,
int initial_len);
138 friend void cp_make_updatable(EST_ChunkPtr &shared, EST_chunk_size inuse);
139 friend void cp_make_updatable(EST_ChunkPtr &shared);
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);
167 EST_ChunkPtr(
void) { ptr = (
EST_Chunk *)NULL; };
169 EST_ChunkPtr(
const EST_ChunkPtr &cp) CII({
175 ~EST_ChunkPtr(
void) CII({
if (ptr) -- *ptr; });
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; };
181 EST_ChunkPtr &operator = (EST_ChunkPtr cp) CII({
194 EST_ChunkPtr &operator = (
EST_Chunk *chp) CII({
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];
233 friend EST_ChunkPtr chunk_allocate(
int size);
234 friend EST_ChunkPtr chunk_allocate(
int bytes,
const char *initial,
int initial_len);
235 friend EST_ChunkPtr chunk_allocate(
int bytes,
const EST_ChunkPtr &initial,
int initial_start,
int initial_len);
238 friend void cp_make_updatable(EST_ChunkPtr &shared, EST_Chunk::EST_chunk_size inuse);
239 friend void cp_make_updatable(EST_ChunkPtr &shared);
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);