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

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

#include "piscmds.h"

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


// Implementation of SeekposCommand

IStreamSeekposCommand::IStreamSeekposCommand(basic_istream_char& is, int sp, ios::openmode which)
  : sp_(sp),
    which_(which)
  { execute_template(is, true); }

IStreamSeekposCommand::~IStreamSeekposCommand()
  {}

ios::iostate IStreamSeekposCommand::execute(basic_istream_char& is)
  {
    result_ = is.rdbuf()->pubseekpos(sp_, which_);
    return ios::goodbit;
  }


// Implementation of basic_istream_char

basic_istream_char& basic_istream_char::seekg(int pos)
  {
    if(fail())
      return *this;

    IStreamSeekposCommand cmd(*this, pos);
    return *this;
  }
