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

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

#include "piscmds.h"

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


// Implementation of ReadCommand

ReadCommand::ReadCommand(basic_istream_char& is, char* s, streamsize n)
  : s_(s),
    n_(n),
    gcount_(0)
  { execute_template(is, true); }

ReadCommand::~ReadCommand()
  {}

ios::iostate ReadCommand::execute(basic_istream_char& is)
  { return ((gcount_ = is.rdbuf()->sgetn(s_, n_)) != n_ ? ios::failbit : ios::goodbit); }


// Implementation of basic_istream_char

basic_istream_char& basic_istream_char::read(char* s, streamsize n)
  {
    gcount_ = 0;

    ReadCommand cmd(*this, s, n);
    gcount_ = cmd.gcount();
    if(gcount_ != n)
      setstate(failbit);

    return *this;
  }
