summaryrefslogtreecommitdiff
path: root/ace/Obstack.cpp
diff options
context:
space:
mode:
authorlevine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1996-10-21 21:41:34 +0000
committerlevine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1996-10-21 21:41:34 +0000
commita5fdebc5f6375078ec1763850a4ca23ec7fe6458 (patch)
treebcf0a25c3d45a209a6e3ac37b233a4812f29c732 /ace/Obstack.cpp
downloadATCD-a5fdebc5f6375078ec1763850a4ca23ec7fe6458.tar.gz
Initial revision
Diffstat (limited to 'ace/Obstack.cpp')
-rw-r--r--ace/Obstack.cpp119
1 files changed, 119 insertions, 0 deletions
diff --git a/ace/Obstack.cpp b/ace/Obstack.cpp
new file mode 100644
index 00000000000..5bd969201bb
--- /dev/null
+++ b/ace/Obstack.cpp
@@ -0,0 +1,119 @@
+// Obstack.cpp
+// $Id$
+
+#define ACE_BUILD_DLL
+#include "ace/Obstack.h"
+
+ACE_ALLOC_HOOK_DEFINE(ACE_Obstack)
+
+void
+ACE_Obstack::dump (void) const
+{
+ ACE_TRACE ("ACE_Obstack::dump");
+
+ ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
+ ACE_DEBUG ((LM_DEBUG, "size_ = %d\n", this->size_));
+ ACE_DEBUG ((LM_DEBUG, "head_ = %x\n", this->head_));
+ ACE_DEBUG ((LM_DEBUG, "curr_ = %x\n", this->curr_));
+ ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
+}
+
+ACE_ALLOC_HOOK_DEFINE(ACE_Obchunk)
+
+void
+ACE_Obchunk::dump (void) const
+{
+ ACE_TRACE ("ACE_Obchunk::dump");
+
+ ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
+ ACE_DEBUG ((LM_DEBUG, "end_ = %x\n", this->end_));
+ ACE_DEBUG ((LM_DEBUG, "cur_ = %x\n", this->cur_));
+ ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
+}
+
+class ACE_Obchunk *
+ACE_Obstack::new_chunk (void)
+{
+ ACE_TRACE ("ACE_Obstack::new_chunk");
+ class ACE_Obchunk *temp = (class ACE_Obchunk *)
+ new char[sizeof (class ACE_Obchunk) + this->size_];
+
+ if (temp == 0)
+ {
+ errno = ENOMEM;
+ return 0;
+ }
+
+ temp->next_ = 0;
+ temp->end_ = temp->contents_ + this->size_;
+ temp->cur_ = temp->contents_;
+
+ return temp;
+}
+
+ACE_Obstack::ACE_Obstack (int sz)
+ : size_ (sz),
+ head_ (0)
+{
+ ACE_TRACE ("ACE_Obstack::ACE_Obstack");
+ this->head_ = this->new_chunk ();
+ this->curr_ = this->head_;
+}
+
+ACE_Obstack::~ACE_Obstack (void)
+{
+ ACE_TRACE ("ACE_Obstack::~ACE_Obstack");
+ class ACE_Obchunk *temp = this->head_;
+
+ while (temp != 0)
+ {
+ class ACE_Obchunk *next = temp->next_;
+ temp->next_ = 0;
+ delete [] temp;
+ temp = next;
+ }
+}
+
+char *
+ACE_Obstack::copy (const char *s,
+ size_t len)
+{
+ ACE_TRACE ("ACE_Obstack::copy");
+ char *result;
+
+ ACE_ASSERT (this->size_ >= len + 1);
+
+ // Check whether we need to grow our chunk...
+
+ if (this->curr_->cur_ + len + 1 >= this->curr_->end_)
+ {
+ // Check whether we can just reuse previously allocated memory.
+
+ if (this->curr_->next_ == 0)
+ {
+ this->curr_->next_ = this->new_chunk ();
+ this->curr_ = this->curr_->next_;
+ }
+ else
+ {
+ this->curr_ = this->curr_->next_;
+ this->curr_->cur_ = this->curr_->contents_;
+ }
+ }
+
+ result = this->curr_->cur_;
+ ACE_OS::memcpy (result, s, len);
+ result[len] = '\0';
+ this->curr_->cur_ += (len + 1);
+ return result;
+}
+
+void
+ACE_Obstack::release (void)
+{
+ ACE_TRACE ("ACE_Obstack::release");
+ this->curr_ = this->head_;
+ this->curr_->cur_ = this->curr_->contents_;
+}
+
+