1
0
mirror of https://git.savannah.gnu.org/git/gperf.git synced 2025-12-02 21:19:24 +00:00

Rework positions handling.

This commit is contained in:
Bruno Haible
2002-12-09 12:35:55 +00:00
parent d776b8df65
commit 5090f380e3
6 changed files with 197 additions and 121 deletions

View File

@@ -21,11 +21,14 @@
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* ---------------------------- Class Positions ---------------------------- */
/* Constructors. */
INLINE
Positions::Positions ()
: _size (0)
{
_positions[0] = PositionIterator::EOS;
}
INLINE
@@ -33,7 +36,6 @@ Positions::Positions (int key1)
: _size (1)
{
_positions[0] = key1;
_positions[1] = PositionIterator::EOS;
}
INLINE
@@ -42,9 +44,10 @@ Positions::Positions (int key1, int key2)
{
_positions[0] = key1;
_positions[1] = key2;
_positions[2] = PositionIterator::EOS;
}
/* Accessors. */
INLINE int
Positions::operator[] (unsigned int index) const
{
@@ -57,6 +60,8 @@ Positions::get_size () const
return _size;
}
/* Write access. */
INLINE unsigned char *
Positions::pointer ()
{
@@ -94,6 +99,9 @@ Positions::sort ()
return duplicate_free;
}
/* ------------------------- Class PositionIterator ------------------------ */
/* Initializes an iterator through POSITIONS. */
INLINE
PositionIterator::PositionIterator (Positions const& positions)
: _set (positions),
@@ -101,12 +109,15 @@ PositionIterator::PositionIterator (Positions const& positions)
{
}
/* Retrieves the next position, or EOS past the end. */
INLINE int
PositionIterator::next ()
{
return _set._positions[_index++];
return (_index < _set._size ? _set._positions[_index++] : EOS);
}
/* ----------------------------- Class Options ----------------------------- */
/* Tests a given boolean option. Returns true if set, false otherwise. */
INLINE bool
Options::operator[] (Option_Type option) const