Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Obstack_T.h
blob27d08d37976dd8ef71a4e3e5a9c304d04a32643e
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Obstack_T.h
7 * @author Doug Schmidt <d.schmidt@vanderbilt.edu>
8 * @author Nanbor Wang <nanbor@cs.wustl.edu>
9 */
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)
20 # pragma once
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
25 class ACE_Allocator;
27 /**
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>
36 class ACE_Obstack_T
38 public:
39 ACE_Obstack_T (size_t size = (4096 * sizeof (ACE_CHAR_T)) - sizeof (ACE_Obchunk),
40 ACE_Allocator *allocator_strategy = 0);
41 ~ACE_Obstack_T ();
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
51 /// error.
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
61 /// if error occurs.
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,
69 size_t len);
71 /// Return the maximum @a size
72 size_t size () const;
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
81 /// list.
82 void release ();
84 /// Dump the state of an object.
85 void dump () const;
87 /// Declare the dynamic allocation hooks.
88 ACE_ALLOC_HOOK_DECLARE;
90 protected:
91 class ACE_Obchunk *new_chunk ();
93 /// Search through the list of Obchunks and release them. Helper function
94 /// used by unwind.
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;
101 size_t size_;
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 */