Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

BitsetIterator.hpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file
00003  */
00004 //----------------------------------------------------------------------------
00005 
00006 #ifndef BITSET_ITERATOR_HPP
00007 #define BITSET_ITERATOR_HPP
00008 
00009 #include "Benzene.hpp"
00010 #include "Hex.hpp"
00011 #include "SafeBool.hpp"
00012 
00013 _BEGIN_BENZENE_NAMESPACE_
00014 
00015 //----------------------------------------------------------------------------
00016 
00017 /** Iterates over the set bits in a bitset. 
00018     Similar to PointIterator. */
00019 class BitsetIterator : public SafeBool<BitsetIterator>
00020 {
00021 public:
00022 
00023     /** Constructor. */
00024     BitsetIterator(const bitset_t& bs);
00025 
00026     /** Returns the HexPoint at the current location. */
00027     HexPoint operator*();
00028 
00029     /** Moves to the next set point in the bistset. */
00030     void operator++();
00031 
00032     /** Used by SafeBool. */
00033     bool boolean_test() const;
00034 
00035 private:
00036     void find_next_set_bit();
00037 
00038     int m_index;
00039     bitset_t m_bitset;
00040 };
00041 
00042 inline BitsetIterator::BitsetIterator(const bitset_t& bs)
00043     : m_index(0),
00044       m_bitset(bs)
00045 {
00046     find_next_set_bit();
00047 }
00048 
00049 inline void BitsetIterator::find_next_set_bit()
00050 {
00051     while (m_index < FIRST_INVALID && !m_bitset.test(m_index))
00052         ++m_index; 
00053 }
00054 
00055 inline HexPoint BitsetIterator::operator*()
00056 {
00057     return static_cast<HexPoint>(m_index);
00058 }
00059 
00060 inline void BitsetIterator::operator++()
00061 {
00062     ++m_index;
00063     find_next_set_bit();
00064 }
00065         
00066 inline bool BitsetIterator::boolean_test() const
00067 {
00068     return (m_index != FIRST_INVALID);
00069 }
00070 
00071 //----------------------------------------------------------------------------
00072 
00073 _END_BENZENE_NAMESPACE_
00074 
00075 #endif // BITSET_ITERATOR_HPP


6 Jan 2011 Doxygen 1.6.3