122 lines
3.7 KiB
C++
Executable File
122 lines
3.7 KiB
C++
Executable File
//
|
|
// EX13CON.CPP
|
|
//
|
|
// C++/DOS Example program for ArchiveLib 2.0
|
|
//
|
|
// Copyright (c) Greenleaf Software, Inc. 1994 - 1996
|
|
// All Rights Reserved
|
|
//
|
|
// MEMBERS/FUNCTIONS DEMONSTRATED
|
|
//
|
|
// ALMemory::ALMemory()
|
|
//
|
|
// DESCRIPTION
|
|
//
|
|
// This example program shows how you can create a derived class and
|
|
// use ALStorage::YieldTime() to monitor for abort conditions. In
|
|
// this case all it takes is a new class with two functions: a ctor
|
|
// and a new version of YieldTime(). You can't do this without
|
|
// writing C++ code, sorry VB and C programmers. But the C++ is
|
|
// pretty easy, it wouldn't be hard to drop a module like this into
|
|
// your C program.
|
|
//
|
|
// REVISION HISTORY
|
|
//
|
|
// February 1, 1996 2.0A : Second release
|
|
//
|
|
|
|
#include <iostream.h>
|
|
#include <iomanip.h>
|
|
#include <conio.h>
|
|
|
|
#include "arclib.h"
|
|
#include "pkarc.h"
|
|
#include "glarc.h"
|
|
#include "bargraph.h"
|
|
#include "memstore.h"
|
|
|
|
//
|
|
// This derived class has to have a constructor, but it gets the base
|
|
// class ctor to do all the work for. The YieldTime() function is
|
|
// where the real work takes place. Everything else is done by
|
|
// ALMemory, so we get off light here.
|
|
//
|
|
|
|
#if defined( HUGE )
|
|
class AL_CLASS_TYPE MyFile : public ALHugeMemory {
|
|
public :
|
|
AL_PROTO MyFile( const char *name ) : ALHugeMemory( name ){;}
|
|
#else
|
|
class AL_CLASS_TYPE MyFile : public ALMemory {
|
|
public :
|
|
AL_INLINE_PROTO MyFile( const char *name ) : ALMemory( name ){;}
|
|
#endif
|
|
virtual void AL_PROTO YieldTime();
|
|
virtual AL_INLINE_PROTO ~MyFile(){;}
|
|
//
|
|
// Normally you wouldn't care about defining these, but I had some
|
|
// troubles with gcc when I didn't.
|
|
//
|
|
protected :
|
|
AL_PROTO MyFile( const MyFile AL_DLL_FAR & );
|
|
MyFile AL_DLL_FAR & AL_PROTO operator=( const MyFile AL_DLL_FAR & );
|
|
|
|
};
|
|
|
|
//
|
|
// ALStorage::YieldTime() actually does some worthwhile work, so we
|
|
// have to be sure to call it. All we do here in addition to that is
|
|
// check for a keyboard hit. If we see one, we set the error status on
|
|
// this so that the archiving function will abort.
|
|
//
|
|
void AL_PROTO MyFile::YieldTime()
|
|
{
|
|
if ( kbhit() ) {
|
|
getch();
|
|
mStatus.SetError( AL_USER_ABORT, "User hit abort key..." );
|
|
}
|
|
#if defined( HUGE )
|
|
ALHugeMemory::YieldTime();
|
|
#else
|
|
ALMemory::YieldTime();
|
|
#endif
|
|
}
|
|
|
|
//
|
|
// The main() function here is a lot like EX00CON.CPP. The main difference
|
|
// is that we are archiving to a memory object instead of a disk object.
|
|
// The only reason for that is so we make less clutter.
|
|
//
|
|
|
|
main( int, char *[] )
|
|
{
|
|
cout << "Archive Library 2.0\nEX13CON.CPP\n\n";
|
|
cout << "This example program shows how you can create a derived class and\n";
|
|
cout << "use ALStorage::YieldTime() to monitor for abort conditions. In\n";
|
|
cout << "this case all it takes is a new class with two functions: a ctor\n";
|
|
cout << "and a new version of YieldTime(). You can't do this without\n";
|
|
cout << "writing C++ code, sorry VB and C programmers. But the C++ is\n";
|
|
cout << "pretty easy, it wouldn't be hard to drop a module like this into\n";
|
|
cout << "your C program.\n\n";
|
|
getch();
|
|
|
|
cout << "\nAdding input*.dat and *.bak to a MyFile object"
|
|
<< " using an ALBarGraph\n"
|
|
<< "Hit any key to abort...\n\n";
|
|
|
|
MyFile archive_file( "Memory based archive" );
|
|
#if defined( ZIP )
|
|
ALPkArchive archive( archive_file );
|
|
#else
|
|
ALGlArchive archive( archive_file );
|
|
#endif
|
|
ALBarGraph monitor( AL_MONITOR_OBJECTS, cout );
|
|
|
|
ALEntryList list( &monitor );
|
|
|
|
list.AddWildCardFiles( "input*.dat, *.bak" );
|
|
archive.Create( list );
|
|
cout << "\n" << archive.mStatus << "\n";
|
|
return archive.mStatus;
|
|
}
|