Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Obstack_T Class Template Reference

#include <Obstack_T.h>

Inheritance diagram for ACE_Obstack_T:

Inheritance graph
[legend]
Collaboration diagram for ACE_Obstack_T:

Collaboration graph
[legend]
List of all members.

Public Methods

 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)
 Request Obstack to prepare a block at least len long for building a new string. Return -1 if fail, 0 if success. More...

CHAR * grow (CHAR c)
 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. More...

void grow_fast (CHAR c)
 Inserting a new CHAR c into the current building block without freezing (null terminating) the block and without checking for out-of-bound error. More...

CHAR * freeze (void)
 Freeze the current building block by null terminating it. Return the starting address of the current building block, 0 if error occurs. More...

CHAR * copy (const CHAR *data, size_t len)
 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. More...

size_t length (void) const
 Return the maximum length or size of a string that can be put into this Obstack. size = length * sizeof (CHAR). Deprecated : No need to use this function as you can put objects of arbitrary lengths into the obstack now. More...

size_t size (void) const
void unwind (void *obj)
 "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. More...

void release (void)
 "Release" the entire stack of Obchunks, putting it back on the free list. More...

void dump (void) const
 Dump the state of an object. More...


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...


Protected Methods

ACE_Obchunknew_chunk (void)
void unwind_i (void *obj)
 Search through the list of Obchunks and release them. Helper funtion used by unwind. More...


Protected Attributes

ACE_Allocatorallocator_strategy_
 Pointer to the allocator used by this Obstack. More...

size_t size_
 Current size of the Obstack;. More...

ACE_Obchunkhead_
 Head of the Obchunk chain. More...

ACE_Obchunkcurr_
 Pointer to the current Obchunk. More...

template<class CHAR>
class ACE_Obstack_T< CHAR >


Constructor & Destructor Documentation

template<class CHAR>
ACE_Obstack_T< CHAR >::ACE_Obstack_T size_t    size = (4096 *sizeof(CHAR))-sizeof(ACE_Obchunk),
ACE_Allocator   allocator_strategy = 0
 

Definition at line 122 of file Obstack_T.cpp.

References ACE_ALLOCATOR, ACE_TRACE, allocator_strategy_, curr_, head_, ACE_Allocator::instance, and new_chunk.

00124   : allocator_strategy_ (allocator_strategy),
00125     size_ (size)
00126 {
00127   ACE_TRACE ("ACE_Obstack_T<CHAR>::ACE_Obstack");
00128 
00129   if (this->allocator_strategy_ == 0)
00130     ACE_ALLOCATOR (this->allocator_strategy_,
00131                    ACE_Allocator::instance ());
00132 
00133   this->head_ = this->new_chunk ();
00134   this->curr_ = this->head_;
00135 }

template<class CHAR>
ACE_Obstack_T< CHAR >::~ACE_Obstack_T void   
 

Definition at line 138 of file Obstack_T.cpp.

References ACE_TRACE, allocator_strategy_, ACE_Allocator::free, head_, and ACE_Obchunk::next_.

00139 {
00140   ACE_TRACE ("ACE_Obstack_T<CHAR>::~ACE_Obstack_T");
00141 
00142   ACE_Obchunk *temp = this->head_;
00143 
00144   while (temp != 0)
00145     {
00146       ACE_Obchunk *next = temp->next_;
00147       temp->next_  = 0;
00148       this->allocator_strategy_->free (temp);
00149       temp = next;
00150     }
00151 }


Member Function Documentation

template<class CHAR>
CHAR * ACE_Obstack_T< CHAR >::copy const CHAR *    data,
size_t    len
 

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 154 of file Obstack_T.cpp.

References ACE_TRACE, ACE_Obchunk::cur_, curr_, freeze, ACE_OS_String::memcpy, and request.

00156 {
00157   ACE_TRACE ("ACE_Obstack_T<CHAR>::copy");
00158 
00159   if (this->request (len) != 0)
00160     return 0;
00161 
00162   size_t tsize = len * sizeof (CHAR);
00163   ACE_OS::memcpy (this->curr_->cur_, s, tsize);
00164   this->curr_->cur_ += tsize ;
00165   return this->freeze ();
00166 }

template<class CHAR>
void ACE_Obstack_T< CHAR >::dump void    const
 

Dump the state of an object.

Definition at line 21 of file Obstack_T.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, and LM_DEBUG.

00022 {
00023   ACE_TRACE ("ACE_Obstack_T<CHAR>::dump");
00024 
00025   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00026   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("size_ = %d\n"), this->size_));
00027   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("head_ = %x\n"), this->head_));
00028   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("curr_ = %x\n"), this->curr_));
00029   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00030 }

