aboutsummaryrefslogtreecommitdiff
path: root/libxsd/xsd/cxx/tree
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-01-08 17:01:08 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-01-08 17:01:08 +0200
commite6d52ecfa2379b1f7f3007e65ded5e4076abc5e9 (patch)
tree70258beb5308c1ec041daea08d41aa745741a0c6 /libxsd/xsd/cxx/tree
parent3f8c237b1abe02df8147170f2fc037edc3f384db (diff)
Add support in buffer class for reusing existing buffer without freeing it
Diffstat (limited to 'libxsd/xsd/cxx/tree')
-rw-r--r--libxsd/xsd/cxx/tree/buffer.hxx9
-rw-r--r--libxsd/xsd/cxx/tree/buffer.txx24
-rw-r--r--libxsd/xsd/cxx/tree/types.hxx8
3 files changed, 18 insertions, 23 deletions
diff --git a/libxsd/xsd/cxx/tree/buffer.hxx b/libxsd/xsd/cxx/tree/buffer.hxx
index 45a1a82..24da287 100644
--- a/libxsd/xsd/cxx/tree/buffer.hxx
+++ b/libxsd/xsd/cxx/tree/buffer.hxx
@@ -45,12 +45,12 @@ namespace xsd
virtual
~buffer_base ()
{
- if (data_)
+ if (free_ && data_)
operator delete (data_);
}
buffer_base ()
- : data_ (0), size_ (0), capacity_ (0)
+ : data_ (0), size_ (0), capacity_ (0), free_ (true)
{
}
@@ -58,6 +58,7 @@ namespace xsd
char* data_;
size_t size_;
size_t capacity_;
+ bool free_;
};
//@endcond
@@ -138,13 +139,13 @@ namespace xsd
buffer (const void* data, size_t size, size_t capacity);
/**
- * @brief Assume ownership of the specified %buffer.
+ * @brief Reuse an existing %buffer.
*
* If the @a assume_ownership argument is true, the %buffer will
* assume ownership of @a data and will release the memory
* by calling @c operator @c delete().
*
- * @param data A %buffer to assume ownership of.
+ * @param data A %buffer to reuse.
* @param size A %buffer size in bytes.
* @param capacity A %buffer capacity in bytes.
* @param assume_ownership A boolean value indication whether to
diff --git a/libxsd/xsd/cxx/tree/buffer.txx b/libxsd/xsd/cxx/tree/buffer.txx
index ab11f40..f88f140 100644
--- a/libxsd/xsd/cxx/tree/buffer.txx
+++ b/libxsd/xsd/cxx/tree/buffer.txx
@@ -60,20 +60,10 @@ namespace xsd
if (size > capacity)
throw bounds<C> ();
- if (own)
- {
- data_ = reinterpret_cast<char*> (data);
- size_ = size;
- capacity_ = capacity;
- }
- else
- {
- this->capacity (capacity);
- size_ = size;
-
- if (size_)
- std::memcpy (data_, data, size_);
- }
+ data_ = reinterpret_cast<char*> (data);
+ size_ = size;
+ capacity_ = capacity;
+ free_ = own;
}
template <typename C>
@@ -111,14 +101,17 @@ namespace xsd
char* tmp_data (data_);
size_t tmp_size (size_);
size_t tmp_capacity (capacity_);
+ bool tmp_free (free_);
data_ = other.data_;
size_ = other.size_;
capacity_ = other.capacity_;
+ free_ = other.free_;
other.data_ = tmp_data;
other.size_ = tmp_size;
other.capacity_ = tmp_capacity;
+ other.free_ = tmp_free;
}
template <typename C>
@@ -139,11 +132,12 @@ namespace xsd
if (copy && size_ > 0)
std::memcpy (data, data_, size_);
- if (data_)
+ if (free_ && data_)
operator delete (data_);
data_ = data;
capacity_ = capacity;
+ free_ = true;
return true;
}
diff --git a/libxsd/xsd/cxx/tree/types.hxx b/libxsd/xsd/cxx/tree/types.hxx
index 2ef5c09..e6dc5a4 100644
--- a/libxsd/xsd/cxx/tree/types.hxx
+++ b/libxsd/xsd/cxx/tree/types.hxx
@@ -3098,13 +3098,13 @@ namespace xsd
base64_binary (const void* data, size_t size, size_t capacity);
/**
- * @brief Assume ownership of the specified %buffer.
+ * @brief Reuse an existing %buffer.
*
* If the @a assume_ownership argument is true, the %buffer will
* assume ownership of @a data and will release the memory
* by calling @c operator @c delete().
*
- * @param data A %buffer to assume ownership of.
+ * @param data A %buffer to reuse.
* @param size A %buffer size in bytes.
* @param capacity A %buffer capacity in bytes.
* @param assume_ownership A boolean value indication whether to
@@ -3294,13 +3294,13 @@ namespace xsd
hex_binary (const void* data, size_t size, size_t capacity);
/**
- * @brief Assume ownership of the specified %buffer.
+ * @brief Reuse an existing %buffer..
*
* If the @a assume_ownership argument is true, the %buffer will
* assume ownership of @a data and will release the memory
* by calling @c operator @c delete().
*
- * @param data A %buffer to assume ownership of.
+ * @param data A %buffer to reuse.
* @param size A %buffer size in bytes.
* @param capacity A %buffer capacity in bytes.
* @param assume_ownership A boolean value indication whether to