diff options
author | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-06-16 06:11:50 +0000 |
---|---|---|
committer | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-06-16 06:11:50 +0000 |
commit | f13fb6fd227d1bf21cbef7542c487271a178a77c (patch) | |
tree | a8a1702f38fe1c6d77a8b2eb46711bfb89917074 /crawl-ref/source/stuff.h | |
parent | aca7f0db12247aae824668b0aeea4f2dd47f8be4 (diff) | |
download | crawl-ref-f13fb6fd227d1bf21cbef7542c487271a178a77c.tar.gz crawl-ref-f13fb6fd227d1bf21cbef7542c487271a178a77c.zip |
Finally implemented stack_iterator(), a way to iterate over objects in
a stack without all that o = mitm[o].link stuff. Redid Ely's destroy
weapons power to use it.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5875 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/stuff.h')
-rw-r--r-- | crawl-ref/source/stuff.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h index 66e492c7ca..3bb0221fca 100644 --- a/crawl-ref/source/stuff.h +++ b/crawl-ref/source/stuff.h @@ -48,6 +48,27 @@ int roll_dice( int num, int size ); int roll_dice( const struct dice_def &dice ); void scale_dice( dice_def &dice, int threshold = 24 ); +// stack_iterator guarantees validity so long as you don't manually +// mess with item_def.link: i.e., you can kill the item you're +// examining but you can't kill the item linked to it. +class stack_iterator : public std::iterator<std::forward_iterator_tag, + item_def> +{ +public: + stack_iterator( const coord_def& pos ); + stack_iterator( int start_link ); + + operator bool() const; + item_def& operator *() const; + int link() const; + + const stack_iterator& operator ++ (); + stack_iterator operator ++ (int); +private: + int cur_link; + int next_link; +}; + class radius_iterator : public std::iterator<std::bidirectional_iterator_tag, coord_def> { |