template<class CHAR>
ACE_INLINE CHAR * ACE_Obstack_T< CHAR >::freeze void   
 

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 24 of file Obstack_T.i.

References ACE_Obchunk::block_, ACE_Obchunk::cur_, and curr_.

Referenced by copy.

00025 {
00026   CHAR *retv = ACE_reinterpret_cast (CHAR *, this->curr_->block_);
00027   * (ACE_reinterpret_cast (CHAR *,
00028                            this->curr_->cur_)) = 0;
00029 
00030   this->curr_->cur_ += sizeof (CHAR);
00031   this->curr_->block_ = this->curr_->cur_;
00032   return retv;
00033 }

template<class CHAR>
CHAR * ACE_Obstack_T< CHAR >::grow CHAR    c
 

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 89 of file Obstack_T.cpp.

References ACE_TRACE, ACE_Obchunk::cur_, curr_, and request.

00090 {
00091   ACE_TRACE ("ACE_Obstack_T<CHAR>::grow");
00092 
00093   if (this->request (1) == 0)
00094     {
00095       CHAR *retv = ACE_reinterpret_cast (CHAR *,
00096                                          this->curr_->cur_);
00097       this->curr_->cur_ += sizeof (CHAR);
00098       *retv = c;
00099       return retv;
00100     }
00101   else
00102     return 0;
00103 }

template<class CHAR>
ACE_INLINE void ACE_Obstack_T< CHAR >::grow_fast CHAR    c
 

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 16 of file Obstack_T.i.

References ACE_Obchunk::cur_, and curr_.

00017 {
00018   * (ACE_reinterpret_cast (CHAR *,
00019                            this->curr_->cur_)) = c;
00020   this->curr_->cur_ += sizeof (CHAR);
00021 }

template<class CHAR>
ACE_INLINE size_t ACE_Obstack_T< CHAR >::length void    const
 

Return the maximum length or size of a string that can be put into this Obstack. size = length * sizeof (CHAR). Deprecated : No need to use this function as you can put objects of arbitrary lengths into the obstack now.

Definition at line 4 of file Obstack_T.i.

References size_.

00005 {
00006   return this->size_ / sizeof (CHAR);
00007 }

template<class CHAR>
ACE_Obchunk * ACE_Obstack_T< CHAR >::new_chunk void    [protected]
 

Definition at line 106 of file Obstack_T.cpp.

References ACE_NEW_MALLOC_RETURN, and ACE_TRACE.

Referenced by ACE_Obstack_T, and request.

00107 {
00108   ACE_TRACE ("ACE_Obstack_T<CHAR>::new_chunk");
00109 
00110   ACE_Obchunk *temp;
00111 
00112   ACE_NEW_MALLOC_RETURN (temp,
00113                          ACE_static_cast (ACE_Obchunk *,
00114                            this->allocator_strategy_->malloc
00115                              (sizeof (class ACE_Obchunk) + this->size_)),
00116                          ACE_Obchunk (this->size_),
00117                          0);
00118   return temp;
00119 }

template<class CHAR>
void ACE_Obstack_T< CHAR >::release void   
 

"Release" the entire stack of Obchunks, putting it back on the free list.

Definition at line 198 of file Obstack_T.cpp.

References ACE_TRACE, ACE_Obchunk::block_, ACE_Obchunk::contents_, ACE_Obchunk::cur_, curr_, and head_.

00199 {
00200   ACE_TRACE ("ACE_Obstack_T<CHAR>::release");
00201 
00202   this->curr_ = this->head_;
00203   this->curr_->block_ = this->curr_->cur_ = this->curr_->contents_;
00204 }

template<class CHAR>
int ACE_Obstack_T< CHAR >::request size_t    len
 

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 33 of file Obstack_T.cpp.

References ACE_TRACE, ACE_Obchunk::block_, ACE_Obchunk::contents_, ACE_Obchunk::cur_, curr_, ACE_Obchunk::end_, ACE_OS_String::memcpy, new_chunk, ACE_Obchunk::next_, and size_.

Referenced by copy, and grow.

