Slide 5.16: Program buffer demonstrations
Slide 5.18: Book.h
Home

Buffer.cpp


The file Buffer.cpp is the main function of the C++ program for the previous interface. This program performs the following tasks:
  1. Fills an input buffer with input records.
  2. Prints the contents of the input buffer.
  3. Puts each record into a Book object.
  4. Prints out the object's title.
  5. Moves the disk get pointer to the end of the last-read record.
  6. Goes to the Step 1 if an End-of-File is not reached. Otherwise, closes the input file and exits.
~wenchen/public_html/cgi-bin/351/week5/Buffer.cpp

#include  <fstream>
#include  <iostream>
#include  <cstring>
  using namespace  std;

#include  "TextBuffer.h"
#include  "Constructor.h"
#include  "Clear.h"
#include  "Read.h"
#include  "Unpack.h"
#include  "Book.h"

int  main( int argc, char* argv[ ] ) {
  fstream    file; 
  int        size;
  streampos  pos = 0; 
  Book       b;
 
  size = atoi( argv[1] );
  TextBuffer  buffer( size );
  file.open( "inventory.xml", fstream::in );
  while ( true ) {
    if ( ( size=buffer.Read( file ) ) == 0 )  break;
    buffer.Put( );
    while ( b.Unpack( buffer ) )
      cout << "Title = " << b.PrintTitle( ) << endl << endl << endl;
    pos += size;
    file.seekg( pos );
  }
  file.close( );
}