// File:       piscmd10.c++
// Version:    1.00
// Author:     (c) Miles Sabin, 1997
// Purpose:    putback command

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

#include "piscmds.h"

#include "istream.h"
#include "streambuf.h"


// Implementation of PutbackCommand

PutbackCommand::PutbackCommand(basic_istream_char& is, char c)
  : c_(c)
  { execute_template(is, true); }

PutbackCommand::~PutbackCommand()
  {}

ios::iostate PutbackCommand::execute(basic_istream_char& is)
  {
    basic_streambuf_char* sb = is.rdbuf();
    return ((sb == 0 || sb->sputbackc(c_) == basic_istream_char::traits::eof()) ? ios::badbit : ios::goodbit);
  }


// Implementation of basic_istream_char

basic_istream_char& basic_istream_char::putback(char c)
  {
    gcount_ = 0;
    PutbackCommand cmd(*this, c);
    return *this;
  }

