From 791b91420f06a7a023cfb456b056a33695c0d033 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 3 Mar 2015 00:14:16 +1100 Subject: [PATCH] extent: add indexing operator --- extent.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++--- extent.hpp | 5 +++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/extent.cpp b/extent.cpp index 37ae21ba..810ab828 100644 --- a/extent.cpp +++ b/extent.cpp @@ -90,11 +90,11 @@ util::extent::area (void) const /////////////////////////////////////////////////////////////////////////////// template util::extent -util::extent::expanded (util::vector<2,T> size) const +util::extent::expanded (util::vector<2,T> mag) const { return { - w + size.x, - h + size.y + w + mag.x, + h + mag.y }; } @@ -126,6 +126,45 @@ util::extent::empty (void) const } +/////////////////////////////////////////////////////////////////////////////// +template +T& +util::extent::operator[] (size_t idx) +{ + switch (idx) { + case 0: return w; + case 1: return h; + + default: + unreachable (); + } +} + + +//----------------------------------------------------------------------------- +template +const T& +util::extent::operator[] (size_t idx) const +{ + switch (idx) { + case 0: return w; + case 1: return h; + + default: + unreachable (); + } +} + + +//----------------------------------------------------------------------------- +template +size_t +util::extent::size (void) const +{ + return 2u; +} + + /////////////////////////////////////////////////////////////////////////////// template bool diff --git a/extent.hpp b/extent.hpp index bc6fe503..244ebd2b 100644 --- a/extent.hpp +++ b/extent.hpp @@ -50,6 +50,11 @@ namespace util { bool empty (void) const; + T& operator[] (size_t idx); + const T& operator[] (size_t idx) const; + + size_t size (void) const; + bool operator ==(const extent& rhs) const; bool operator !=(const extent& rhs) const { return !(*this == rhs); }