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

Obstack_T.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 //=============================================================================
00003 /**
00004  *  @file    Obstack_T.h
00005  *
00006  *  $Id: Obstack_T.h,v 1.1.1.2 2003/02/21 18:36:32 chad Exp $
00007  *
00008  *  @author Doug Schmidt <schmidt@cs.wustl.edu> and Nanbor Wang <nanbor@cs.wustl.edu>
00009  */
00010 //=============================================================================
00011 
00012 #ifndef ACE_OBSTACK_T_H
00013 #define ACE_OBSTACK_T_H
00014 #include "ace/pre.h"
00015 
00016 #include "ace/Obchunk.h"
00017 
00018 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00019 # pragma once
00020 #endif /* ACE_LACKS_PRAGMA_ONCE */
00021 
00022 /**
00023  * @class ACE_Obstack
00024  *
00025  * @brief Define a simple "mark and release" memory allocation utility.
00026  *
00027  * The implementation is similar to the GNU obstack utility,
00028  * which is used extensively in the GCC compiler.
00029  */
00030 template <class CHAR>
00031 class ACE_Obstack_T
00032 {
00033 public:
00034   // = Initialization and termination methods.
00035   ACE_Obstack_T (size_t size = (4096 * sizeof (CHAR)) - sizeof (ACE_Obchunk),
00036                  ACE_Allocator *allocator_strategy = 0);
00037   ~ACE_Obstack_T (void);
00038 
00039   /// Request Obstack to prepare a block at least @a len long for building
00040   /// a new string.  Return -1 if fail, 0 if success.
00041   int request (size_t len);
00042 
00043   /// Inserting a new CHAR \a c into the current building
00044   /// block without freezing (null terminating) the block.
00045   /// This function will create new chunk by checking the
00046   /// boundary of current Obchunk.  Return
00047   /// the location \a c gets inserted to, or 0 if error.
00048   CHAR *grow (CHAR c);
00049 
00050   /// Inserting a new CHAR \a c into the current building
00051   /// block without freezing (null terminating) the block and without
00052   /// checking for out-of-bound error.
00053   void grow_fast (CHAR c);
00054 
00055   /// Freeze the current building block by null terminating it.
00056   /// Return the starting address of the current building block, 0
00057   /// if error occurs.
00058   CHAR *freeze (void);
00059 
00060   /// Copy the data into the current Obchunk and freeze the current
00061   /// block.  Return the starting address of the current building
00062   /// block, 0 if error occurs.  @a len specify the string length,
00063   /// not the actually data size.
00064   CHAR *copy (const CHAR *data,
00065               size_t len);
00066 
00067   /// Return the maximum @a length or @a size of a string that can be put
00068   /// into this Obstack. @a size = @a length * sizeof (CHAR).
00069   ///
00070   /// Deprecated : No need to use this function as you can put objects of
00071   /// arbitrary lengths into the obstack now.
00072   size_t length (void) const;
00073   size_t size (void) const;
00074 
00075   /// "Unwind" the stack. If @a obj is a null pointer, everything allocated
00076   /// in the stack is released. Otherwise, @a obj must be an address of an
00077   /// object allocated in the stack. In this case, @a obj is released along
00078   /// with everthing allocated in the Obstack since @a obj.
00079   void unwind (void* obj);
00080 
00081   /// "Release" the entire stack of Obchunks, putting it back on the free
00082   /// list.
00083   void release (void);
00084 
00085   /// Dump the state of an object.
00086   void dump (void) const;
00087 
00088   /// Declare the dynamic allocation hooks.
00089   ACE_ALLOC_HOOK_DECLARE;
00090 
00091 protected:
00092   class ACE_Obchunk *new_chunk (void);
00093 
00094   /// Search through the list of Obchunks and release them. Helper funtion
00095   /// used by unwind.
00096   void unwind_i (void* obj);
00097 
00098   /// Pointer to the allocator used by this Obstack.
00099   ACE_Allocator *allocator_strategy_;
00100 
00101   /// Current size of the Obstack;
00102   size_t size_;
00103 
00104   // Don't change the order of the following two fields.
00105   /// Head of the Obchunk chain.
00106   class ACE_Obchunk *head_;
00107 
00108   /// Pointer to the current Obchunk.
00109   class ACE_Obchunk *curr_;
00110 };
00111 
00112 #if defined (__ACE_INLINE__)
00113 #include "ace/Obstack_T.i"
00114 #endif /* __ACE_INLINE__ */
00115 
00116 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00117 #include "ace/Obstack_T.cpp"
00118 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00119 
00120 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00121 #pragma implementation ("Obstack_T.cpp")
00122 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00123 
00124 #include "ace/post.h"
00125 #endif /* ACE_OBSTACK_T_H */

Generated on Mon Jun 16 11:20:30 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002