aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-09-15 13:41:40 +0000
committerlloyd <[email protected]>2010-09-15 13:41:40 +0000
commita9d0f37596e5413cae45f32740738c5c68abcce1 (patch)
treecde74396fe8234f491a4bd6465390758586b5280 /src
parent522d73aff8a321c96ba3cb1fe0ab7ffef1e15fab (diff)
Remove all versions of MemoryRegion::append.
Add a push_back that takes a single argument ala std::vector For appending, provide some namespace level += operators - we can use this technique with either MemoryRegion or a std::vector.
Diffstat (limited to 'src')
-rw-r--r--src/alloc/secmem.h62
1 files changed, 43 insertions, 19 deletions
diff --git a/src/alloc/secmem.h b/src/alloc/secmem.h
index e92efe9a0..5c8bd377b 100644
--- a/src/alloc/secmem.h
+++ b/src/alloc/secmem.h
@@ -149,29 +149,13 @@ class MemoryRegion
void set(const T in[], u32bit n) { resize(n); copy(in, n); }
/**
- * Append data to the end of this buffer.
- * @param data the array containing the data to append
- * @param n the size of the array data
- */
- void append(const T data[], u32bit n)
- {
- resize(size()+n);
- copy_mem(buf + size() - n, data, n);
- }
-
- /**
* Append a single element.
* @param x the element to append
*/
- void append(T x) { append(&x, 1); }
-
- /**
- * Append data to the end of this buffer.
- * @param other the buffer containing the data to append
- */
- void append(const MemoryRegion<T>& other)
+ void push_back(T x)
{
- append(&other[0], other.size());
+ resize(size() + 1);
+ buf[size()-1] = x;
}
/**
@@ -375,6 +359,46 @@ class SecureVector : public MemoryRegion<T>
}
};
+template<typename T>
+MemoryRegion<T>& operator+=(MemoryRegion<T>& out,
+ const MemoryRegion<T>& in)
+ {
+ const u32bit copy_offset = out.size();
+ out.resize(out.size() + in.size());
+ copy_mem(&out[copy_offset], &in[0], in.size());
+ return out;
+ }
+
+template<typename T>
+MemoryRegion<T>& operator+=(MemoryRegion<T>& out,
+ T in)
+ {
+ const u32bit copy_offset = out.size();
+ out.resize(out.size() + 1);
+ copy_mem(&out[copy_offset], &in, 1);
+ return out;
+ }
+
+template<typename T, typename L>
+MemoryRegion<T>& operator+=(MemoryRegion<T>& out,
+ const std::pair<const T*, L>& in)
+ {
+ const u32bit copy_offset = out.size();
+ out.resize(out.size() + in.second);
+ copy_mem(&out[copy_offset], in.first, in.second);
+ return out;
+ }
+
+template<typename T, typename L>
+MemoryRegion<T>& operator+=(MemoryRegion<T>& out,
+ const std::pair<T*, L>& in)
+ {
+ const u32bit copy_offset = out.size();
+ out.resize(out.size() + in.second);
+ copy_mem(&out[copy_offset], in.first, in.second);
+ return out;
+ }
+
/**
* Zeroise the values; length remains unchanged
* @param vec the vector to zeroise