#include "worditer.h"

// implementation of WordStreamIterator class
// Owen Astrachan 7/3/95, 4/9/99

WordStreamIterator::WordStreamIterator()
    : myWord(""),
      myMore(false)
// postcondition: iterator is initialized, HasMore() == false
{
    // initializer list does the work
}

void WordStreamIterator::Open(const string & name)
// postcondition: myInput open, bound to name
{
    myInput.open(name.c_str());
}

void WordStreamIterator::Init()
// postcondition: first word read from stream myInput
{
    myInput.clear();         // clear error flags
    myInput.seekg(0);        // back to beginning
    myMore =  (myInput >> myWord);
}

string WordStreamIterator::Current()
// postcondition: returns current word     
{
    return myWord;
}

bool WordStreamIterator::HasMore()
// postcondition: returns true if more words to read    
{
    return myMore;
}

void WordStreamIterator::Next()
// precondition: HasMore()     
// postcondition: next word from stream myInput read     
{
    if (HasMore())
    {   myMore = (myInput >> myWord);
    }
}
