Patch level : 2.2
Files correlati : Ricompilazione Demo : [ ] Commento : Migliorata ed elegantita gestione cache delle unita' di misura git-svn-id: svn://10.65.10.50/trunk@13425 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
2dedf5f983
commit
18cb466b6b
58
db/dblib.cpp
58
db/dblib.cpp
@ -13,31 +13,53 @@
|
||||
#include "../mg/rmovmag.h"
|
||||
#include "../include/rdoc.h"
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// Cache fattori di conversione
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
class TConversionCache : public TCache
|
||||
{
|
||||
TLocalisamfile _umart;
|
||||
|
||||
private:
|
||||
virtual TObject* key2obj(const char* key);
|
||||
|
||||
public:
|
||||
TConversionCache();
|
||||
};
|
||||
|
||||
TObject* TConversionCache::key2obj(const char* key)
|
||||
{
|
||||
TToken_string str = key;
|
||||
_umart.put(UMART_CODART, str.get(0));
|
||||
_umart.put(UMART_UM, str.get());
|
||||
_umart.setkey(2);
|
||||
|
||||
real num;
|
||||
if (_umart.read() == NOERR)
|
||||
num = _umart.get_real(UMART_FC);
|
||||
else
|
||||
num = UNO; // Should never happen
|
||||
return new fraction(num, UNO);
|
||||
}
|
||||
|
||||
TConversionCache::TConversionCache()
|
||||
: _umart(LF_UMART)
|
||||
{ }
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TQuantita'
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
const fraction& TQuantita::get_factor(const TCodice_um& um) const
|
||||
{
|
||||
static TAssoc_array factors;
|
||||
static TConversionCache* factors = NULL;
|
||||
if (factors == NULL)
|
||||
factors = new TConversionCache;
|
||||
|
||||
TString80 code;
|
||||
code << _articolo << '|' << (um.empty() ? _um : um);
|
||||
|
||||
fraction* conv = (fraction*)factors.objptr(code);
|
||||
if (conv == NULL)
|
||||
{
|
||||
TLocalisamfile umart(LF_UMART);
|
||||
umart.setkey(2);
|
||||
umart.put(UMART_CODART, _articolo);
|
||||
umart.put(UMART_UM, um.empty() ? _um : um);
|
||||
if (umart.read() == NOERR)
|
||||
conv = new fraction(umart.get_real(UMART_FC), UNO);
|
||||
else
|
||||
conv = new fraction(1,1);
|
||||
factors.add(code, conv);
|
||||
}
|
||||
|
||||
code << _articolo << '|' << (um.blank() ? _um : um);
|
||||
const fraction* conv = (const fraction*)factors->objptr(code);
|
||||
return *conv;
|
||||
}
|
||||
|
||||
@ -91,7 +113,7 @@ void TQuantita::convert(real& val, const TCodice_um& from_um, const TCodice_um&
|
||||
{
|
||||
const fraction& mul = get_factor(from_um);
|
||||
const fraction& div = get_factor(to_um);
|
||||
val = fraction(val, UNO) * mul / div;
|
||||
val = mul / div * fraction(val, UNO);
|
||||
TArticolo::round_um(val, to_um);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user