3 //=============================================================================
7 * @author Doug Schmidt <d.schmidt@vanderbilt.edu>
8 * @author Nanbor Wang <nanbor@cs.wustl.edu>
10 //=============================================================================
12 #ifndef ACE_OBSTACK_T_H
13 #define ACE_OBSTACK_T_H
15 #include /**/ "ace/pre.h"
17 #include "ace/Obchunk.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
28 * @class ACE_Obstack_T
30 * @brief Define a simple "mark and release" memory allocation utility.
32 * The implementation is similar to the GNU obstack utility,
33 * which is used extensively in the GCC compiler.
35 template <class ACE_CHAR_T
>
39 ACE_Obstack_T (size_t size
= (4096 * sizeof (ACE_CHAR_T
)) - sizeof (ACE_Obchunk
),
40 ACE_Allocator
*allocator_strategy
= 0);
43 /// Request Obstack to prepare a block at least @a len long for building
44 /// a new string. Return -1 if fail, 0 if success.
45 int request (size_t len
);
47 /// Inserting a new ACE_CHAR_T \a c into the current building block
48 /// without freezing (null terminating) the block. This function
49 /// will create new chunk by checking the boundary of current
50 /// Obchunk. Return the location \a c gets inserted to, or 0 if
52 ACE_CHAR_T
*grow (ACE_CHAR_T c
);
54 /// Inserting a new ACE_CHAR_T \a c into the current building
55 /// block without freezing (null terminating) the block and without
56 /// checking for out-of-bound error.
57 void grow_fast (ACE_CHAR_T c
);
59 /// Freeze the current building block by null terminating it.
60 /// Return the starting address of the current building block, 0
62 ACE_CHAR_T
*freeze ();
64 /// Copy the data into the current Obchunk and freeze the current
65 /// block. Return the starting address of the current building
66 /// block, 0 if error occurs. @a len specify the string length,
67 /// not the actually data size.
68 ACE_CHAR_T
*copy (const ACE_CHAR_T
*data
,
71 /// Return the maximum @a size
74 /// "Unwind" the stack. If @a obj is a null pointer, everything allocated
75 /// in the stack is released. Otherwise, @a obj must be an address of an
76 /// object allocated in the stack. In this case, @a obj is released along
77 /// with everything allocated in the Obstack since @a obj.
78 void unwind (void *obj
);
80 /// "Release" the entire stack of Obchunks, putting it back on the free
84 /// Dump the state of an object.
87 /// Declare the dynamic allocation hooks.
88 ACE_ALLOC_HOOK_DECLARE
;
91 class ACE_Obchunk
*new_chunk ();
93 /// Search through the list of Obchunks and release them. Helper function
95 void unwind_i (void *obj
);
97 /// Pointer to the allocator used by this Obstack.
98 ACE_Allocator
*allocator_strategy_
;
100 /// Current size of the Obstack;
103 // Don't change the order of the following two fields.
104 /// Head of the Obchunk chain.
105 class ACE_Obchunk
*head_
;
107 /// Pointer to the current Obchunk.
108 class ACE_Obchunk
*curr_
;
111 ACE_END_VERSIONED_NAMESPACE_DECL
113 #if defined (__ACE_INLINE__)
114 #include "ace/Obstack_T.inl"
115 #endif /* __ACE_INLINE__ */
117 #include "ace/Obstack_T.cpp"
119 #include /**/ "ace/post.h"
120 #endif /* ACE_OBSTACK_T_H */