Module: sems Branch: master Commit: 6a105aa09f7464cf0e6c231d3946c29696c811b4 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=6a105aa09f7464cf0e6c231d3946c29696c811b4
Author: Stefan Sayer <[email protected]> Committer: Stefan Sayer <[email protected]> Date: Thu Sep 29 14:20:16 2011 +0200 adds AmArg::back() to access last element of array --- core/AmArg.cpp | 20 ++++++++++++++++++-- core/AmArg.h | 6 ++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/core/AmArg.cpp b/core/AmArg.cpp index 1940f21..2590c2d 100644 --- a/core/AmArg.cpp +++ b/core/AmArg.cpp @@ -230,8 +230,24 @@ const size_t AmArg::size() const { throw TypeMismatchException(); } -AmArg& AmArg::get(size_t idx) { +AmArg& AmArg::back() { assertArray(); + if (!v_array->size()) + throw OutOfBoundsException(); + + return (*v_array)[v_array->size()-1]; +} + +AmArg& AmArg::back() const { + assertArray(); + if (!v_array->size()) + throw OutOfBoundsException(); + + return (*v_array)[v_array->size()-1]; +} + +AmArg& AmArg::get(size_t idx) { + assertArray(); if (idx >= v_array->size()) throw OutOfBoundsException(); @@ -239,7 +255,7 @@ AmArg& AmArg::get(size_t idx) { } AmArg& AmArg::get(size_t idx) const { - assertArray(); + assertArray(); if (idx >= v_array->size()) throw OutOfBoundsException(); diff --git a/core/AmArg.h b/core/AmArg.h index 6d6a410..6225b07 100644 --- a/core/AmArg.h +++ b/core/AmArg.h @@ -285,6 +285,12 @@ class AmArg /** throws OutOfBoundsException if array too small */ AmArg& get(size_t idx) const; + /** throws OutOfBoundsException if array too small */ + AmArg& back(); + + /** throws OutOfBoundsException if array too small */ + AmArg& back() const; + /** resizes array if too small */ AmArg& operator[](size_t idx); /** throws OutOfBoundsException if array too small */ _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
