Aggiunti metodi dup

git-svn-id: svn://10.65.10.50/trunk@3365 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
alex 1996-08-09 13:44:22 +00:00
parent 8657d05879
commit db174ab6f9
2 changed files with 85 additions and 5 deletions

View File

@ -131,6 +131,14 @@ TDir::TDir () : _num(-1), _com(FALSE)
zero (); zero ();
} }
TDir::TDir(const TDir & d)
{
_dir = new FileDes;
*_dir = *d._dir;
_num = d._num;
_com = d._com;
}
TDir::~TDir () TDir::~TDir ()
{ {
delete _dir; delete _dir;
@ -143,7 +151,7 @@ const char *TDir::name () const
const char *TDir::filename () const const char *TDir::filename () const
{ {
strcpy(_files_tmp_string, _dir->SysName); strcpy(_files_tmp_string, CAddPref(_dir->SysName));
strcat(_files_tmp_string, ".dbf"); strcat(_files_tmp_string, ".dbf");
return _files_tmp_string; return _files_tmp_string;
} }
@ -204,7 +212,7 @@ TRecnotype & TDir::flags () const
return _dir->Flags; return _dir->Flags;
} }
word & TDir::len () word & TDir::len () const
{ {
return (word &) _dir->LenR; return (word &) _dir->LenR;
@ -306,6 +314,13 @@ TTrec::TTrec ()
_num = -1; _num = -1;
} }
TTrec::TTrec(const TTrec & r)
{
_rec = new RecDes;
*_rec = *r._rec;
_num = r._num;
}
TTrec::~TTrec () TTrec::~TTrec ()
{ {
@ -321,7 +336,43 @@ int TTrec::compare(const TSortable & a) const
void TTrec::rehash() void TTrec::rehash()
{ {
setrdes (_rec); int pos, tmppos, nf, i;
for (i = 0; i < MaxFields; i++) _rec->SortFd[i] = INVFLD;
if (_rec->NFields)
{
for (i = 0; i < _rec->NFields; i++)
{
nf = i;
pos = hashfun(_rec->Fd[nf].Name);
while (TRUE)
{
if (_rec->SortFd[pos] == INVFLD)
{
_rec->SortFd[pos] = (byte) nf;
break;
}
else
{
if (strcmp(_rec->Fd[_rec->SortFd[pos]].Name, _rec->Fd[nf].Name) <= 0)
{
pos++;
if (pos >= MaxFields)
pos = 0;
}
else
{
tmppos = _rec->SortFd[pos];
_rec->SortFd[pos] = (byte) nf;
nf = tmppos;
}
}
}
}
_rec->Fd[0].RecOff = 1;
for (i = 1; i < _rec->NFields; i++)
_rec->Fd[i].RecOff = _rec->Fd[i - 1].RecOff + _rec->Fd[i - 1].Len;
}
} }
TTrec & TTrec::operator = (const TTrec & b) TTrec & TTrec::operator = (const TTrec & b)
@ -363,7 +414,28 @@ void TTrec::put (
void TTrec::zero () void TTrec::zero ()
{ {
zerordes (_rec); _rec->NFields = 0;
for (int i = 0; i < MaxFields; i++)
{
strcpy(_rec->Fd[i].Name, "");
_rec->Fd[i].TypeF = _nullfld;
_rec->Fd[i].Len = 0;
_rec->Fd[i].Dec = 0;
_rec->Fd[i].RecOff = 0;
_rec->SortFd[i] = INVFLD;
}
_rec->NKeys = 0;
for (i = 1; i < MaxKeys; i++)
{
_rec->Ky[i].DupKeys = FALSE;
_rec->Ky[i].NkFields = 0;
for (int j = 0; j < MKFields; j++)
{
_rec->Ky[i].FieldSeq[j] = INVFLD;
_rec->Ky[i].FromCh[j] = INVFLD;
_rec->Ky[i].ToCh[j] = INVFLD;
}
}
} }
int TTrec::status (TDirtype dirop) const int TTrec::status (TDirtype dirop) const

View File

@ -135,7 +135,7 @@ public:
// @cmember Ritorna il flag del file selezionato // @cmember Ritorna il flag del file selezionato
TRecnotype& flags() const; TRecnotype& flags() const;
// @cmember Ritorna la lunghezza del tracciato record in bytes // @cmember Ritorna la lunghezza del tracciato record in bytes
word& len(); word& len() const;
// @cmember Ritorna lo stato d'errore del file // @cmember Ritorna lo stato d'errore del file
int status(TDirtype dirtype = _nordir) const ; int status(TDirtype dirtype = _nordir) const ;
// @cmember Ritorna il numero di file presenti // @cmember Ritorna il numero di file presenti
@ -161,7 +161,11 @@ public:
// @cmember Controlla se il file e' attivato dalla chiave hardware. // @cmember Controlla se il file e' attivato dalla chiave hardware.
// Valido solo se prefhnd e settato a "" // Valido solo se prefhnd e settato a ""
bool is_active() const; bool is_active() const;
// @cmember Duplica il tracciato record
virtual TObject* dup() const { return new TDir(*this);}
// @cmember Costruttore
TDir(const TDir & d);
// @cmember Costruttore // @cmember Costruttore
TDir(); TDir();
// @cmember Distruttore // @cmember Distruttore
@ -248,7 +252,11 @@ public:
virtual void read_from(istream& in); virtual void read_from(istream& in);
void set_des(TConfig* c = NULL, const char* tab = "") { _des = c; _tab = tab;} void set_des(TConfig* c = NULL, const char* tab = "") { _des = c; _tab = tab;}
#endif #endif
// @cmember Duplica il descrittore di file
virtual TObject* dup() const { return new TTrec(*this);}
// @cmember Costruttore
TTrec(const TTrec & r);
// @cmember Costruttore // @cmember Costruttore
TTrec(); TTrec();
// @cmember Distruttore // @cmember Distruttore