#include <Obstack_T.h>
Collaboration diagram for ACE_Obstack_T< CHAR >:
Public Member Functions | |
ACE_Obstack_T (size_t size=(4096 *sizeof(CHAR))-sizeof(ACE_Obchunk), ACE_Allocator *allocator_strategy=0) | |
~ACE_Obstack_T (void) | |
int | request (size_t len) |
CHAR * | grow (CHAR c) |
void | grow_fast (CHAR c) |
CHAR * | freeze (void) |
CHAR * | copy (const CHAR *data, size_t len) |
size_t | length (void) const |
size_t | size (void) const |
void | unwind (void *obj) |
void | release (void) |
void | dump (void) const |
Dump the state of an object. | |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
Protected Member Functions | |
ACE_Obchunk * | new_chunk (void) |
void | unwind_i (void *obj) |
Protected Attributes | |
ACE_Allocator * | allocator_strategy_ |
Pointer to the allocator used by this Obstack. | |
size_t | size_ |
Current size of the Obstack;. | |
ACE_Obchunk * | head_ |
Head of the Obchunk chain. | |
ACE_Obchunk * | curr_ |
Pointer to the current Obchunk. |
The implementation is similar to the GNU obstack utility, which is used extensively in the GCC compiler.
Definition at line 38 of file Obstack_T.h.
|
Definition at line 124 of file Obstack_T.cpp. References ACE_ALLOCATOR, ACE_TRACE, and ACE_Obstack_T< CHAR >::new_chunk().
00126 : allocator_strategy_ (allocator_strategy), 00127 size_ (size), 00128 head_ (0), 00129 curr_ (0) 00130 { 00131 ACE_TRACE ("ACE_Obstack_T<CHAR>::ACE_Obstack"); 00132 00133 if (this->allocator_strategy_ == 0) 00134 ACE_ALLOCATOR (this->allocator_strategy_, 00135 ACE_Allocator::instance ()); 00136 00137 this->head_ = this->new_chunk (); 00138 this->curr_ = this->head_; 00139 } |
|
Definition at line 142 of file Obstack_T.cpp. References ACE_TRACE, ACE_Allocator::free(), and ACE_Obchunk::next_.
00143 { 00144 ACE_TRACE ("ACE_Obstack_T<CHAR>::~ACE_Obstack_T"); 00145 00146 ACE_Obchunk *temp = this->head_; 00147 00148 while (temp != 0) 00149 { 00150 ACE_Obchunk *next = temp->next_; 00151 temp->next_ = 0; 00152 this->allocator_strategy_->free (temp); 00153 temp = next; 00154 } 00155 } |
|
Copy the data into the current Obchunk and freeze the current block. Return the starting address of the current building block, 0 if error occurs. len specify the string length, not the actually data size. Definition at line 158 of file Obstack_T.cpp. References ACE_TRACE, ACE_Obchunk::cur_, ACE_Obstack_T< CHAR >::freeze(), ACE_OS::memcpy(), and ACE_Obstack_T< CHAR >::request().
|
|
Dump the state of an object.
Definition at line 23 of file Obstack_T.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_TEXT, ACE_TRACE, and LM_DEBUG.
00024 { 00025 #if defined (ACE_HAS_DUMP) 00026 ACE_TRACE ("ACE_Obstack_T<CHAR>::dump"); 00027 00028 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); 00029 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("size_ = %d\n"), this->size_)); 00030 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("head_ = %x\n"), this->head_)); 00031 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("curr_ = %x\n"), this->curr_)); 00032 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); 00033 #endif /* ACE_HAS_DUMP */ 00034 } |
|
Freeze the current building block by null terminating it. Return the starting address of the current building block, 0 if error occurs. Definition at line 216 of file Obstack_T.cpp. References ACE_Obchunk::block_, and ACE_Obchunk::cur_. Referenced by ACE_Obstack_T< CHAR >::copy().
|
|
Inserting a new CHAR c into the current building block without freezing (null terminating) the block. This function will create new chunk by checking the boundary of current Obchunk. Return the location c gets inserted to, or 0 if error. Definition at line 93 of file Obstack_T.cpp. References ACE_TRACE, ACE_Obchunk::cur_, and ACE_Obstack_T< CHAR >::request().
|
|
Inserting a new CHAR c into the current building block without freezing (null terminating) the block and without checking for out-of-bound error. Definition at line 209 of file Obstack_T.cpp. References ACE_Obchunk::cur_.
|
|
Return the maximum length or size of a string that can be put into this Obstack. size = length * sizeof (CHAR).
Definition at line 8 of file Obstack_T.inl.
00009 { 00010 return this->size_ / sizeof (CHAR); 00011 } |
|
Definition at line 109 of file Obstack_T.cpp. References ACE_NEW_MALLOC_RETURN, and ACE_TRACE. Referenced by ACE_Obstack_T< CHAR >::ACE_Obstack_T(), and ACE_Obstack_T< CHAR >::request().
00110 { 00111 ACE_TRACE ("ACE_Obstack_T<CHAR>::new_chunk"); 00112 00113 ACE_Obchunk *temp; 00114 00115 ACE_NEW_MALLOC_RETURN (temp, 00116 static_cast<ACE_Obchunk *> (this->allocator_strategy_->malloc 00117 (sizeof (class ACE_Obchunk) + this->size_)), 00118 ACE_Obchunk (this->size_), 00119 0); 00120 return temp; 00121 } |
|
"Release" the entire stack of Obchunks, putting it back on the free list. Definition at line 200 of file Obstack_T.cpp. References ACE_TRACE, ACE_Obchunk::block_, ACE_Obchunk::contents_, and ACE_Obchunk::cur_.
|
|
Request Obstack to prepare a block at least len long for building a new string. Return -1 if fail, 0 if success. Definition at line 37 of file Obstack_T.cpp. References ACE_TRACE, ACE_Obchunk::block_, ACE_Obchunk::contents_, ACE_Obchunk::cur_, ACE_Obchunk::end_, ACE_OS::memcpy(), ACE_Obstack_T< CHAR >::new_chunk(), and ACE_Obchunk::next_. Referenced by ACE_Obstack_T< CHAR >::copy(), and ACE_Obstack_T< CHAR >::grow().
00038 { 00039 ACE_TRACE ("ACE_Obstack_T<CHAR>::request"); 00040 00041 // normalize the length. 00042 len *= sizeof (CHAR); 00043 00044 // Check to see if there's room for the requested length, including 00045 // any part of an existing string, if any. 00046 size_t resulting_len = (this->curr_->cur_ - this->curr_->block_) + len; 00047 00048 // Increase the length of the underlying chunks if the request made is 00049 // for bigger sized chunks. 00050 if (this->size_ < resulting_len) 00051 this->size_ = this->size_ << 1; 00052 00053 // We now know the request will fit; see if it can fit in the current 00054 // chunk or will need a new one. 00055 if (this->curr_->cur_ + len >= this->curr_->end_) 00056 { 00057 // Need a new chunk. Save the current one so the current string can be 00058 // copied to the new chunk. 00059 ACE_Obchunk *temp = this->curr_; 00060 if (this->curr_->next_ == 0) 00061 { 00062 // We must allocate new memory. 00063 ACE_Obchunk* tmp = this->new_chunk(); 00064 if (!tmp) 00065 return -1; 00066 this->curr_->next_ = tmp; 00067 this->curr_ = this->curr_->next_; 00068 } 00069 else 00070 { 00071 // We can reuse previously allocated memory. 00072 this->curr_ = this->curr_->next_; 00073 this->curr_->block_ = this->curr_->cur_ = this->curr_->contents_; 00074 } 00075 00076 // Copy any initial characters to the new chunk. 00077 if (temp->cur_ != temp->block_) 00078 { 00079 size_t datasize = temp->cur_ - temp->block_; 00080 ACE_OS::memcpy (this->curr_->block_, 00081 temp->block_, 00082 datasize); 00083 this->curr_->cur_ = this->curr_->block_ + datasize; 00084 // Reset the old chunk. 00085 temp->cur_ = temp->block_; 00086 } 00087 } 00088 00089 return 0; 00090 } |
|
Definition at line 14 of file Obstack_T.inl.
00015 { 00016 return this->size_; 00017 } |
|
"Unwind" the stack. If obj is a null pointer, everything allocated in the stack is released. Otherwise, obj must be an address of an object allocated in the stack. In this case, obj is released along with everthing allocated in the Obstack since obj. Definition at line 173 of file Obstack_T.cpp. References ACE_Obchunk::block_, ACE_Obchunk::contents_, ACE_Obchunk::cur_, ACE_Obchunk::end_, and ACE_Obstack_T< CHAR >::unwind_i().
|
|
Search through the list of Obchunks and release them. Helper funtion used by unwind. Definition at line 182 of file Obstack_T.cpp. References ACE_ERROR, ACE_TEXT, ACE_Obchunk::block_, ACE_Obchunk::contents_, ACE_Obchunk::cur_, ACE_Obchunk::end_, LM_ERROR, and ACE_Obchunk::next_. Referenced by ACE_Obstack_T< CHAR >::unwind().
00183 { 00184 ACE_Obchunk* curr; 00185 00186 curr = this->head_; 00187 while (curr != 0 && (curr->contents_ > obj || curr->end_ < obj)) 00188 curr = curr->next_; 00189 if (curr) 00190 { 00191 this->curr_ = curr; 00192 this->curr_->block_ = this->curr_->cur_ = reinterpret_cast<char*> (obj); 00193 } 00194 else if (obj != 0) 00195 ACE_ERROR ((LM_ERROR, 00196 ACE_TEXT ("Deletion of non-existent object.\n%a"))); 00197 } |
|
Declare the dynamic allocation hooks.
Definition at line 96 of file Obstack_T.h. |
|
Pointer to the allocator used by this Obstack.
Definition at line 106 of file Obstack_T.h. |
|
Pointer to the current Obchunk.
Definition at line 116 of file Obstack_T.h. |
|
Head of the Obchunk chain.
Definition at line 113 of file Obstack_T.h. |
|
Current size of the Obstack;.
Definition at line 109 of file Obstack_T.h. |