Patch level :

Files correlati     :
Ricompilazione Demo : [ ]
Commento            :
Aggiunti metodi di test sulle dimensioni e sui cambiamenti delle cache


git-svn-id: svn://10.65.10.50/trunk@7302 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1998-10-20 12:42:57 +00:00
parent 9e10d401f6
commit 405b8c618c
2 changed files with 40 additions and 5 deletions

View File

@ -1,3 +1,5 @@
#include <time.h>
#include <prefix.h>
#include <recarray.h>
#include <tabutil.h>
@ -401,20 +403,23 @@ int TRecord_array::remove() const
///////////////////////////////////////////////////////////
TFile_cache::TFile_cache(TLocalisamfile *f , int key)
: _file(NULL), _key(key)
: _file(NULL), _key(key),
_test_changes(FALSE), _last_read(0), _limit(0)
{
_filecode << f->num();
init_file(f);
}
TFile_cache::TFile_cache(int num, int key)
: _file(NULL), _key(key), _last_firm(-883)
: _file(NULL), _key(key), _last_firm(-883),
_test_changes(FALSE), _last_read(0), _limit(0)
{
_filecode << num;
}
TFile_cache::TFile_cache(const char* tab, int key)
: _file(NULL), _key(key), _last_firm(-883)
: _file(NULL), _key(key), _last_firm(-883),
_test_changes(FALSE), _last_read(0), _limit(0)
{
_filecode = tab;
}
@ -455,6 +460,7 @@ void TFile_cache::init_file(TLocalisamfile* f)
dir.get(_file->num(), _nolock, _nordir, _sysdirop);
// Se e' un file comune metti a -1, altrimenti alla ditta corrente
_last_firm = dir.is_com() ? -1 : prefix().get_codditta();
_last_read = 0L;
}
}
@ -462,7 +468,7 @@ void TFile_cache::test_firm()
{
if (_last_firm < -1)
init_file();
if (_last_firm >= 0) // Se e' un file di ditta ...
{ // ... controlla che non sia cambiata
const long cur_firm = prefix().get_codditta();
@ -472,6 +478,30 @@ void TFile_cache::test_firm()
_cache.destroy();
}
}
bool flush_needed = FALSE;
if (_test_changes)
{
if (_file != NULL && _file->is_changed_since(_last_read))
flush_needed = TRUE;
}
if (_limit > 0 && items() > _limit)
flush_needed = TRUE;
if (flush_needed)
{
flush();
_cache.destroy();
}
_last_read = clock();
}
void TFile_cache::flush()
{
// Needed by read/write cache
}
const TObject& TFile_cache::query(const char* code)

View File

@ -147,10 +147,11 @@ class TFile_cache : public TObject
TToken_string _code;
TString16 _filecode;
TLocalisamfile* _file;
TString16 _filecode;
int _key;
long _last_firm;
int _error;
long _last_read, _limit;
bool _test_changes;
protected:
TAssoc_array _cache;
@ -175,6 +176,10 @@ public:
long fill();
void destroy();
virtual void flush();
void set_items_limit(long l) { _limit = l; }
void test_file_changes(bool t = TRUE) { _test_changes = t; }
TFile_cache(TLocalisamfile *f,int key = 1);
TFile_cache(int num, int key = 1);