From: Ulya Trofimovich Date: Thu, 28 May 2015 17:40:41 +0000 (+0100) Subject: Moved another utility class to a separate file in 'src/util/'. X-Git-Tag: 0.15~233 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=56c5aa37689e8894e4be191d75e8b9604ba0b0af;p=re2c Moved another utility class to a separate file in 'src/util/'. --- diff --git a/re2c/Makefile.am b/re2c/Makefile.am index 6bebdbca..285c0038 100644 --- a/re2c/Makefile.am +++ b/re2c/Makefile.am @@ -64,7 +64,8 @@ SRC_HDR = \ $(srcdir)/src/util/local_increment.h \ $(srcdir)/src/util/range.h \ $(srcdir)/src/util/smart_ptr.h \ - $(srcdir)/src/util/substr.h + $(srcdir)/src/util/substr.h \ + $(srcdir)/src/util/wrap_iterator.h SRC = \ $(SRC_SCANNER) \ diff --git a/re2c/src/codegen/skeleton/skeleton.h b/re2c/src/codegen/skeleton/skeleton.h index f0680410..2f0d7c11 100644 --- a/re2c/src/codegen/skeleton/skeleton.h +++ b/re2c/src/codegen/skeleton/skeleton.h @@ -8,6 +8,7 @@ #include "src/util/c99_stdint.h" #include "src/util/forbid_copy.h" #include "src/util/local_increment.h" +#include "src/util/wrap_iterator.h" namespace re2c { @@ -31,44 +32,12 @@ struct Path void append (const Path * p); }; -template -class wrap_iter_t -{ - container_t & cont; - typename container_t::iterator iter; - bool wrapped; - -public: - wrap_iter_t (container_t & c) - : cont (c) - , iter (cont.begin ()) - , wrapped (false) - {} - bool end () const - { - return wrapped; - } - wrap_iter_t & operator ++ () - { - if (++iter == cont.end ()) - { - iter = cont.begin (); - wrapped = true; - } - return * this; - } - typename container_t::value_type * operator -> () - { - return iter.operator -> (); - } -}; - struct Node { typedef std::map s2n_map; typedef std::map > arcs_t; typedef local_increment_t local_inc; - typedef wrap_iter_t wrap_iter; + typedef wrap_iterator_t wrap_iter; // outgoing arcs arcs_t arcs; diff --git a/re2c/src/util/wrap_iterator.h b/re2c/src/util/wrap_iterator.h new file mode 100644 index 00000000..16166833 --- /dev/null +++ b/re2c/src/util/wrap_iterator.h @@ -0,0 +1,41 @@ +#ifndef __WRAP_ITERATOR__ +#define __WRAP_ITERATOR__ + +namespace re2c +{ + +template +class wrap_iterator_t +{ + container_t & cont; + typename container_t::iterator iter; + bool wrapped; + +public: + wrap_iterator_t (container_t & c) + : cont (c) + , iter (cont.begin ()) + , wrapped (false) + {} + bool end () const + { + return wrapped; + } + wrap_iterator_t & operator ++ () + { + if (++iter == cont.end ()) + { + iter = cont.begin (); + wrapped = true; + } + return * this; + } + typename container_t::value_type * operator -> () + { + return iter.operator -> (); + } +}; + +} // namespace re2c + +#endif // __WRAP_ITERATOR__