Aggiunto first nei record array

git-svn-id: svn://10.65.10.50/trunk@1259 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
alex 1995-04-18 11:03:46 +00:00
parent 311aeca7f1
commit 56b49e4991
2 changed files with 28 additions and 23 deletions

View File

@ -1,4 +1,4 @@
// $Id: relation.cpp,v 1.36 1995-04-18 08:40:52 guy Exp $ // $Id: relation.cpp,v 1.37 1995-04-18 11:03:40 alex Exp $
// relation.cpp // relation.cpp
// fv 12/8/93 // fv 12/8/93
// relation class for isam files // relation class for isam files
@ -1308,14 +1308,14 @@ int TFieldref::len(TRectype &rec) const
// TRecord_Array // TRecord_Array
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
TRecord_array::TRecord_array(const TRectype& r, const char* numfield) TRecord_array::TRecord_array(const TRectype& r, const char* numfield, int first)
: _file(r.num()), _num(numfield) : _file(r.num()), _num(numfield), _offset(first - 1)
{ {
read(r); read(r);
} }
TRecord_array::TRecord_array(int logicnum, const char* numfield) TRecord_array::TRecord_array(int logicnum, const char* numfield, int first)
: _file(logicnum), _num(numfield) : _file(logicnum), _num(numfield), _offset(first - 1)
{} {}
const TRectype& TRecord_array::key() const const TRectype& TRecord_array::key() const
@ -1327,13 +1327,14 @@ const TRectype& TRecord_array::key() const
TRectype& TRecord_array::row(int n, bool create) TRectype& TRecord_array::row(int n, bool create)
{ {
TRectype* r = (TRectype*)objptr(n); const int i = n > 0 ? n - _offset : -1;
TRectype* r = (TRectype*)objptr(i);
if (r == NULL && create) if (r == NULL && create)
{ {
r = new TRectype(key()); r = new TRectype(key());
n = add(r, n); // Riassegna n se era negativo! n = add(r, i) + _offset; // Riassegna n se era negativo!
r->put(_num, n); // Aggiorna campo numero riga r->put(_num, n); // Aggiorna campo numero riga
} }
CHECKD(r && n > 0, "Bad record number ", n); CHECKD(r && n > 0, "Bad record number ", n);
return *r; return *r;
@ -1375,8 +1376,8 @@ bool TRecord_array::renum_key(const char* field, long num)
int TRecord_array::rec2row(const TRectype& r) const int TRecord_array::rec2row(const TRectype& r) const
{ {
CHECK(r == key(), "Incompatible record"); CHECK(r == key(), "Incompatible record");
const int n = atoi(r.get(_num)); // Non e' detto che sia un int! const int n = atoi(r.get(_num)) - _offset; // Non e' detto che sia un int!
CHECKD(n > 0 && n < 32000, "Bad line number in record ", n); CHECKD(n > 0 && n < 32000, "Bad line number in record ", n + _offset);
return n; return n;
} }
@ -1391,12 +1392,14 @@ int TRecord_array::add_row(const TRectype& r)
bool TRecord_array::destroy_row(int r, bool pack) bool TRecord_array::destroy_row(int r, bool pack)
{ {
CHECKD(r > 0, "Can't destroy row ", r); CHECKD(r > _offset, "Can't destroy row ", r);
const bool ok = destroy(r, pack); const int index = r - _offset;
const bool ok = destroy(index, pack);
if (ok && pack) if (ok && pack)
{ {
for (int i = r; i < items(); i++) for (int i = index; i < items(); i++)
row(i, FALSE).put(_num, i); row(i + _offset, FALSE).put(_num, i + _offset);
} }
return ok; return ok;
} }
@ -1404,7 +1407,7 @@ bool TRecord_array::destroy_row(int r, bool pack)
void TRecord_array::destroy_rows() void TRecord_array::destroy_rows()
{ {
for (int i = last(); i > 0; i--) for (int i = last(); i > 0; i--)
destroy_row(i); destroy(i);
} }
int TRecord_array::read(const TRectype& filter) int TRecord_array::read(const TRectype& filter)
@ -1445,7 +1448,7 @@ int TRecord_array::write(bool re)
} }
else else
{ {
f.curr() = key(); f.put(_num, i); f.curr() = key(); f.put(_num, i + _offset);
err = f.read(); err = f.read();
if (err == NOERR) // La riga c'era ma ora non piu' if (err == NOERR) // La riga c'era ma ora non piu'
{ {
@ -1459,7 +1462,7 @@ int TRecord_array::write(bool re)
if (err == NOERR) if (err == NOERR)
{ {
// Cancella eventuali residui successivi // Cancella eventuali residui successivi
f.curr() = key(); f.put(_num, i); f.curr() = key(); f.put(_num, i + _offset);
for (int e = f.read(_isgteq); e == NOERR && f.curr() == key(); e = f.next()) for (int e = f.read(_isgteq); e == NOERR && f.curr() == key(); e = f.next())
{ {
err = f.remove(); err = f.remove();

View File

@ -1,4 +1,4 @@
/* $Id: relation.h,v 1.15 1995-04-18 08:40:18 guy Exp $ */ /* $Id: relation.h,v 1.16 1995-04-18 11:03:46 alex Exp $ */
// join.h // join.h
// fv 12/8/93 // fv 12/8/93
// join class for isam files // join class for isam files
@ -149,6 +149,7 @@ public:
class TRecord_array : private TArray class TRecord_array : private TArray
{ {
int _file; // Numero logico del file principale int _file; // Numero logico del file principale
int _offset; // Offset iniziale del record array
TString16 _num; // Nome del campo col numero di riga TString16 _num; // Nome del campo col numero di riga
private: private:
@ -157,10 +158,11 @@ private:
public: public:
int rows() const { return items()-1; } // Numero di righe presenti int rows() const { return items()-1; } // Numero di righe presenti
int last_row() const { return last(); } // Ultima riga int last_row() const { return last() + _offset; } // Ultima riga
int first_row() const { return 1 + _offset ; }
const TRectype& row(int r) const // Ennesima riga costante const TRectype& row(int r) const // Ennesima riga costante
{ CHECKD(r > 0, "Bad record number ", r); return (const TRectype&)operator[](r); } { CHECKD(r > _offset, "Bad record number ", r); return (const TRectype&)operator[](r - _offset); }
TRectype& row(int r, bool create); // Ennesima riga TRectype& row(int r, bool create); // Ennesima riga
@ -177,8 +179,8 @@ public:
virtual int rewrite() { return write(TRUE); } virtual int rewrite() { return write(TRUE); }
virtual int remove(); // Cancella tutti i record dal file virtual int remove(); // Cancella tutti i record dal file
TRecord_array(const TRectype& r, const char* numfield); TRecord_array(const TRectype& r, const char* numfield, int first = 1);
TRecord_array(int logicnum, const char* numfield); TRecord_array(int logicnum, const char* numfield, int first = 1);
}; };