1994-08-12 10:52:49 +00:00
# ifndef __ISAM_H
# define __ISAM_H
# ifndef __ARRAY_H
# include <array.h>
# endif
# ifndef __SYSFLD_H
# include <sysfld.h>
# endif
# ifndef FOXPRO
# ifndef __REAL_H
# include <real.h>
# endif
# endif
# ifndef __DATE_H
# include <date.h>
# endif
# ifndef __STRINGS_H
# include <strings.h>
# endif
# ifndef __FILES_H
# include <files.h>
# endif
# ifndef __LFFILES_H
# include <lffiles.h>
# endif
// @M
# define FIELDERR -1
const int MAX_KEYS = 8 ;
// @END
class TBaseisamfile ;
class TExtrectype ;
// @C
// Classe TRectype : public TObject
//
// Tipo record
//
// @END
class TRectype : public TSortable
{
1994-08-22 11:16:25 +00:00
friend class TExtrectype ;
friend class TRecfield ;
friend class TBaseisamfile ;
friend class TLocalisamfile ;
friend class TIsamtempfile ;
// DPRIV
char * _rec ; // Puntatore a inizio record
int _logicnum ; // Numero logico
int _length ; // Lunghezza
isdef * _i ; // Puntatore al file isam
bool _isempty ; // Se il record e' vuoto
// @END
protected :
// FPROT
const char * start ( int nf ) const ;
1994-08-12 10:52:49 +00:00
void setempty ( bool val ) { _isempty = val ; } // Rende vero is_empty
virtual TObject * dup ( ) const ; // Duplica record
1994-08-22 11:16:25 +00:00
virtual int compare ( const TSortable & s ) const ;
// @END
1994-08-12 10:52:49 +00:00
1994-08-22 11:16:25 +00:00
public :
// FPUB
int items ( ) const ;
void setdirty ( ) { setempty ( FALSE ) ; }
1994-08-12 10:52:49 +00:00
char * string ( ) const { return _rec ; } // Ritorna il puntatore all'inizio. NON dovrebbe essere usata!
1994-08-22 11:16:25 +00:00
void discard ( ) { * _rec = char ( _deleted ) ; } // Setta il flag di cancellazione
1994-08-12 10:52:49 +00:00
void recall ( ) { * _rec = char ( _valid ) ; } // Ripristina il flag di cancellazione
bool isdeleted ( ) const { return * _rec = = _deleted ; } // Chiede se e' cancellato
int len ( ) const { return _length ; } // Ritorna la lunghezza
1994-08-22 11:16:25 +00:00
TFieldtypes type ( const char * fieldname ) const ; // Ritorna il tipo del campo
int length ( const char * fieldname ) const ; // Ritorna lunghezza campo
int ndec ( const char * fieldname ) const ; // Ritorna numero di decimali
bool exist ( const char * fieldname ) const ; // Ritorna l'esistenza del campo
const char * fieldname ( int i ) const ; // Ritorna il nome del campo i
// @DES Get tipizzata. Ritorna il contenuto del campo nei vari tipi
// @FPUB
1994-08-12 10:52:49 +00:00
# ifndef FOXPRO
1994-08-22 11:16:25 +00:00
int get_int ( const char * fieldname ) const ;
1994-08-12 10:52:49 +00:00
long get_long ( const char * fieldname ) const ;
word get_word ( const char * fieldname ) const ;
char get_char ( const char * fieldname ) const ;
bool get_bool ( const char * fieldname ) const ;
real get_real ( const char * fieldname ) const ;
# endif
TDate get_date ( const char * fieldname ) const ;
1994-08-22 11:16:25 +00:00
// @DES Get non tipizzata. Il campo e' ritornato come TString&
// @FPUB
1994-08-12 10:52:49 +00:00
const TString & get ( const char * fieldname ) const ;
1994-08-22 11:16:25 +00:00
// @DES Put tipizzata
// @FPUB
1994-08-12 10:52:49 +00:00
# ifndef FOXPRO
void put ( const char * fieldname , int val ) ;
void put ( const char * fieldname , long val ) ;
void put ( const char * fieldname , word val ) ;
void put ( const char * fieldname , const TDate & val ) ;
1994-08-22 11:16:25 +00:00
void put ( const char * fieldname , char val ) ;
void put ( const char * fieldname , bool val ) ;
1994-08-12 10:52:49 +00:00
void put ( const char * fieldname , const real & val ) ;
# endif
1994-08-22 11:16:25 +00:00
// @DES Put NON tipizzata
// @FPUB
void put ( const char * fieldname , const char * val ) ;
// void put(const char* fieldname, TString& val);
1994-08-12 10:52:49 +00:00
1994-08-22 11:16:25 +00:00
void zero ( const char * fieldname ) ; // Vuota campo puntato da fieldname
void zero ( ) ; // Vuota tutto il record
void zero ( char c ) ; // Vuota tutto il record usando il carattere c
1994-08-12 10:52:49 +00:00
1994-08-22 11:16:25 +00:00
TRectype & operator = ( const TRectype & rec ) ; // assegnazione tra TRectype
TRectype & operator = ( const char * rec ) ; // assegnazione tra TRectype
TRectype & operator = ( const TBaseisamfile & f ) ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:16:25 +00:00
const isdef * filehnd ( ) const { return _i ; } // Ritorna il file isam associato
int num ( ) const { return _logicnum ; } // Ritorna il numero logico
bool empty ( ) const { return _isempty ; } // Ritorna se e' vuoto
bool valid ( ) const { return _rec [ 0 ] = = 0 ; } // Ritorna se il record non e'cancellato
const char * key ( int numkey = 1 ) const ; // Ritorna l'espressione della chiave numero numkey
bool ok ( ) const { return _i ! = NULL ; }
1994-08-12 10:52:49 +00:00
1994-08-22 11:16:25 +00:00
TRectype ( int logicnum ) ; // Costruisce un record staccato da un file. Bisogna poi chiamare linkfile(). Sarebbe meglio utilizzare una delle altre due
TRectype ( const TBaseisamfile * i ) ; // Costruisce record e lo associa al file isam i
TRectype ( const TRectype & r ) ; // Costruisce il record a partire da r
1994-08-12 10:52:49 +00:00
1994-08-22 11:16:25 +00:00
virtual ~ TRectype ( ) ;
1994-08-12 10:52:49 +00:00
} ;
// @C
// Classe TBaseisamfile : public TObject
//
// File isam di base
//
// @END
class TBaseisamfile : public TObject
{
1994-08-22 11:16:25 +00:00
// @DPRIV
1994-08-12 10:52:49 +00:00
isdef * _isamfile ; // Descrittore file isam
int _logicnum ; // Numero logico del record corrente
int _lasterr ; // Ultimo errore
bool _delrec ; // Per sapere se rimuovere il record alla fine
bool _delopenrec ; // Per sapere se rimuovere il record alla fine dalla lista interna di record
TRectype * _current ; // Puntatore a record corrente
TFile _hf ;
TFile _hfhd ;
bool _historicfile ; // Vero se il file e' archivio storico
TRecnotype _lasthf ;
TRecnotype _recno ;
1994-08-22 11:16:25 +00:00
friend class TRectype ;
1994-08-12 10:52:49 +00:00
friend class TLocalisamfile ;
friend class TIsamfile ;
friend class TIsamtempfile ;
friend class TRecfield ;
1994-08-22 11:16:25 +00:00
// friend class TCursor;
// @END
// @FPRIV
1994-08-12 10:52:49 +00:00
// friend TRecnotype __buildcursor(TFilecursor* tic, TRecnotype rp);
// friend TRecnotype __filtercursor(TFilecursor* tic);
// friend bool __evalcondition(TBaseisamfile* i,TString& condition);
// friend void __readrec(TFilecursor* tic);
1994-08-22 11:16:25 +00:00
int gethr ( TRectype & rec , TDate & atdate ) ;
1994-08-12 10:52:49 +00:00
int addhr ( const TRectype & rec , TDate & atdate ) ;
int rewhr ( const TRectype & rec , TDate & atdate ) ;
int delhr ( const TRectype & rec , TDate & atdate ) ;
1994-08-22 11:16:25 +00:00
protected :
// @FPROT
1994-08-12 10:52:49 +00:00
isdef * * ptrfilehnd ( ) const { return ( isdef * * ) & _isamfile ; }
void clearfilehnd ( ) { _isamfile = NULL ; }
int _open ( unsigned int mode = _manulock ) ; // Apre isam file con lock
int _close ( ) ;
1994-08-22 11:16:25 +00:00
const char * filename ( ) const ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:16:25 +00:00
public :
// @FPUB
1994-08-12 10:52:49 +00:00
void setkey ( int nkey ) ; // Attiva una chiave
1994-08-22 11:16:25 +00:00
int getkey ( ) const ; // Ritorna la chiave
1994-08-12 10:52:49 +00:00
void setstatus ( int status ) { _lasterr = status ; } // Setta _lasterr
1994-08-22 11:16:25 +00:00
virtual int first ( word lockop = _nolock ) ;
virtual int last ( word lockop = _nolock ) ;
virtual int next ( word lockop = _nolock ) ;
virtual int next ( TDate & atdate ) ;
virtual int prev ( word lockop = _nolock ) ;
virtual int prev ( TDate & atdate ) ;
virtual int reread ( word lockop = _nolock , TDate & atdate = botime ) ;
virtual int reread ( TRectype & rec , word lockop = _nolock , TDate & atdate = botime ) ;
virtual int skip ( TRecnotype nrec , word lockop = _nolock ) ;
virtual int read ( word op = _isequal , word lockop = _nolock , TDate & atdate = botime ) ;
virtual int read ( TRectype & rec , word op = _isequal , word lockop = _nolock , TDate & atdate = botime ) ;
virtual int readat ( TRecnotype nrec , word lockop = _nolock ) ;
virtual int readat ( TRectype & rec , TRecnotype nrec , word lockop = _nolock ) ;
virtual int write ( TDate & atdate = botime ) ;
virtual int write ( const TRectype & rec , TDate & atdate = botime ) ;
virtual int rewrite ( TDate & atdate = botime ) ;
virtual int rewrite ( const TRectype & rec , TDate & atdate = botime ) ;
virtual int rewriteat ( TRecnotype nrec ) ;
virtual int rewriteat ( const TRectype & rec , TRecnotype nrec ) ;
virtual int remove ( TDate & atdate = botime ) ;
virtual int remove ( const TRectype & rec , TDate & atdate = botime ) ;
virtual const char * name ( ) const ;
TRecnotype recno ( ) const { return _recno ; }
int lock ( ) ; // Attiva lock di tutto il file
int unlock ( ) ; // Disattiva lock di tutto il file
void indexon ( ) ; // Accende gli indici
void indexoff ( ) ; // Spegne gli indici
int status ( ) const { return _lasterr ; } // Ritorna _lasterr
TRectype & curr ( ) const { return * _current ; } // Ritorna puntatore a record corrente
bool eof ( ) const { return status ( ) = = _iseof | | status ( ) = = _isemptyfile ; } // Vero se siamo a fine file
bool bof ( ) const { return status ( ) = = _isbof | | status ( ) = = _isemptyfile ; } // Vero se siamo a inizio file
bool good ( ) const { return status ( ) = = NOERR ; } // Vero se _lasterr non contiene codici d'errore
bool bad ( ) const { return status ( ) ! = NOERR ; } // Vero se _lasterr contiene codici d'errore
bool empty ( ) ; // Vero se il file e' vuoto
int num ( ) const { return _logicnum ; } // Ritorna il numero logico del record corrente
TRecnotype eod ( ) const { return filehnd ( ) - > d - > EOD ; }
isdef * filehnd ( ) const { return ( isdef * ) _isamfile ; } // Ritorna l'handle del file isam nella tabella
long items ( ) const ; // n.o di records nel file
// @DES Get tipizzata. Ritorna il contenuto del campo nei vari tipi
// @FPUB
1994-08-12 10:52:49 +00:00
# ifndef FOXPRO
int get_int ( const char * fieldname ) const
1994-08-22 11:16:25 +00:00
{ return curr ( ) . get_int ( fieldname ) ; }
1994-08-12 10:52:49 +00:00
long get_long ( const char * fieldname ) const
1994-08-22 11:16:25 +00:00
{ return curr ( ) . get_long ( fieldname ) ; }
1994-08-12 10:52:49 +00:00
word get_word ( const char * fieldname ) const
1994-08-22 11:16:25 +00:00
{ return curr ( ) . get_word ( fieldname ) ; }
1994-08-12 10:52:49 +00:00
char get_char ( const char * fieldname ) const
1994-08-22 11:16:25 +00:00
{ return curr ( ) . get_char ( fieldname ) ; }
1994-08-12 10:52:49 +00:00
bool get_bool ( const char * fieldname ) const
1994-08-22 11:16:25 +00:00
{ return curr ( ) . get_bool ( fieldname ) ; }
1994-08-12 10:52:49 +00:00
real get_real ( const char * fieldname ) const
1994-08-22 11:16:25 +00:00
{ return curr ( ) . get_real ( fieldname ) ; }
1994-08-12 10:52:49 +00:00
# endif
TDate get_date ( const char * fieldname ) const
1994-08-22 11:16:25 +00:00
{ return curr ( ) . get_date ( fieldname ) ; }
1994-08-12 10:52:49 +00:00
1994-08-22 11:16:25 +00:00
// @DES Get non tipizzata. Il campo e' ritornato come TString&
// @FPUB
1994-08-12 10:52:49 +00:00
const TString & get ( const char * fieldname ) const
1994-08-22 11:16:25 +00:00
{ return curr ( ) . get ( fieldname ) ; }
1994-08-12 10:52:49 +00:00
1994-08-22 11:16:25 +00:00
// @DES Put NON tipizzata
// @FPUB
1994-08-12 10:52:49 +00:00
# ifndef FOXPRO
void put ( const char * fieldname , int val )
1994-08-22 11:16:25 +00:00
{ curr ( ) . put ( fieldname , val ) ; }
1994-08-12 10:52:49 +00:00
void put ( const char * fieldname , long val )
1994-08-22 11:16:25 +00:00
{ curr ( ) . put ( fieldname , val ) ; }
1994-08-12 10:52:49 +00:00
void put ( const char * fieldname , word val )
1994-08-22 11:16:25 +00:00
{ curr ( ) . put ( fieldname , val ) ; }
1994-08-12 10:52:49 +00:00
void put ( const char * fieldname , const TDate & val )
1994-08-22 11:16:25 +00:00
{ curr ( ) . put ( fieldname , val ) ; }
1994-08-12 10:52:49 +00:00
void put ( const char * fieldname , char val )
1994-08-22 11:16:25 +00:00
{ curr ( ) . put ( fieldname , val ) ; }
1994-08-12 10:52:49 +00:00
void put ( const char * fieldname , bool val )
1994-08-22 11:16:25 +00:00
{ curr ( ) . put ( fieldname , val ) ; }
1994-08-12 10:52:49 +00:00
void put ( const char * fieldname , const real & val )
1994-08-22 11:16:25 +00:00
{ curr ( ) . put ( fieldname , val ) ; }
1994-08-12 10:52:49 +00:00
# endif
1994-08-22 11:16:25 +00:00
// @DES Put NON tipizzata
// @FPUB
1994-08-12 10:52:49 +00:00
void put ( const char * fieldname , const char * val )
1994-08-22 11:16:25 +00:00
{ curr ( ) . put ( fieldname , val ) ; }
1994-08-12 10:52:49 +00:00
void zero ( const char * fieldname ) { curr ( ) . zero ( fieldname ) ; }
void zero ( ) { curr ( ) . zero ( ) ; }
void zero ( char c ) { curr ( ) . zero ( c ) ; }
TRectype & operator = ( const TRectype & rec ) { return curr ( ) = rec ; }
TBaseisamfile ( int logicnum , bool linkrecinst = TRUE ) ;
virtual ~ TBaseisamfile ( ) ;
} ;
// @C
// Classe TIsamfile : public TBaseisamfile
//
// File isam
//
// @END
class TIsamfile : public TBaseisamfile
{
1994-08-22 11:16:25 +00:00
public :
// @FPUB
1994-08-12 10:52:49 +00:00
int flags ( bool updateeod = FALSE ) ;
int open ( unsigned int mode = _manulock ) { return _open ( mode ) ; } // Apre isam file con lock
int close ( ) { return _close ( ) ; }
TIsamfile ( int logicnum , bool linkrecinst = TRUE ) ;
virtual ~ TIsamfile ( ) ;
} ;
// @C
// Classe TIsamtempfile : public TBaseisamfile
//
// File isam temporaneo
//
// @END
class TIsamtempfile : public TBaseisamfile
{
1994-08-22 11:16:25 +00:00
public :
// @FPUB
1994-08-12 10:52:49 +00:00
int open ( char * radix , bool create = TRUE , TRecnotype eod = 0 ,
1994-08-22 11:16:25 +00:00
TRecnotype eox = 100 ) ; // Apre il file. radix e' la radice del path del file, se create e' falso vuol dire che il file esiste gia', e allora eod dice quanti record ci sono; eox quanti bisogna aggiungerne
1994-08-12 10:52:49 +00:00
int close ( bool flagdel = TRUE ) ; // Chiude il file e se e' vero flagdel lo cancella
TIsamtempfile ( int logicnum , bool linkrecinst = FALSE ) ;
virtual ~ TIsamtempfile ( ) ;
} ;
// @C
// Classe TSystemisamfile : public TBaseisamfile
//
// @END
class TSystemisamfile : public TIsamfile
{
1994-08-22 11:16:25 +00:00
public :
// @FPUB
1994-08-12 10:52:49 +00:00
int build ( TRecnotype eox ) ; // Costruisce un file isam
int extend ( TRecnotype eox ) ; // Estende un file preesistente
long size ( TRecnotype eox ) ; // Calcola lo spazio che il file occuperebbe se venisse esteso a eox
int update ( TTrec & newrec , bool vis = TRUE ) ;
int packfile ( bool vis = TRUE ) ; // Rimuove fisicamente i record cancellati
int packindex ( bool vis = TRUE ) ; // La stessa cosa sugli indici
1994-08-22 11:16:25 +00:00
// @DES Importa un file ascii. from e' il nome del file da importare
int load ( const char * from , char fs = ' | ' , char fd = ' \0 ' , char rs = ' \n ' , bool vis = TRUE ) ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:16:25 +00:00
// @DES Esporta VERSO un file ascii.
int dump ( const char * to , int nkey = 1 , char fs = ' | ' , char fd = ' \0 ' , char rs = ' \n ' , bool vis = TRUE , bool withdeleted = FALSE ) ;
1994-08-12 10:52:49 +00:00
TSystemisamfile ( int logicnum , bool linkrecinst = TRUE ) ;
virtual ~ TSystemisamfile ( ) ;
} ;
// @C
// Classe TLocalisamfile : public TBaseisamfile
//
// @END
class TLocalisamfile : public TBaseisamfile
{
1994-08-22 11:16:25 +00:00
// @DPRIV
bool _was_open ; // Vero se il file e' stato aperto come Localisamfile
1994-08-12 10:52:49 +00:00
bool _isatab ; // Vero se il file e' una tabella
1994-08-22 11:16:25 +00:00
public :
// @FPUB
1994-08-12 10:52:49 +00:00
virtual int operator + = ( const TRecnotype npos ) ; // Avanza npos record
virtual int operator - = ( const TRecnotype npos ) ; // Sposta indietro di npos
virtual int operator + + ( ) ; // record successivo
virtual int operator - - ( ) ; // record precedente
bool tab ( ) const { return _isatab ; } // Ritorna vero se tabella
void settab ( bool fl = FALSE ) { _isatab = fl ; } // Setta il flag _isatab
int open ( unsigned int mode = _manulock ) ;
int close ( ) ;
1994-08-22 11:16:25 +00:00
// Costruttore. linkrecinst dice se il file deve utilizzare un area record separata oppure la stessa.
1994-08-12 10:52:49 +00:00
TLocalisamfile ( int logicnum , bool linkrecinst = TRUE ) ;
virtual ~ TLocalisamfile ( ) ;
} ;
// @C
// Classe TRec_array : public TArray
//
// @END
class TRec_array : public TArray
{
1994-08-22 11:16:25 +00:00
public :
// @FPUB
1994-08-12 10:52:49 +00:00
TRec_array ( int dimension , TBaseisamfile & i ) ;
} ;
// @C
// Classe TRecfield : public TObject
//
// @END
class TRecfield : public TObject
{
1994-08-22 11:16:25 +00:00
// @DPRIV
1994-08-12 10:52:49 +00:00
char _name [ 12 ] ; // Nome campo
TRectype * _rec ; // Puntatore a inizio record
char * _p ; // Puntatore a inizio campo
byte _len ; // Lunghezza campo
byte _dec ; // Numero di decimali
byte _type ; // Tipo del campo
1994-08-22 11:16:25 +00:00
// @END
1994-08-12 10:52:49 +00:00
1994-08-22 11:16:25 +00:00
// @FPRIV
1994-08-12 10:52:49 +00:00
void set ( int from , int to ) ;
1994-08-22 11:16:25 +00:00
public :
// @FPUB
// @DES Operatore di assegnazione (=) per i vari tipi
// @FPUB
1994-08-12 10:52:49 +00:00
int operator = ( int i ) ;
long operator = ( long l ) ;
const TDate & operator = ( const TDate & d ) ;
const char * operator = ( const char * s ) ;
# ifndef FOXPRO
const real & operator = ( const real & r ) ;
# endif // FOXPRO
1994-08-22 11:16:25 +00:00
// @DES Operatore di estrazione per i vari tipi
// @FPUB
1994-08-12 10:52:49 +00:00
operator int ( ) const ;
operator long ( ) const ;
operator const char * ( ) const ;
operator TDate ( ) const ;
# ifndef FOXPRO
operator const real ( ) const ;
# endif // FOXPRO
void setptr ( TRecnotype r ) ; // Scrive un campo packed. Sarebbe meglio non usare mai campi packed.
TRecnotype ptr ( ) const ; // Legge un campo packed. Sarebbe meglio non usare mai campi packed.
const char * pos ( ) const { return ( const char * ) _p ; } // Ritorna un puntatore all'inizio del campo nel record. Dovrebbe essere protected!
int len ( ) const { return ( int ) _len ; } // Ritorna la lunghezza
int dec ( ) const { return ( int ) _dec ; } // Ritorna il numero di decimali
TFieldtypes type ( ) const { return ( TFieldtypes ) _type ; } // Ritorna il tipo del campo
TRectype & record ( ) const { return * _rec ; } // Ritorna puntatore a inizio record
TRecfield ( TRectype & rec , const char * name , int from = 0 , int to = - 1 ) ;
} ;
// @C
// Classe TTransaction
//
// @END
class TTransaction
{
1994-08-22 11:16:25 +00:00
public :
// @FPUB
1994-08-12 10:52:49 +00:00
void begin ( ) ;
void end ( bool success = TRUE ) ;
void abort ( ) { end ( FALSE ) ; }
} ;
# ifdef __ISAM_CPP
1994-08-22 11:16:25 +00:00
# define extern
1994-08-12 10:52:49 +00:00
# endif
// @DPUB
extern TTransaction transaction ;
extern TRectype * * openrec ;
// @END
# undef extern
# endif // __ISAM_