Cambiata derivazione dei record-array. L'array di record e' ora contenuta nel record_array
git-svn-id: svn://10.65.10.50/trunk@4486 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
0e6df8119c
commit
432ff18f6b
@ -19,7 +19,7 @@ TRecord_array::TRecord_array(int logicnum, const char* numfield, int first)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TRecord_array::TRecord_array(const TRecord_array& a)
|
TRecord_array::TRecord_array(const TRecord_array& a)
|
||||||
: TArray(a), _file(a._file), _offset(a._offset), _num(a._num)
|
: _data(a._data), _file(a._file), _offset(a._offset), _num(a._num)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
TRecord_array::~TRecord_array()
|
TRecord_array::~TRecord_array()
|
||||||
@ -31,7 +31,7 @@ void TRecord_array::set_key(TRectype* r)
|
|||||||
CHECK(r != NULL, "TRecord_array can't have a null key");
|
CHECK(r != NULL, "TRecord_array can't have a null key");
|
||||||
CHECK(r->num() == _file, "Bad key record");
|
CHECK(r->num() == _file, "Bad key record");
|
||||||
|
|
||||||
add(r, 0); // Setta il nuovo campo chiave
|
_data.add(r, 0); // Setta il nuovo campo chiave
|
||||||
if (rows() > 0)
|
if (rows() > 0)
|
||||||
{
|
{
|
||||||
const RecDes* recd = r->rec_des(); // Descrizione del record della testata
|
const RecDes* recd = r->rec_des(); // Descrizione del record della testata
|
||||||
@ -49,7 +49,7 @@ void TRecord_array::set_key(TRectype* r)
|
|||||||
|
|
||||||
const TRectype& TRecord_array::key() const
|
const TRectype& TRecord_array::key() const
|
||||||
{
|
{
|
||||||
TRectype* r = (TRectype*)objptr(0);
|
TRectype* r = (TRectype*)_data.objptr(0);
|
||||||
CHECK(r, "TRecord_array lost its key");
|
CHECK(r, "TRecord_array lost its key");
|
||||||
return *r;
|
return *r;
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ const TRectype& TRecord_array::key() const
|
|||||||
bool TRecord_array::exist(int n) const
|
bool TRecord_array::exist(int n) const
|
||||||
{
|
{
|
||||||
const int i = n > 0 ? n - _offset : -1;
|
const int i = n > 0 ? n - _offset : -1;
|
||||||
TObject* r = objptr(i);
|
TObject* r = _data.objptr(i);
|
||||||
return r != NULL;
|
return r != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,11 +78,11 @@ TRectype& TRecord_array::row(
|
|||||||
// record copiando la chiave.
|
// record copiando la chiave.
|
||||||
{
|
{
|
||||||
const int i = n >= 0 ? n - _offset : -1;
|
const int i = n >= 0 ? n - _offset : -1;
|
||||||
TRectype* r = (TRectype*)objptr(i);
|
TRectype* r = (TRectype*)_data.objptr(i);
|
||||||
if (r == NULL && create)
|
if (r == NULL && create)
|
||||||
{
|
{
|
||||||
r = (TRectype*)key().dup(); // Crea nuovo record copiando la chiave
|
r = (TRectype*)key().dup(); // Crea nuovo record copiando la chiave
|
||||||
n = add(r, i) + _offset; // Riassegna n se era negativo!
|
n = _data.add(r, i) + _offset; // Riassegna n se era negativo!
|
||||||
char str[16]; sprintf(str, "%d", n);
|
char str[16]; sprintf(str, "%d", n);
|
||||||
r->renum_key(_num, str); // Aggiorna campo numero riga
|
r->renum_key(_num, str); // Aggiorna campo numero riga
|
||||||
}
|
}
|
||||||
@ -109,9 +109,9 @@ bool TRecord_array::renum_key(
|
|||||||
if (curr == num)
|
if (curr == num)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
for (int i = last(); i >= 0; i--)
|
for (int i = _data.last(); i >= 0; i--)
|
||||||
{
|
{
|
||||||
TRectype* r = (TRectype*)objptr(i);
|
TRectype* r = (TRectype*)_data.objptr(i);
|
||||||
if (r != NULL)
|
if (r != NULL)
|
||||||
r->renum_key(field, num);
|
r->renum_key(field, num);
|
||||||
}
|
}
|
||||||
@ -140,10 +140,10 @@ int TRecord_array::insert_row(TRectype* r)
|
|||||||
const int nr = rec2row(*r);
|
const int nr = rec2row(*r);
|
||||||
CHECK(nr > 0, "You cannot insert a new key");
|
CHECK(nr > 0, "You cannot insert a new key");
|
||||||
const bool shift = exist(nr);
|
const bool shift = exist(nr);
|
||||||
insert(r, nr);
|
_data.insert(r, nr);
|
||||||
if (shift)
|
if (shift)
|
||||||
{
|
{
|
||||||
for (int f = last(); f > nr; f = pred(f))
|
for (int f = _data.last(); f > nr; f = _data.pred(f))
|
||||||
{
|
{
|
||||||
char n[16];
|
char n[16];
|
||||||
TRectype & rec = row(f, FALSE);
|
TRectype & rec = row(f, FALSE);
|
||||||
@ -158,7 +158,7 @@ int TRecord_array::insert_row(TRectype* r)
|
|||||||
int TRecord_array::add_row(TRectype* r)
|
int TRecord_array::add_row(TRectype* r)
|
||||||
{
|
{
|
||||||
const int nr = rec2row(*r);
|
const int nr = rec2row(*r);
|
||||||
add(r, nr);
|
_data.add(r, nr);
|
||||||
if (nr == 0 && rows() > 0) // Se ho cambiato il record campione
|
if (nr == 0 && rows() > 0) // Se ho cambiato il record campione
|
||||||
{ // e ci sono altre righe ...
|
{ // e ci sono altre righe ...
|
||||||
for (int f = r->items()-1; f >= 0; f--)
|
for (int f = r->items()-1; f >= 0; f--)
|
||||||
@ -177,11 +177,11 @@ int TRecord_array::add_row(TRectype* r)
|
|||||||
// @mfunc Elimina le righe vuote
|
// @mfunc Elimina le righe vuote
|
||||||
void TRecord_array::pack()
|
void TRecord_array::pack()
|
||||||
{
|
{
|
||||||
TArray::pack();
|
_data.pack();
|
||||||
|
|
||||||
for (int i = size()-1; i > 0; i--)
|
for (int i = _data.size()-1; i > 0; i--)
|
||||||
{
|
{
|
||||||
TRectype* r = (TRectype*)objptr(i);
|
TRectype* r = (TRectype*)_data.objptr(i);
|
||||||
if (r != NULL)
|
if (r != NULL)
|
||||||
{
|
{
|
||||||
TString16 n; n << i+_offset;
|
TString16 n; n << i+_offset;
|
||||||
@ -207,13 +207,13 @@ bool TRecord_array::destroy_row(
|
|||||||
{
|
{
|
||||||
CHECKD(r > _offset, "Can't destroy row ", r);
|
CHECKD(r > _offset, "Can't destroy row ", r);
|
||||||
const int index = r - _offset;
|
const int index = r - _offset;
|
||||||
const bool ok = destroy(index, pack);
|
const bool ok = _data.destroy(index, pack);
|
||||||
|
|
||||||
if (ok && pack)
|
if (ok && pack)
|
||||||
{
|
{
|
||||||
for (int i = size()-1; i >= index; i--)
|
for (int i = _data.size()-1; i >= index; i--)
|
||||||
{
|
{
|
||||||
TRectype* r = (TRectype*)objptr(i);
|
TRectype* r = (TRectype*)_data.objptr(i);
|
||||||
if (r != NULL)
|
if (r != NULL)
|
||||||
{
|
{
|
||||||
TString16 n; n << i+_offset;
|
TString16 n; n << i+_offset;
|
||||||
@ -226,8 +226,8 @@ bool TRecord_array::destroy_row(
|
|||||||
|
|
||||||
void TRecord_array::destroy_rows()
|
void TRecord_array::destroy_rows()
|
||||||
{
|
{
|
||||||
for (int i = last(); i > 0; i = pred(i))
|
for (int i = _data.last(); i > 0; i = _data.pred(i))
|
||||||
destroy(i);
|
_data.destroy(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @doc EXTERNAL
|
// @doc EXTERNAL
|
||||||
@ -250,7 +250,7 @@ int TRecord_array::read(TRectype* filter)
|
|||||||
CHECKD(filter->num() == _file, "Bad key record ", filter->num());
|
CHECKD(filter->num() == _file, "Bad key record ", filter->num());
|
||||||
CHECKS(filter->get(_num).empty(), "You can't specify in the filter the field ", (const char*)_num);
|
CHECKS(filter->get(_num).empty(), "You can't specify in the filter the field ", (const char*)_num);
|
||||||
|
|
||||||
destroy();
|
_data.destroy();
|
||||||
int err = NOERR;
|
int err = NOERR;
|
||||||
if (filter != NULL && !filter->empty())
|
if (filter != NULL && !filter->empty())
|
||||||
{
|
{
|
||||||
@ -310,10 +310,10 @@ int TRecord_array::write(bool re) const
|
|||||||
int err = NOERR;
|
int err = NOERR;
|
||||||
|
|
||||||
TLocalisamfile f(_file);
|
TLocalisamfile f(_file);
|
||||||
const int u = last();
|
const int u = _data.last();
|
||||||
for (int i = 1; i <= u; i++)
|
for (int i = 1; i <= u; i++)
|
||||||
{
|
{
|
||||||
const TRectype* r = (TRectype*)objptr(i);
|
const TRectype* r = (TRectype*)_data.objptr(i);
|
||||||
|
|
||||||
if (r != NULL)
|
if (r != NULL)
|
||||||
{
|
{
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
// @class TRecord_array | Classe per la gestione di un array di record
|
// @class TRecord_array | Classe per la gestione di un array di record
|
||||||
//
|
//
|
||||||
// @base public | TArray
|
// @base public | TArray
|
||||||
class TRecord_array : private TArray
|
class TRecord_array : public TObject
|
||||||
|
|
||||||
// @author:(INTERNAL) Guido
|
// @author:(INTERNAL) Guido
|
||||||
|
|
||||||
@ -26,6 +26,8 @@ class TRecord_array : private TArray
|
|||||||
{
|
{
|
||||||
// @cmember:(INTERNAL) Numero logico del file principale
|
// @cmember:(INTERNAL) Numero logico del file principale
|
||||||
int _file;
|
int _file;
|
||||||
|
// @cmember:(INTERNAL) Array di records
|
||||||
|
TArray _data;
|
||||||
// @cmember:(INTERNAL) Offset iniziale del record array
|
// @cmember:(INTERNAL) Offset iniziale del record array
|
||||||
int _offset;
|
int _offset;
|
||||||
// @cmember:(INTERNAL) Nome del campo col numero di riga
|
// @cmember:(INTERNAL) Nome del campo col numero di riga
|
||||||
@ -49,17 +51,17 @@ public:
|
|||||||
const TRectype& key() const;
|
const TRectype& key() const;
|
||||||
// @cmember Ritorna il numero di righe presenti
|
// @cmember Ritorna il numero di righe presenti
|
||||||
int rows() const
|
int rows() const
|
||||||
{ return items()-1; }
|
{ return _data.items()-1; }
|
||||||
|
|
||||||
// @cmember Ritorna la riga successiva non vuota a partire da <p r>
|
// @cmember Ritorna la riga successiva non vuota a partire da <p r>
|
||||||
int succ_row(int r) const
|
int succ_row(int r) const
|
||||||
{ return succ(r - _offset) + _offset; }
|
{ return _data.succ(r - _offset) + _offset; }
|
||||||
// @cmember Ritorna la riga precedente non vuota a partire da <p r>
|
// @cmember Ritorna la riga precedente non vuota a partire da <p r>
|
||||||
int pred_row(int r) const
|
int pred_row(int r) const
|
||||||
{ return pred(r - _offset) + _offset; };
|
{ return _data.pred(r - _offset) + _offset; };
|
||||||
// @cmember Ritorna l'ultma riga non vuota
|
// @cmember Ritorna l'ultma riga non vuota
|
||||||
int last_row() const
|
int last_row() const
|
||||||
{ return last() + _offset; }
|
{ return _data.last() + _offset; }
|
||||||
// @cmember Ritorna la prima riga non vuota
|
// @cmember Ritorna la prima riga non vuota
|
||||||
int first_row() const
|
int first_row() const
|
||||||
{ return succ_row(0); }
|
{ return succ_row(0); }
|
||||||
@ -72,6 +74,10 @@ public:
|
|||||||
bool exist(int r) const;
|
bool exist(int r) const;
|
||||||
// @cmember Ritorna la riga <p r>-esima; se tale riga non esiste e se <p create> assume il valore TRUE la riga viene creata
|
// @cmember Ritorna la riga <p r>-esima; se tale riga non esiste e se <p create> assume il valore TRUE la riga viene creata
|
||||||
TRectype& row(int r, bool create);
|
TRectype& row(int r, bool create);
|
||||||
|
// @cmember Ritorna la riga <p r>-esima se tale riga esiste
|
||||||
|
const TRectype& operator [](int r) const { return (const TRectype &) ((TRecord_array *) this)->row(r, FALSE);}
|
||||||
|
// @cmember Ritorna la riga <p r>-esima se tale riga esiste
|
||||||
|
TRectype& operator [](int r) { return row(r, FALSE);}
|
||||||
|
|
||||||
// @cmember Inserisce una riga alla posizione indicata nel record, sposta gli altri elementi se la posizione era gia' occupata
|
// @cmember Inserisce una riga alla posizione indicata nel record, sposta gli altri elementi se la posizione era gia' occupata
|
||||||
virtual int insert_row(TRectype* r);
|
virtual int insert_row(TRectype* r);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user