summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2012-11-16 13:57:51 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-11-16 13:57:51 -0800
commit843fdc303f9cafff2b77fa927c183d64e59fa1d8 (patch)
tree5fffa3f5dd328823a91b61600004f9c30f36d148
parenta4cbc2b0cf0f6fbdb21e84a3e17585eda1885e3e (diff)
parent2c7206e7e19c23fdaa2dd5843f0597624a5e7341 (diff)
downloadrs-843fdc303f9cafff2b77fa927c183d64e59fa1d8.tar.gz
Merge "Add FieldPacker to C++ reflected API."
-rw-r--r--cpp/rsCppStructs.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/cpp/rsCppStructs.h b/cpp/rsCppStructs.h
index ee3ebb15..f1376b0a 100644
--- a/cpp/rsCppStructs.h
+++ b/cpp/rsCppStructs.h
@@ -384,6 +384,73 @@ private:
size_t mVectorSize;
};
+class FieldPacker {
+protected:
+ unsigned char* mData;
+ size_t mPos;
+ size_t mLen;
+
+public:
+ FieldPacker(size_t len)
+ : mPos(0),
+ mLen(len) {
+ mData = new unsigned char[len];
+ }
+
+ virtual ~FieldPacker() {
+ delete [] mData;
+ }
+
+ void align(size_t v) {
+ if ((v & (v - 1)) != 0) {
+ ALOGE("Non-power-of-two alignment: %zu", v);
+ return;
+ }
+
+ while ((mPos & (v - 1)) != 0) {
+ mData[mPos++] = 0;
+ }
+ }
+
+ void reset() {
+ mPos = 0;
+ }
+
+ void reset(size_t i) {
+ if (i >= mLen) {
+ ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen);
+ return;
+ }
+ mPos = i;
+ }
+
+ void skip(size_t i) {
+ size_t res = mPos + i;
+ if (res > mLen) {
+ ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen);
+ return;
+ }
+ mPos = res;
+ }
+
+ void* getData() const {
+ return mData;
+ }
+
+ size_t getLength() const {
+ return mLen;
+ }
+
+ template <typename T>
+ void add(T t) {
+ align(sizeof(t));
+ if (mPos + sizeof(t) <= mLen) {
+ memcpy(&mData[mPos], &t, sizeof(t));
+ mPos += sizeof(t);
+ }
+ }
+};
+
class Type : public BaseObj {
protected:
friend class Allocation;