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

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

#include "piscmds.h"

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


// Implementation of IStreamSeekoffCommand

IStreamSeekoffCommand::IStreamSeekoffCommand(basic_istream_char& is, int off, ios::seekdir way, ios::openmode which)
  : off_(off),
    way_(way),
    which_(which)
  { execute_template(is, true); }

IStreamSeekoffCommand::~IStreamSeekoffCommand()
  {}

ios::iostate IStreamSeekoffCommand::execute(basic_istream_char& is)
  {
    result_ = is.rdbuf()->pubseekoff(off_, way_, which_);
    return ios::goodbit;
  }


// Implementation of basic_istream_char

int basic_istream_char::tellg()
  {
    if(fail())
      return -1;

    IStreamSeekoffCommand cmd(*this, 0, cur, in);
    return cmd.as_int();
  }

basic_istream_char& basic_istream_char::seekg(int off, seekdir dir)
  {
    if(fail())
      return *this;

    IStreamSeekoffCommand cmd(*this, off, dir);
    return *this;
  }
