aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-05-18 13:58:23 +0000
committerlloyd <[email protected]>2012-05-18 13:58:23 +0000
commit2c3dc93d6466a9215d585613fb55f5222ce70d10 (patch)
tree9d44c738fdbb79103bed2d34c8fb171f8eaa00a2 /src/alloc
parentc2d0d2982e96ab7ce15e90b8d73c9774e2650d86 (diff)
First step towards replacing the existing containers with std::vector
with a custom allocator; remove the 3 argument version of MemoryRegion::copy, replacing with freestanding buffer_insert function.
Diffstat (limited to 'src/alloc')
-rw-r--r--src/alloc/secmem.h36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/alloc/secmem.h b/src/alloc/secmem.h
index 884f2ebc0..e6b2b71ec 100644
--- a/src/alloc/secmem.h
+++ b/src/alloc/secmem.h
@@ -117,23 +117,16 @@ class MemoryRegion
* @param in the array to copy the contents from
* @param n the length of in
*/
+
void copy(const T in[], size_t n)
{
copy_mem(buf, in, std::min(n, size()));
}
- /**
- * Copy the contents of an array of objects of type T into this buffer.
- * The former contents of *this are discarded.
- * The length of *this must be at least n, otherwise memory errors occur.
- * @param off the offset position inside this buffer to start inserting
- * the copied bytes
- * @param in the array to copy the contents from
- * @param n the length of in
- */
- void copy(size_t off, const T in[], size_t n)
+ void assign(const T* start, const T* end)
{
- copy_mem(buf + off, in, std::min(n, size() - off));
+ resize(end - start);
+ copy_mem(buf, start, (end - start));
}
/**
@@ -370,6 +363,27 @@ class SecureVector : public MemoryRegion<T>
};
template<typename T>
+size_t buffer_insert(MemoryRegion<T>& buf,
+ size_t buf_offset,
+ const T input[],
+ size_t input_length)
+ {
+ const size_t to_copy = std::min(input_length, buf.size() - buf_offset);
+ copy_mem(&buf[buf_offset], input, to_copy);
+ return to_copy;
+ }
+
+template<typename T>
+size_t buffer_insert(MemoryRegion<T>& buf,
+ size_t buf_offset,
+ const MemoryRegion<T>& input)
+ {
+ const size_t to_copy = std::min(input.size(), buf.size() - buf_offset);
+ copy_mem(&buf[buf_offset], &input[0], to_copy);
+ return to_copy;
+ }
+
+template<typename T>
MemoryRegion<T>& operator+=(MemoryRegion<T>& out,
const MemoryRegion<T>& in)
{