// File:       piscmd00.c++
// Version:    1.00
// Author:     (c) Miles Sabin, 1997
// Purpose:    base class for istream commands

// Change log:
//  27/03/97   v. 1.00

#include "piscmds.h"

#include "exception.h"
#include "istream.h"


// Implementation of IStreamCommand

IStreamCommand::~IStreamCommand()
  {}

void IStreamCommand::execute_template(basic_istream_char& is, bool noskipws)
  {
    ios::iostate state = ios::goodbit;

    try
    {
      basic_istream_char_sentry sentry(is, noskipws);
      DESTROY_ON_THROW(sentry);

      if(!sentry)
        state |= ios::failbit;
      else
        state |= execute(is);
    }
    BEGIN_HANDLERS
    catch_DOTS
    {
      is.setstate_no_throw(state|ios::badbit);
      if((is.exceptions()&ios::badbit) != 0)
        rethrow;
    }
    END_HANDLERS

    if(state != ios::goodbit)
      is.setstate(state);
  }

