From efe0aeed5f1854628df8bace645a072d569fe7b9 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 10 Dec 2016 15:39:39 +0100 Subject: Introduce `BoxIndicator` and `BoxTraverser` helper classes `BoxIndicator` implements an indicator function for the world area. Together with `BoxTraverser` it is used to simplifiy action validation and area traversion. --- src/box_traverser.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/box_traverser.h (limited to 'src/box_traverser.h') diff --git a/src/box_traverser.h b/src/box_traverser.h new file mode 100644 index 0000000..1bc0edd --- /dev/null +++ b/src/box_traverser.h @@ -0,0 +1,26 @@ +#ifndef LIFE_SRC_BOX_TRAVERSER_ +#define LIFE_SRC_BOX_TRAVERSER_ + +#include + +#include "box_indicator.h" + +namespace life { +namespace util { + +struct BoxTraverser : public BoxIndicator { + using BoxIndicator::BoxIndicator; + + void for_each(const std::function f) const { + for ( std::size_t x = this->a_x_; x < this->b_x_; x++ ) { + for ( std::size_t y = this->a_y_; y < this->b_y_; y++ ) { + f(x, y); + } + } + } +}; + +} +} + +#endif // LIFE_SRC_BOX_TRAVERSER_ -- cgit v1.2.3