isam.cpp Aggiunti metodi di confronto tra record
isam.h E loro prototipi relation.cpp Usati nei record array i precedenti metodi strings.cpp Aggiunta sort dei TString_array strings.h e suo prototipo git-svn-id: svn://10.65.10.50/trunk@2137 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
fb0eaada3a
commit
31282ab714
@ -174,7 +174,9 @@ HIDDEN int CBuildKey(RecDes *recd, int numkey, RecType recin, char *key, bool b
|
||||
/* recin; buffer contenente il record */
|
||||
/* *key; valore della chiave */
|
||||
/* build_x_cb flag di costruzione per codebase */
|
||||
{
|
||||
{
|
||||
CHECKD(numkey > 0, "Can't build key ", numkey);
|
||||
|
||||
key[0] = '\0';
|
||||
if (numkey-- <= recd->NKeys)
|
||||
{
|
||||
@ -2105,11 +2107,36 @@ const char* TRectype::build_key(int num) const
|
||||
return __tmp_string;
|
||||
}
|
||||
|
||||
int TRectype::compare_key(const TRectype& rec, int key) const
|
||||
const char* TRectype::last_key_field(int key) const
|
||||
{
|
||||
const KeyDes& kd = rec_des()->Ky[key];
|
||||
const int last = kd.NkFields-1;
|
||||
const bool upp = kd.FieldSeq[last] > MaxFields;
|
||||
const int nf = upp ? kd.FieldSeq[last] - MaxFields : kd.FieldSeq[last];
|
||||
const RecFieldDes& rf = rec_des()->Fd[nf];
|
||||
return rf.Name;
|
||||
}
|
||||
|
||||
int TRectype::compare_key(const TRectype& rec, int key, int skip_last) const
|
||||
{
|
||||
TString256 key1= build_key(key);
|
||||
TString256 key2 = rec.build_key(key);
|
||||
return key1.compare(key2);
|
||||
if (skip_last > 0)
|
||||
{
|
||||
const KeyDes& kd = rec_des()->Ky[key-1];
|
||||
const int last = kd.NkFields-1;
|
||||
CHECKD(last >= skip_last, "Can't ignore so many fields in key: ", skip_last);
|
||||
for (int l = 0; l < skip_last; l++)
|
||||
{
|
||||
int nf = kd.FieldSeq[last-l];
|
||||
if (nf > MaxFields) nf -= MaxFields;
|
||||
const RecFieldDes& rf = rec_des()->Fd[nf];
|
||||
key1.rtrim(rf.Len);
|
||||
key2.rtrim(rf.Len);
|
||||
}
|
||||
}
|
||||
const int res = strcmp(key1, key2);
|
||||
return res;
|
||||
}
|
||||
|
||||
HIDDEN bool fld_empty(const char* s, int len, bool number)
|
||||
|
@ -65,6 +65,7 @@ class TRectype : public TSortable
|
||||
|
||||
protected: // TObject
|
||||
virtual int compare(const TSortable& s) const;
|
||||
const char* last_key_field(int key) const;
|
||||
|
||||
protected:
|
||||
const char* start(int nf) const;
|
||||
@ -98,8 +99,9 @@ public:
|
||||
const char* fieldname(int i) const; // Ritorna il nome del campo i
|
||||
|
||||
const char* build_key(int key = 1) const;
|
||||
int compare_key(const TRectype& rec, int key = 1) const;
|
||||
bool same_key(const TRectype& rec, int key = 1) const { return compare_key(rec, key) == 0; }
|
||||
int compare_key(const TRectype& rec, int key = 1, int skip_last = 0) const;
|
||||
bool same_key(const TRectype& rec, int key = 1, int skip_last = 0) const
|
||||
{ return compare_key(rec, key, skip_last) == 0; }
|
||||
|
||||
const char* get_str(const char* fieldname) const ;
|
||||
#ifndef FOXPRO
|
||||
|
@ -1,4 +1,4 @@
|
||||
// $Id: relation.cpp,v 1.68 1995-11-10 13:37:28 guy Exp $
|
||||
// $Id: relation.cpp,v 1.69 1995-11-13 12:08:51 guy Exp $
|
||||
// relation.cpp
|
||||
// fv 12/8/93
|
||||
// relation class for isam files
|
||||
@ -1733,6 +1733,13 @@ void TRecord_array::destroy_rows()
|
||||
destroy(i);
|
||||
}
|
||||
|
||||
// Confronta i campi della chiave 1 scartando l'ultimo
|
||||
bool TRecord_array::good(const TRectype& rec) const
|
||||
{
|
||||
const bool yes = key().same_key(rec, 1, 1);
|
||||
return yes;
|
||||
}
|
||||
|
||||
int TRecord_array::read(TRectype* filter)
|
||||
{
|
||||
CHECKD(filter->num() == _file, "Bad key record ", filter->num());
|
||||
@ -1747,7 +1754,7 @@ int TRecord_array::read(TRectype* filter)
|
||||
set_key(filter);
|
||||
TRectype* rec = (TRectype*)filter->dup();
|
||||
err = rec->read(f, _isgteq);
|
||||
for (int e = err; e == NOERR && *rec == *filter; e = rec->next(f))
|
||||
for (int e = err; e == NOERR && good(*rec); e = rec->next(f))
|
||||
{
|
||||
add_row(rec);
|
||||
rec = (TRectype*)filter->dup();
|
||||
@ -1772,12 +1779,8 @@ int TRecord_array::remove_from(int pos) const
|
||||
|
||||
TLocalisamfile f(_file);
|
||||
rec->put(_num, pos);
|
||||
for (int e = rec->read(f, _isgteq); e == NOERR && *rec == key(); e = rec->next(f))
|
||||
for (int e = rec->read(f, _isgteq); e == NOERR && good(*rec); e = rec->next(f))
|
||||
{
|
||||
#ifdef DBG
|
||||
TString k_rec = rec->build_key();
|
||||
TString k_key = key().build_key();
|
||||
#endif
|
||||
const int found = rec->get_int(_num);
|
||||
if (found >= pos)
|
||||
{
|
||||
@ -1838,7 +1841,7 @@ int TRecord_array::write(bool re) const
|
||||
CHECK(!rec->empty(), "TRecord_array has an empty key");
|
||||
rec->put(_num, pos);
|
||||
err = rec->read(f, _isgteq);
|
||||
if (err == NOERR && *rec == key()) // La riga c'era ma ora non piu'
|
||||
if (err == NOERR && good(*rec)) // La riga c'era ma ora non piu'
|
||||
{
|
||||
last_on_file = atoi(rec->get(_num));
|
||||
if (last_on_file == pos)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: relation.h,v 1.28 1995-09-19 15:45:42 guy Exp $ */
|
||||
/* $Id: relation.h,v 1.29 1995-11-13 12:08:55 guy Exp $ */
|
||||
// join.h
|
||||
// fv 12/8/93
|
||||
// join class for isam files
|
||||
@ -139,6 +139,7 @@ protected:
|
||||
int rec2row(const TRectype& r) const; // Estrae il numero riga di un record
|
||||
const TString& num_field() const { return _num; }
|
||||
int remove_from(int i) const;
|
||||
bool good(const TRectype& rec) const;
|
||||
|
||||
public:
|
||||
const TRectype& key() const;
|
||||
|
@ -1361,3 +1361,21 @@ int TString_array::find(
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
HIDDEN int ascending_string(const TObject** o1, const TObject** o2)
|
||||
{
|
||||
const TString* s1 = (const TString*)*o1;
|
||||
const TString* s2 = (const TString*)*o2;
|
||||
return strcmp(*s1, *s2);
|
||||
}
|
||||
|
||||
HIDDEN int descending_string(const TObject** o1, const TObject** o2)
|
||||
{
|
||||
return -ascending_string(o1, o2);
|
||||
}
|
||||
|
||||
void TString_array::sort(bool ascending)
|
||||
{
|
||||
TArray::sort(ascending ? ascending_string : descending_string);
|
||||
}
|
||||
|
||||
|
@ -510,6 +510,8 @@ public:
|
||||
int add(const char* s, int n = -1);
|
||||
// @cmember Cerca una stringa nell'array
|
||||
int find(const char* s, int from = 0) const;
|
||||
// @cmember Ordina alfabeticamente l'array
|
||||
void sort(bool ascendig = TRUE);
|
||||
|
||||
// @cmember Costruttore
|
||||
TString_array(int size = 8) : TArray(size)
|
||||
|
Loading…
x
Reference in New Issue
Block a user