From 027467de505f9e90860b4d70a4d36ba88cbf2daf Mon Sep 17 00:00:00 2001 From: augusto Date: Fri, 26 Sep 1997 10:18:05 +0000 Subject: [PATCH] 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 --- include/recarray.cpp | 52 ++++++++++++++++++++++++++++++-------------- include/recarray.h | 28 +++++++++++++++++------- 2 files changed, 56 insertions(+), 24 deletions(-) diff --git a/include/recarray.cpp b/include/recarray.cpp index f7cf88f2d..03a5c9f5d 100755 --- a/include/recarray.cpp +++ b/include/recarray.cpp @@ -448,7 +448,7 @@ void TFile_cache::test_firm() if (cur_firm != _last_firm) { _last_firm = cur_firm; - destroy(); + _cache.destroy(); } } } @@ -457,11 +457,11 @@ const TObject& TFile_cache::query(const char* code) { test_firm(); + _error = NOERR; _code = code; - TObject* obj = objptr(_code); + TObject* obj = _cache.objptr(_code); if (obj == NULL) { - int err = ~NOERR; TRectype& curr = _file->curr(); if (_code.not_empty()) { @@ -475,20 +475,34 @@ const TObject& TFile_cache::query(const char* code) if (val) curr.put(rf.Name, val); 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); - 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); - add(_code, obj); + _cache.add(_code, obj); } return *obj; } +int TFile_cache::io_result() +{ + return _error; +} + int TFile_cache::fill() { test_firm(); @@ -509,12 +523,19 @@ int TFile_cache::fill() _code.add(val); } 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 /////////////////////////////////////////////////////////// @@ -563,15 +584,14 @@ TObject* TRecord_cache::rec2obj(const TRectype& curr) const 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& rec = (const TRectype&)query(key); return rec; } +const TString& TRecord_cache::get(const char* key, const char* field) +{ + return get(key).get(field); +} + diff --git a/include/recarray.h b/include/recarray.h index 8f54ec3b2..e7fc39943 100755 --- a/include/recarray.h +++ b/include/recarray.h @@ -142,24 +142,34 @@ public: // TFile_cache /////////////////////////////////////////////////////////// -class TFile_cache : private TAssoc_array +class TFile_cache : public TObject { + TToken_string _code; TLocalisamfile* _file; int _key; long _last_firm; + int _error; -private: +protected: + TAssoc_array _cache; + +protected: void init_file(); void test_firm(); - -protected: + const TObject& query(const char* chiave); virtual TObject* rec2obj(const TRectype& rec) const pure; + TLocalisamfile & file(); public: + int io_result(); + const int key_number() const + {return _key;} + long items() + {return _cache.items();} int fill(); - + TFile_cache(int num, int key = 1); TFile_cache(const char* table, int key = 1); virtual ~TFile_cache(); @@ -170,7 +180,7 @@ class TDecoder : public TFile_cache TString16 _outf; protected: - TObject* rec2obj(const TRectype& rec) const; + virtual TObject* rec2obj(const TRectype& rec) const; public: const TString& decode(const char* code); @@ -184,11 +194,13 @@ public: class TRecord_cache : public TFile_cache { protected: - TObject* rec2obj(const TRectype& rec) const; + virtual TObject* rec2obj(const TRectype& rec) const; public: + // @cmember ritorna il campo (chiama get(chiave)) 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(const char* table, int key = 1);