From fb0ee7f2fc01b4e5720e4f8420175004a79426be Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 24 Jul 2013 23:58:35 -0700 Subject: [PATCH] Improve constness of the Nif RecordPtr structs --- components/nif/recordptr.hpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/components/nif/recordptr.hpp b/components/nif/recordptr.hpp index 2ecde7f60..1a4fc235b 100644 --- a/components/nif/recordptr.hpp +++ b/components/nif/recordptr.hpp @@ -71,16 +71,26 @@ public: } /// Look up the actual object from the index - X* getPtr() const + const X* getPtr() const { assert(ptr != NULL); return ptr; } - X& get() const + X* getPtr() + { + assert(ptr != NULL); + return ptr; + } + + const X& get() const + { return *getPtr(); } + X& get() { return *getPtr(); } /// Syntactic sugar - X* operator->() const + const X* operator->() const + { return getPtr(); } + X* operator->() { return getPtr(); } /// Pointers are allowed to be empty @@ -116,6 +126,8 @@ public: const Ptr& operator[](size_t index) const { return list.at(index); } + Ptr& operator[](size_t index) + { return list.at(index); } size_t length() const { return list.size(); }