/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project. All
................................................ contributions are welcome.
....Copyright(C).1995.Melvin.Smith.............. Enjoy.
------------------------------------------------------------------------------
Melvin Smith (aka Fusion) msmith@falcon.mercer.peachnet.edu
MUD++ development mailing list mudpp-list@spice.com
------------------------------------------------------------------------------
persistent.h
*/
#ifndef _PERSISTENT_H
#define _PERSISTENT_H
#include "io.h"
#include "string.h"
// Any object that can write or read itself to and from a stream
class Streamable
{
public:
virtual ~Streamable() {}
// Interface for all 'Streamable' objects
// Child classes must implement all pure virtual
// functions and fulfill the requirement of a 'Streamable'
virtual int readFrom( InFile & ) = 0;
virtual int readFrom( const String & filename );
virtual int writeTo( OutFile & ) const = 0;
virtual int writeTo( const String & filename ) const;
virtual int readProtoFrom( InFile & ) = 0;
virtual int readProtoFrom( const String & filename );
virtual int writeProtoTo( OutFile & ) const = 0;
virtual int writeProtoTo( const String & filename ) const;
};
// Invoke virtual readFrom( InFile ) of child class.
inline int Streamable::readFrom( const String & filename )
{
InFile in( filename.chars() );
return readFrom( in );
}
// Invoke virtual writeTo( OutFile ) of child class.
inline int Streamable::writeTo( const String & filename ) const
{
OutFile out( filename.chars() );
return writeTo( out );
}
// Invoke virtual readProtoFrom( InFile ) of child class.
inline int Streamable::readProtoFrom( const String & filename )
{
InFile in( filename.chars() );
return readProtoFrom( in );
}
// Invoke virtual writeProtoTo( OutFile ) of child class.
inline int Streamable::writeProtoTo( const String & filename ) const
{
OutFile out( filename.chars() );
return writeProtoTo( out );
}
#endif