package SimpleDB::Base;
# $Id: Base.pm,v 1.1.1.1 2000/01/25 17:00:58 tom Exp $
################################################################

=head1 NAME

SimpleDB::Base - 簡易データベース基本クラス

=head1 DESCRIPTION

派生することを前提。
tie に用いる。

=cut

################################################################

use strict;

sub new ($$$)
{
    my ($class, $filename, $readonly, $no_autoflush) = @_;
    my $self = {filename=>$filename,
		readonly=>$readonly,
		no_autoflush=>$no_autoflush,
		modified=>0, 'read'=>0};
    bless $self, $class;
}

sub FETCH
{
    my $self = shift;
#    print "fetching\n";
    $self->Read
	unless $self->{'read'};
    $self->{'read'} = 1;
}
sub STORE
{
    my $self = shift;
    if ($self->{readonly}){
	die "Read only";
    }
    $self->Read()
	unless $self->{'read'};
    $self->{'read'} = 1;
    $self->{modified} = 1;
}
# セーブする必要がなければ真を返す
sub DESTROY
{
#    print "desctoying\n";
    my $self = shift;
    if ($self->{readonly} || !$self->{modified} || $self->{no_autoflush}){
	return 1;
    } else {
	return 0;
    }
}
################################################################
# すでに読んでいたら真を返す
sub Read($)
{
#    print "reading\n";
    my $self = shift;
    if ($self->{'read'}){
	return 1;
    } else {
	$self->{'read'} = 1;
	return 0;
    }
}
1;

