POV-Ray : Newsgroups : povray.programming : pov_io_base question : pov_io_base question Server Time
21 Jul 2024 06:29:37 EDT (-0400)
  pov_io_base question  
From: ABX
Date: 7 Oct 2002 04:36:10
Message: <nih2quouobesergu3qtvmmithvvjskjfr2@4ax.com>
Working on MPEG port I found useful to perform buffered reading: allocate
buffer and read fixed number of bytes there. The problem appear when there is
less bytes to read than specified. I have to know how much was readed. I
thought it could be useful to introduce below changes for it but since I'm not
very experienced with OOP rules and IO operations I thought I could discuss it
first. I have introduced private field 'transfered' with number of bytes
transfered to/from file and public method to get this value. I have also
changed content of read and write with reversed order of number of blocks and
size of block (I have to measure in bytes). I want to know if I do it correct
way. Perhaps direction of last transfer could be additionaly stored in sign of
transfer field. So here are my changes...

// file_pov.h

class pov_io_base
{
  public:
    ....
    inline u_int32 lasttransfer (void) { return (transfer) ; }

  protected:
    ....
    u_int32 transfer;
} ;

// file_pov.cpp

pov_io_base::pov_io_base (u_int32 dir, u_int32 type)
{
    ....
    transfer = 0;
}

pov_io_base& pov_io_base::read (void *buffer, u_int32 count)
{
  if (!fail && count > 0)
  {
    transfer = fread (buffer, 1, count, f);
    fail = ( transfer > count ) ;
  }
  else
    transfer = 0;

  return (*this) ;
}

pov_io_base& pov_io_base::write (void *buffer, u_int32 count)
{
  if (!fail && count > 0)
  {
    transfer = fwrite (buffer, 1, count, f);
    fail = ( transfer > count ) ;
  }
  else
    transfer = 0;

  return (*this) ;
}

ABX


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.