Derivazione di TRecarray da TObject con TAssoc_array contenuto all'interno.
Modifiche in preparazione alla classe TRWcache git-svn-id: svn://10.65.10.50/trunk@5280 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
2840b79430
commit
027467de50
@ -448,7 +448,7 @@ void TFile_cache::test_firm()
|
|||||||
if (cur_firm != _last_firm)
|
if (cur_firm != _last_firm)
|
||||||
{
|
{
|
||||||
_last_firm = cur_firm;
|
_last_firm = cur_firm;
|
||||||
destroy();
|
_cache.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -457,11 +457,11 @@ const TObject& TFile_cache::query(const char* code)
|
|||||||
{
|
{
|
||||||
test_firm();
|
test_firm();
|
||||||
|
|
||||||
|
_error = NOERR;
|
||||||
_code = code;
|
_code = code;
|
||||||
TObject* obj = objptr(_code);
|
TObject* obj = _cache.objptr(_code);
|
||||||
if (obj == NULL)
|
if (obj == NULL)
|
||||||
{
|
{
|
||||||
int err = ~NOERR;
|
|
||||||
TRectype& curr = _file->curr();
|
TRectype& curr = _file->curr();
|
||||||
if (_code.not_empty())
|
if (_code.not_empty())
|
||||||
{
|
{
|
||||||
@ -475,20 +475,34 @@ const TObject& TFile_cache::query(const char* code)
|
|||||||
if (val)
|
if (val)
|
||||||
curr.put(rf.Name, val);
|
curr.put(rf.Name, val);
|
||||||
else
|
else
|
||||||
NFCHECK("Valore del campo chiave %s non specificato per il decoder", rf.Name);
|
NFCHECK("Valore del campo chiave %s non specificato per la cache", rf.Name);
|
||||||
}
|
}
|
||||||
_file->setkey(_key);
|
_file->setkey(_key);
|
||||||
err = _file->read();
|
_error = _file->read();
|
||||||
|
} else
|
||||||
|
_error = _iskeyerr;
|
||||||
|
switch (_error)
|
||||||
|
{
|
||||||
|
case NOERR:
|
||||||
|
break;
|
||||||
|
case _iskeynotfound:
|
||||||
|
case _iseof:
|
||||||
|
case _isemptyfile:
|
||||||
|
default:
|
||||||
|
curr.zero();
|
||||||
}
|
}
|
||||||
if (err != NOERR)
|
|
||||||
curr.zero();
|
|
||||||
obj = rec2obj(curr);
|
obj = rec2obj(curr);
|
||||||
add(_code, obj);
|
_cache.add(_code, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
return *obj;
|
return *obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TFile_cache::io_result()
|
||||||
|
{
|
||||||
|
return _error;
|
||||||
|
}
|
||||||
|
|
||||||
int TFile_cache::fill()
|
int TFile_cache::fill()
|
||||||
{
|
{
|
||||||
test_firm();
|
test_firm();
|
||||||
@ -509,12 +523,19 @@ int TFile_cache::fill()
|
|||||||
_code.add(val);
|
_code.add(val);
|
||||||
}
|
}
|
||||||
TObject* obj = rec2obj(curr);
|
TObject* obj = rec2obj(curr);
|
||||||
add(_code, obj);
|
_cache.add(_code, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
return items();
|
return _cache.items();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TLocalisamfile & TFile_cache::file()
|
||||||
|
{
|
||||||
|
if (!_file)
|
||||||
|
init_file();
|
||||||
|
return *_file;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
// TDecoder
|
// TDecoder
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
@ -563,15 +584,14 @@ TObject* TRecord_cache::rec2obj(const TRectype& curr) const
|
|||||||
return new TRectype(curr);
|
return new TRectype(curr);
|
||||||
}
|
}
|
||||||
|
|
||||||
const TString& TRecord_cache::get(const char* key, const char* field)
|
|
||||||
{
|
|
||||||
const TRectype& rec = (const TRectype&)query(key);
|
|
||||||
return rec.get(field);
|
|
||||||
}
|
|
||||||
|
|
||||||
const TRectype& TRecord_cache::get(const char* key)
|
const TRectype& TRecord_cache::get(const char* key)
|
||||||
{
|
{
|
||||||
const TRectype& rec = (const TRectype&)query(key);
|
const TRectype& rec = (const TRectype&)query(key);
|
||||||
return rec;
|
return rec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TString& TRecord_cache::get(const char* key, const char* field)
|
||||||
|
{
|
||||||
|
return get(key).get(field);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -142,24 +142,34 @@ public:
|
|||||||
// TFile_cache
|
// TFile_cache
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class TFile_cache : private TAssoc_array
|
class TFile_cache : public TObject
|
||||||
{
|
{
|
||||||
|
|
||||||
TToken_string _code;
|
TToken_string _code;
|
||||||
TLocalisamfile* _file;
|
TLocalisamfile* _file;
|
||||||
int _key;
|
int _key;
|
||||||
long _last_firm;
|
long _last_firm;
|
||||||
|
int _error;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
|
TAssoc_array _cache;
|
||||||
|
|
||||||
|
protected:
|
||||||
void init_file();
|
void init_file();
|
||||||
void test_firm();
|
void test_firm();
|
||||||
|
|
||||||
protected:
|
|
||||||
const TObject& query(const char* chiave);
|
const TObject& query(const char* chiave);
|
||||||
virtual TObject* rec2obj(const TRectype& rec) const pure;
|
virtual TObject* rec2obj(const TRectype& rec) const pure;
|
||||||
|
TLocalisamfile & file();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
int io_result();
|
||||||
|
const int key_number() const
|
||||||
|
{return _key;}
|
||||||
|
long items()
|
||||||
|
{return _cache.items();}
|
||||||
int fill();
|
int fill();
|
||||||
|
|
||||||
TFile_cache(int num, int key = 1);
|
TFile_cache(int num, int key = 1);
|
||||||
TFile_cache(const char* table, int key = 1);
|
TFile_cache(const char* table, int key = 1);
|
||||||
virtual ~TFile_cache();
|
virtual ~TFile_cache();
|
||||||
@ -170,7 +180,7 @@ class TDecoder : public TFile_cache
|
|||||||
TString16 _outf;
|
TString16 _outf;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TObject* rec2obj(const TRectype& rec) const;
|
virtual TObject* rec2obj(const TRectype& rec) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const TString& decode(const char* code);
|
const TString& decode(const char* code);
|
||||||
@ -184,11 +194,13 @@ public:
|
|||||||
class TRecord_cache : public TFile_cache
|
class TRecord_cache : public TFile_cache
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
TObject* rec2obj(const TRectype& rec) const;
|
virtual TObject* rec2obj(const TRectype& rec) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
// @cmember ritorna il campo (chiama get(chiave))
|
||||||
const TString& get(const char* chiave, const char* campo);
|
const TString& get(const char* chiave, const char* campo);
|
||||||
const TRectype& get(const char* chiave);
|
// @cmember ritorna il record con una determinata chiave
|
||||||
|
virtual const TRectype& get(const char* chiave);
|
||||||
|
|
||||||
TRecord_cache(int num, int key = 1);
|
TRecord_cache(int num, int key = 1);
|
||||||
TRecord_cache(const char* table, int key = 1);
|
TRecord_cache(const char* table, int key = 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user