00034 {
00035   ACE_TRACE ("ACE_Obstack_T<CHAR>::request");
00036 
00037   // normalize the length.
00038   len *= sizeof (CHAR);
00039 
00040   // Check to see if there's room for the requested length, including
00041   // any part of an existing string, if any.
00042   size_t resulting_len = (this->curr_->cur_ - this->curr_->block_) + len;
00043 
00044   // Increase the length of the underlying chunks if the request made is
00045   // for bigger sized chunks.
00046   if (this->size_ < resulting_len)
00047     this->size_ = this->size_ << 1;
00048 
00049   // We now know the request will fit; see if it can fit in the current
00050   // chunk or will need a new one.
00051   if (this->curr_->cur_ + len >= this->curr_->end_)
00052     {
00053       // Need a new chunk. Save the current one so the current string can be
00054       // copied to the new chunk.
00055       ACE_Obchunk *temp = this->curr_;
00056       if (this->curr_->next_ == 0)
00057         {
00058           // We must allocate new memory.
00059           ACE_Obchunk* tmp = this->new_chunk();
00060           if (!tmp)
00061             return -1;
00062           this->curr_->next_ = tmp;
00063           this->curr_ = this->curr_->next_;
00064         }
00065       else
00066         {
00067           // We can reuse previously allocated memory.
00068           this->curr_ = this->curr_->next_;
00069           this->curr_->block_ = this->curr_->cur_ = this->curr_->contents_;
00070         }
00071 
00072       // Copy any initial characters to the new chunk.
00073       if (temp->cur_ != temp->block_)
00074         {
00075           size_t datasize = temp->cur_ - temp->block_;
00076           ACE_OS::memcpy (this->curr_->block_,
00077                           temp->block_,
00078                           datasize);
00079           this->curr_->cur_ = this->curr_->block_ + datasize;
00080           // Reset the old chunk.
00081           temp->cur_ = temp->block_;
00082         }
00083     }
00084 
00085   return 0;
00086 }

template<class CHAR>
ACE_INLINE size_t ACE_Obstack_T< CHAR >::size void    const
 

Definition at line 10 of file Obstack_T.i.

References size_.

00011 {
00012   return this->size_;
00013 }

template<class CHAR>
void ACE_Obstack_T< CHAR >::unwind void *    obj
 

"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 169 of file Obstack_T.cpp.

References ACE_Obchunk::block_, ACE_Obchunk::contents_, ACE_Obchunk::cur_, curr_, ACE_Obchunk::end_, and unwind_i.

00170 {
00171   if (obj >= this->curr_->contents_ && obj < this->curr_->end_)
00172     this->curr_->block_ = this->curr_->cur_ = ACE_reinterpret_cast (char*,
00173                                                                     obj);
00174   else
00175     this->unwind_i (obj);
00176 }

template<class CHAR>
void ACE_Obstack_T< CHAR >::unwind_i void *    obj [protected]
 

Search through the list of Obchunks and release them. Helper funtion used by unwind.

Definition at line 179 of file Obstack_T.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_Obchunk::block_, ACE_Obchunk::contents_, ACE_Obchunk::cur_, curr_, ACE_Obchunk::end_, head_, LM_ERROR, and ACE_Obchunk::next_.

Referenced by unwind.

00180 {
00181   ACE_Obchunk* curr;
00182 
00183   curr = this->head_;
00184   while (curr != 0 && (curr->contents_ > obj || curr->end_ < obj))
00185       curr = curr->next_;
00186   if (curr)
00187     {
00188       this->curr_ = curr;
00189       this->curr_->block_ = this->curr_->cur_ = ACE_reinterpret_cast (char*,
00190                                                                       obj);
00191     }
00192   else if (obj != 0)
00193     ACE_ERROR ((LM_ERROR,
00194                 ACE_LIB_TEXT ("Deletion of non-existent object.\n%a")));
00195 }


Member Data Documentation

template<class CHAR>
ACE_Obstack_T::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 89 of file Obstack_T.h.

template<class CHAR>
ACE_Allocator* ACE_Obstack_T::allocator_strategy_ [protected]
 

Pointer to the allocator used by this Obstack.

Definition at line 99 of file Obstack_T.h.

Referenced by ACE_Obstack_T, and ~ACE_Obstack_T.

template<class CHAR>
class ACE_Obchunk* ACE_Obstack_T::curr_ [protected]
 

Pointer to the current Obchunk.

Definition at line 109 of file Obstack_T.h.

Referenced by ACE_Obstack_T, copy, freeze, grow, grow_fast, release, request, unwind, and unwind_i.

template<class CHAR>
class ACE_Obchunk* ACE_Obstack_T::head_ [protected]
 

Head of the Obchunk chain.

Definition at line 106 of file Obstack_T.h.

Referenced by ACE_Obstack_T, release, unwind_i, and ~ACE_Obstack_T.

template<class CHAR>
size_t ACE_Obstack_T::size_ [protected]
 

Current size of the Obstack;.

Definition at line 102 of file Obstack_T.h.

Referenced by length, request, and size.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:51:21 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002