From 56b49e49917ce9e4bc85a67ede5171e041ccd91e Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 18 Apr 1995 11:03:46 +0000 Subject: [PATCH] Aggiunto first nei record array git-svn-id: svn://10.65.10.50/trunk@1259 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/relation.cpp | 39 +++++++++++++++++++++------------------ include/relation.h | 12 +++++++----- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/include/relation.cpp b/include/relation.cpp index 9f8a24ec4..5a9d1a72f 100755 --- a/include/relation.cpp +++ b/include/relation.cpp @@ -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 // fv 12/8/93 // relation class for isam files @@ -1308,14 +1308,14 @@ int TFieldref::len(TRectype &rec) const // TRecord_Array /////////////////////////////////////////////////////////// -TRecord_array::TRecord_array(const TRectype& r, const char* numfield) -: _file(r.num()), _num(numfield) +TRecord_array::TRecord_array(const TRectype& r, const char* numfield, int first) +: _file(r.num()), _num(numfield), _offset(first - 1) { read(r); } -TRecord_array::TRecord_array(int logicnum, const char* numfield) -: _file(logicnum), _num(numfield) +TRecord_array::TRecord_array(int logicnum, const char* numfield, int first) +: _file(logicnum), _num(numfield), _offset(first - 1) {} 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* r = (TRectype*)objptr(n); +{ + const int i = n > 0 ? n - _offset : -1; + TRectype* r = (TRectype*)objptr(i); if (r == NULL && create) { r = new TRectype(key()); - n = add(r, n); // Riassegna n se era negativo! - r->put(_num, n); // Aggiorna campo numero riga + n = add(r, i) + _offset; // Riassegna n se era negativo! + r->put(_num, n); // Aggiorna campo numero riga } CHECKD(r && n > 0, "Bad record number ", n); return *r; @@ -1375,8 +1376,8 @@ bool TRecord_array::renum_key(const char* field, long num) int TRecord_array::rec2row(const TRectype& r) const { CHECK(r == key(), "Incompatible record"); - const int n = atoi(r.get(_num)); // Non e' detto che sia un int! - CHECKD(n > 0 && n < 32000, "Bad line number in record ", n); + 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 + _offset); return n; } @@ -1391,12 +1392,14 @@ int TRecord_array::add_row(const TRectype& r) bool TRecord_array::destroy_row(int r, bool pack) { - CHECKD(r > 0, "Can't destroy row ", r); - const bool ok = destroy(r, pack); + CHECKD(r > _offset, "Can't destroy row ", r); + const int index = r - _offset; + const bool ok = destroy(index, pack); + if (ok && pack) { - for (int i = r; i < items(); i++) - row(i, FALSE).put(_num, i); + for (int i = index; i < items(); i++) + row(i + _offset, FALSE).put(_num, i + _offset); } return ok; } @@ -1404,7 +1407,7 @@ bool TRecord_array::destroy_row(int r, bool pack) void TRecord_array::destroy_rows() { for (int i = last(); i > 0; i--) - destroy_row(i); + destroy(i); } int TRecord_array::read(const TRectype& filter) @@ -1445,7 +1448,7 @@ int TRecord_array::write(bool re) } else { - f.curr() = key(); f.put(_num, i); + f.curr() = key(); f.put(_num, i + _offset); err = f.read(); if (err == NOERR) // La riga c'era ma ora non piu' { @@ -1459,7 +1462,7 @@ int TRecord_array::write(bool re) if (err == NOERR) { // 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()) { err = f.remove(); diff --git a/include/relation.h b/include/relation.h index 5ed479b7c..2468f9452 100755 --- a/include/relation.h +++ b/include/relation.h @@ -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 // fv 12/8/93 // join class for isam files @@ -149,6 +149,7 @@ public: class TRecord_array : private TArray { int _file; // Numero logico del file principale + int _offset; // Offset iniziale del record array TString16 _num; // Nome del campo col numero di riga private: @@ -157,10 +158,11 @@ private: public: 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 - { 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 @@ -177,8 +179,8 @@ public: virtual int rewrite() { return write(TRUE); } virtual int remove(); // Cancella tutti i record dal file - TRecord_array(const TRectype& r, const char* numfield); - TRecord_array(int logicnum, const char* numfield); + TRecord_array(const TRectype& r, const char* numfield, int first = 1); + TRecord_array(int logicnum, const char* numfield, int first = 1); };