1998-05-08 12:19:34 +00:00
|
|
|
#include <currency.h>
|
1999-01-19 09:15:17 +00:00
|
|
|
#include <prefix.h>
|
1998-05-08 12:19:34 +00:00
|
|
|
#include <recarray.h>
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// DowJones
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TDowJones : public TFile_cache
|
|
|
|
{
|
|
|
|
struct TExchangeData : public TObject
|
|
|
|
{
|
1999-01-19 09:15:17 +00:00
|
|
|
real _chg; // Cambio
|
|
|
|
int _dec; // Decimali per gli importi normali
|
|
|
|
int _dec_prices; // Decimali per i prezzi unitari
|
1999-02-02 08:43:43 +00:00
|
|
|
int _dec_change; // Decimali per i cambi
|
1999-01-19 09:15:17 +00:00
|
|
|
bool _is_euro; // E' l'EURO in persona
|
1999-10-22 10:00:18 +00:00
|
|
|
exchange_type _et; // Il cambio e' espresso contro EURO
|
1998-05-08 12:19:34 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
const TExchangeData& operator=(const TExchangeData& d)
|
1999-01-19 09:15:17 +00:00
|
|
|
{
|
|
|
|
_chg = d._chg; _dec = d._dec; _dec_prices = d._dec_prices;
|
1999-10-22 10:00:18 +00:00
|
|
|
_is_euro = d._is_euro; _et = d._et;
|
1999-01-19 09:15:17 +00:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
TExchangeData()
|
1999-10-22 10:00:18 +00:00
|
|
|
: _chg(1.0), _dec(0), _dec_prices(0), _is_euro(FALSE), _et(_exchange_base) { }
|
1998-05-08 12:19:34 +00:00
|
|
|
};
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
long _codditta;
|
1999-01-19 09:15:17 +00:00
|
|
|
TString16 _base_val, _firm_val, _euro_val;
|
|
|
|
real _euro_chg;
|
1998-05-08 12:19:34 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual TObject* rec2obj(const TRectype& rec) const;
|
|
|
|
|
|
|
|
void test_cache();
|
|
|
|
const TExchangeData& get(const char* key);
|
|
|
|
|
|
|
|
public:
|
1998-11-03 10:27:35 +00:00
|
|
|
const TString& get_base_val();
|
|
|
|
const TString& get_firm_val();
|
1999-01-19 09:15:17 +00:00
|
|
|
const TString& get_euro_val();
|
2000-10-03 13:45:12 +00:00
|
|
|
void force_firm_val(const char* val);
|
1998-11-03 10:27:35 +00:00
|
|
|
const char* expand_value(const char* val);
|
1999-10-22 10:00:18 +00:00
|
|
|
const char* normalize_value(const char* val, const real& chg, exchange_type& et);
|
1998-05-08 12:19:34 +00:00
|
|
|
|
1998-11-03 10:27:35 +00:00
|
|
|
real exchange(const real& num,
|
1999-10-22 10:00:18 +00:00
|
|
|
const char* fromval, const real& fromchg, exchange_type fromeuro,
|
|
|
|
const char* toval, const real& tochg, exchange_type toeuro,
|
2002-10-23 14:14:55 +00:00
|
|
|
int price = 0);
|
1999-10-22 10:00:18 +00:00
|
|
|
|
2002-10-23 14:14:55 +00:00
|
|
|
real exchange(const real& num, const TExchange& frval, const TExchange& toval, int price = 0);
|
1999-10-22 10:00:18 +00:00
|
|
|
|
1998-11-03 10:27:35 +00:00
|
|
|
int get_dec(const char* val, bool prices = FALSE);
|
1999-10-22 10:00:18 +00:00
|
|
|
const real& get_change(const char* val, exchange_type& contro_euro);
|
|
|
|
real get_base_change(const char* val);
|
|
|
|
real get_contro_change(const char* val);
|
1998-05-08 12:19:34 +00:00
|
|
|
|
2001-04-30 15:04:10 +00:00
|
|
|
virtual void flush();
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
TDowJones() : TFile_cache("%VAL"), _codditta(0) { }
|
1998-05-08 12:19:34 +00:00
|
|
|
virtual ~TDowJones() { }
|
|
|
|
} DowJones;
|
|
|
|
|
|
|
|
TObject* TDowJones::rec2obj(const TRectype& rec) const
|
|
|
|
{
|
|
|
|
TExchangeData* data = new TExchangeData;
|
1999-01-19 09:15:17 +00:00
|
|
|
|
|
|
|
const TString16 codval = rec.get("CODTAB");
|
|
|
|
data->_chg = rec.get_real("S4");
|
|
|
|
if (data->_chg <= ZERO)
|
1998-05-08 12:19:34 +00:00
|
|
|
{
|
1999-01-19 09:15:17 +00:00
|
|
|
data->_chg = rec.get_real("R10");
|
|
|
|
if (data->_chg <= ZERO)
|
1999-06-18 15:35:05 +00:00
|
|
|
{
|
1999-07-16 14:59:11 +00:00
|
|
|
if (codval.not_empty() && codval != "LIT")
|
1999-06-18 15:35:05 +00:00
|
|
|
NFCHECK("Codice valuta senza cambio: '%s'", (const char*)codval);
|
1999-01-19 09:15:17 +00:00
|
|
|
data->_chg = 1.0;
|
|
|
|
}
|
1998-05-08 12:19:34 +00:00
|
|
|
}
|
1998-11-03 10:27:35 +00:00
|
|
|
|
1999-01-19 09:15:17 +00:00
|
|
|
if (codval.not_empty())
|
1998-05-08 12:19:34 +00:00
|
|
|
{
|
1999-01-19 09:15:17 +00:00
|
|
|
data->_dec = rec.get_int("I0");
|
|
|
|
data->_dec_prices = rec.get_int("I1");
|
|
|
|
if (data->_dec_prices < data->_dec)
|
|
|
|
data->_dec_prices = data->_dec;
|
1999-02-02 08:43:43 +00:00
|
|
|
data->_dec_change = rec.get_int("I2");
|
1999-01-19 09:15:17 +00:00
|
|
|
data->_is_euro = rec.get_bool("B0");
|
1999-10-22 10:00:18 +00:00
|
|
|
data->_et = rec.get_bool("B1") ? _exchange_contro : _exchange_base;
|
1998-05-08 12:19:34 +00:00
|
|
|
}
|
1999-01-19 09:15:17 +00:00
|
|
|
|
1998-05-08 12:19:34 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
1998-11-03 10:27:35 +00:00
|
|
|
void TDowJones::flush()
|
|
|
|
{
|
|
|
|
_base_val.cut(0);
|
|
|
|
_firm_val.cut(0);
|
1999-01-19 09:15:17 +00:00
|
|
|
_euro_val.cut(0);
|
2001-04-30 15:04:10 +00:00
|
|
|
kill_file();
|
1998-11-03 10:27:35 +00:00
|
|
|
}
|
|
|
|
|
1998-05-08 12:19:34 +00:00
|
|
|
void TDowJones::test_cache()
|
1999-10-22 10:00:18 +00:00
|
|
|
{
|
|
|
|
// Controllo se e' cambiata la ditta
|
|
|
|
const long newfirm = prefix().get_codditta();
|
|
|
|
if (newfirm != _codditta)
|
|
|
|
{
|
|
|
|
_codditta = newfirm;
|
|
|
|
_firm_val = prefix().firm().codice_valuta();
|
|
|
|
}
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
if (_base_val.empty())
|
1998-05-08 12:19:34 +00:00
|
|
|
{
|
|
|
|
fill();
|
1999-01-19 09:15:17 +00:00
|
|
|
FOR_EACH_ASSOC_OBJECT(_cache, hash, key, obj) if (*key)
|
1998-05-08 12:19:34 +00:00
|
|
|
{
|
1999-01-19 09:15:17 +00:00
|
|
|
const TExchangeData& data = *(const TExchangeData*)obj;
|
1999-10-22 10:00:18 +00:00
|
|
|
if ((_base_val.empty() || strcmp(key, "LIT") == 0) && data._chg == 1.0)
|
1999-07-16 14:59:11 +00:00
|
|
|
_base_val = key;
|
1999-06-18 15:35:05 +00:00
|
|
|
if (data._is_euro && _euro_val.empty())
|
1999-01-19 09:15:17 +00:00
|
|
|
_euro_val = key;
|
1998-05-08 12:19:34 +00:00
|
|
|
}
|
1999-01-19 09:15:17 +00:00
|
|
|
|
|
|
|
if (_euro_val.empty()) // Si son dimenticati dell'EURO?
|
|
|
|
{
|
|
|
|
TExchangeData* euro = new TExchangeData;
|
1999-10-22 10:00:18 +00:00
|
|
|
euro->_chg = 1936.27; euro->_dec = euro->_dec_prices = 2;
|
|
|
|
euro->_is_euro = TRUE; euro->_et = _exchange_base;
|
1999-01-19 09:15:17 +00:00
|
|
|
_euro_val = "EUR";
|
|
|
|
_cache.add(_euro_val, euro);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_base_val.empty()) // Si son dimenticati delle LIRE?
|
1998-05-08 12:19:34 +00:00
|
|
|
{
|
1999-01-19 09:15:17 +00:00
|
|
|
TExchangeData* lira = new TExchangeData;
|
1999-10-22 10:00:18 +00:00
|
|
|
lira->_chg = 1.0; lira->_dec = lira->_dec_prices = 0;
|
|
|
|
lira->_is_euro = FALSE; lira->_et = _exchange_base;
|
1998-11-03 10:27:35 +00:00
|
|
|
_base_val = "LIT";
|
1999-01-19 09:15:17 +00:00
|
|
|
_cache.add(_base_val, lira);
|
|
|
|
}
|
|
|
|
_firm_val = prefix().firm().codice_valuta();
|
1999-10-22 10:00:18 +00:00
|
|
|
_euro_chg = get_base_change(_euro_val);
|
1998-05-08 12:19:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-03 10:27:35 +00:00
|
|
|
const char* TDowJones::expand_value(const char* val)
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
if (val && *val > ' ')
|
1998-11-03 10:27:35 +00:00
|
|
|
{
|
|
|
|
if (*val == '_')
|
|
|
|
{
|
|
|
|
if (stricmp(val, "_FIRM") == 0)
|
|
|
|
val = get_firm_val(); else
|
1999-01-19 09:15:17 +00:00
|
|
|
if (stricmp(val, "_EURO") == 0)
|
|
|
|
val = get_euro_val(); else
|
1998-11-03 10:27:35 +00:00
|
|
|
if (stricmp(val, "_BASE") == 0)
|
1999-07-16 14:59:11 +00:00
|
|
|
val = get_base_val();
|
1998-11-03 10:27:35 +00:00
|
|
|
}
|
1999-07-16 14:59:11 +00:00
|
|
|
else
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
// Leave code as is
|
|
|
|
}
|
1998-11-03 10:27:35 +00:00
|
|
|
}
|
|
|
|
else
|
1999-07-16 14:59:11 +00:00
|
|
|
val = get_firm_val();
|
|
|
|
|
|
|
|
return val;
|
1998-11-03 10:27:35 +00:00
|
|
|
}
|
|
|
|
|
1998-05-08 12:19:34 +00:00
|
|
|
const TDowJones::TExchangeData& TDowJones::get(const char* val)
|
|
|
|
{
|
|
|
|
test_cache();
|
1998-11-03 10:27:35 +00:00
|
|
|
return (const TExchangeData&)query(expand_value(val));
|
1998-05-08 12:19:34 +00:00
|
|
|
}
|
|
|
|
|
1998-11-03 10:27:35 +00:00
|
|
|
const TString& TDowJones::get_base_val()
|
1998-05-08 12:19:34 +00:00
|
|
|
{
|
|
|
|
test_cache();
|
1998-11-03 10:27:35 +00:00
|
|
|
return _base_val;
|
1998-05-08 12:19:34 +00:00
|
|
|
}
|
|
|
|
|
1998-11-03 10:27:35 +00:00
|
|
|
const TString& TDowJones::get_firm_val()
|
|
|
|
{
|
|
|
|
test_cache();
|
|
|
|
return _firm_val;
|
|
|
|
}
|
|
|
|
|
1999-01-19 09:15:17 +00:00
|
|
|
const TString& TDowJones::get_euro_val()
|
|
|
|
{
|
|
|
|
test_cache();
|
|
|
|
return _euro_val;
|
|
|
|
}
|
1998-11-03 10:27:35 +00:00
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
void TDowJones::force_firm_val(const char* val)
|
|
|
|
{
|
|
|
|
test_cache();
|
|
|
|
_firm_val = val;
|
|
|
|
}
|
|
|
|
|
1998-05-08 12:19:34 +00:00
|
|
|
real TDowJones::exchange(const real& num, // Importo da convertire
|
1999-01-19 09:15:17 +00:00
|
|
|
const char* frval, // Dalla valuta
|
|
|
|
const real& frchg, // Dal cambio
|
1999-10-22 10:00:18 +00:00
|
|
|
exchange_type freur, // Dal cambio in euro
|
1998-11-03 10:27:35 +00:00
|
|
|
const char* toval, // Alla valuta
|
|
|
|
const real& tochg, // Al cambio
|
1999-10-22 10:00:18 +00:00
|
|
|
exchange_type toeur, // Al cambio in euro
|
2002-10-23 14:14:55 +00:00
|
|
|
int price) // e' un prezzo ?
|
1998-05-08 12:19:34 +00:00
|
|
|
{
|
|
|
|
real n = num;
|
1999-01-19 09:15:17 +00:00
|
|
|
if (!n.is_zero())
|
1998-05-08 12:19:34 +00:00
|
|
|
{
|
1999-01-19 09:15:17 +00:00
|
|
|
const TExchangeData& datafr = get(frval);
|
1998-05-08 12:19:34 +00:00
|
|
|
const TExchangeData& datato = get(toval);
|
1999-07-16 14:59:11 +00:00
|
|
|
|
1999-06-18 15:35:05 +00:00
|
|
|
real fr = frchg;
|
1999-10-22 10:00:18 +00:00
|
|
|
if (fr <= ZERO) { fr = datafr._chg; freur = datafr._et; }
|
1999-07-16 14:59:11 +00:00
|
|
|
|
1999-06-18 15:35:05 +00:00
|
|
|
real to = tochg;
|
1999-10-22 10:00:18 +00:00
|
|
|
if (to <= ZERO) { to = datato._chg; toeur = datato._et; }
|
1999-07-16 14:59:11 +00:00
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
const int mode = (freur == _exchange_contro ? 1 : 0) + (toeur == _exchange_contro ? 2 : 0);
|
1999-01-19 09:15:17 +00:00
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case 1:
|
1999-06-18 15:35:05 +00:00
|
|
|
n = (n * _euro_chg) / (fr * to); // Modo misto 1
|
1999-01-19 09:15:17 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
n = n * (fr * to) / _euro_chg; // Modo misto 2
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
n = n * to / fr; // Nuovo modo
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
n = n * fr / to; // Vecchio modo
|
|
|
|
break;
|
1998-11-03 10:27:35 +00:00
|
|
|
}
|
2002-10-23 14:14:55 +00:00
|
|
|
if (price == 0 || price == 1) // Arrotonda solo in caso normale
|
|
|
|
n.round(price ? datato._dec_prices : datato._dec);
|
1998-05-08 12:19:34 +00:00
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
real TDowJones::exchange(const real& num, // Importo da convertire
|
|
|
|
const TExchange& frval, // Dalla valuta
|
|
|
|
const TExchange& toval, // Alla valuta
|
2002-10-23 14:14:55 +00:00
|
|
|
int price) // e' un prezzo ?
|
1999-10-22 10:00:18 +00:00
|
|
|
{
|
|
|
|
exchange_type fret, toet;
|
|
|
|
const real& frch = frval.get_change(fret);
|
|
|
|
const real& toch = toval.get_change(toet);
|
|
|
|
return exchange(num, frval.get_value(), frch, fret, toval.get_value(), toch, toet, price);
|
|
|
|
}
|
|
|
|
|
1998-11-03 10:27:35 +00:00
|
|
|
int TDowJones::get_dec(const char* val, bool price)
|
1998-05-08 12:19:34 +00:00
|
|
|
{
|
|
|
|
const TExchangeData& data = get(val);
|
1998-11-03 10:27:35 +00:00
|
|
|
return price ? data._dec_prices : data._dec;
|
1998-05-08 12:19:34 +00:00
|
|
|
}
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
const real& TDowJones::get_change(const char* val, exchange_type& et)
|
1999-01-19 09:15:17 +00:00
|
|
|
{
|
|
|
|
const TExchangeData& data = get(val);
|
1999-10-22 10:00:18 +00:00
|
|
|
et = data._et;
|
1999-01-19 09:15:17 +00:00
|
|
|
return data._chg;
|
|
|
|
}
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
real TDowJones::get_base_change(const char* val)
|
|
|
|
{
|
|
|
|
exchange_type et;
|
|
|
|
real c = get_change(val, et);
|
|
|
|
if (et == _exchange_contro)
|
|
|
|
{
|
|
|
|
c = _euro_chg / c;
|
|
|
|
c.round(6);
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
real TDowJones::get_contro_change(const char* val)
|
|
|
|
{
|
|
|
|
exchange_type et;
|
|
|
|
real c = get_change(val, et);
|
|
|
|
if (et == _exchange_base)
|
|
|
|
{
|
|
|
|
c = _euro_chg / c;
|
|
|
|
c.round(6);
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* TDowJones::normalize_value(const char* val, const real& exch, exchange_type& et)
|
|
|
|
{
|
|
|
|
val = expand_value(val);
|
|
|
|
if (et == _exchange_undefined)
|
|
|
|
{
|
|
|
|
if (exch > ZERO)
|
|
|
|
{
|
|
|
|
real base_diff = get_base_change(val) - exch;
|
|
|
|
base_diff = abs(base_diff);
|
|
|
|
|
|
|
|
real contro_diff = get_contro_change(val) - exch;
|
|
|
|
contro_diff = abs(contro_diff);
|
|
|
|
|
|
|
|
et = base_diff < contro_diff ? _exchange_base : _exchange_contro;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
get_change(val, et);
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TExchange
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void TExchange::copy(const TExchange& exc)
|
|
|
|
{
|
|
|
|
strcpy(_val, exc._val);
|
|
|
|
_exchange = exc._exchange;
|
|
|
|
_et = exc._et;
|
|
|
|
}
|
|
|
|
|
|
|
|
const real& TExchange::get_change(exchange_type& et) const
|
|
|
|
{
|
|
|
|
if (_exchange.is_zero())
|
|
|
|
return DowJones.get_change(_val, et);
|
|
|
|
et = _et;
|
|
|
|
return _exchange;
|
|
|
|
}
|
|
|
|
|
|
|
|
real TExchange::get_base_change() const
|
|
|
|
{
|
|
|
|
exchange_type et;
|
|
|
|
real c = get_change(et);
|
|
|
|
if (et != _exchange_base)
|
|
|
|
{
|
|
|
|
c = DowJones.get_base_change("_EURO") / c;
|
|
|
|
c.round(6);
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
real TExchange::get_contro_change() const
|
|
|
|
{
|
|
|
|
exchange_type et;
|
|
|
|
real c = get_change(et);
|
|
|
|
if (et != _exchange_contro)
|
|
|
|
{
|
|
|
|
c = DowJones.get_base_change("_EURO") / c;
|
|
|
|
c.round(6);
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TExchange::compare(const TSortable& obj) const
|
|
|
|
{
|
|
|
|
const TExchange& exc = (const TExchange&)obj;
|
|
|
|
int cmp = strcmp(_val, exc._val);
|
|
|
|
if (cmp == 0)
|
|
|
|
{
|
|
|
|
if (_et == exc._et)
|
|
|
|
{
|
|
|
|
exchange_type dummy;
|
|
|
|
const real diff = get_change(dummy) - exc.get_change(dummy);
|
|
|
|
cmp = diff.sign();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
real chg1 = get_contro_change();
|
|
|
|
real chg2 = exc.get_contro_change();
|
|
|
|
const real diff = chg1 - chg2;
|
|
|
|
cmp = diff.sign();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TExchange::same_value_as(const TExchange& exc) const
|
|
|
|
{
|
|
|
|
return strcmp(_val, exc._val) == 0;
|
|
|
|
}
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
bool TExchange::is_firm_value() const
|
|
|
|
{
|
|
|
|
return DowJones.get_firm_val() == _val;
|
|
|
|
}
|
|
|
|
|
2001-04-30 15:04:10 +00:00
|
|
|
bool TExchange::is_euro_value() const
|
|
|
|
{
|
|
|
|
return DowJones.get_euro_val() == _val;
|
|
|
|
}
|
|
|
|
|
2002-10-23 14:14:55 +00:00
|
|
|
int TExchange::decimals(bool price) const
|
|
|
|
{
|
|
|
|
return DowJones.get_dec(_val, price);
|
|
|
|
}
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
void TExchange::set(const char* val, const real& chg, exchange_type et)
|
|
|
|
{
|
|
|
|
val = DowJones.normalize_value(val, chg, et);
|
|
|
|
strncpy(_val, val, 4);
|
|
|
|
_val[3] = '\0';
|
|
|
|
_exchange = chg;
|
|
|
|
_et = et;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TExchange::set(const TRectype& rec)
|
|
|
|
{
|
2003-11-10 15:01:49 +00:00
|
|
|
const TString4 codval = rec.get("CODVAL");
|
1999-10-22 10:00:18 +00:00
|
|
|
const real chg = rec.get_real("CAMBIO");
|
|
|
|
exchange_type et = _exchange_undefined;
|
|
|
|
if (rec.exist("CONTROEURO"))
|
|
|
|
et = rec.get_bool("CONTROEURO") ? _exchange_contro : _exchange_base;
|
|
|
|
set(codval, chg, et);
|
|
|
|
}
|
|
|
|
|
|
|
|
TExchange::TExchange(const char* val, const real& chg, exchange_type et)
|
|
|
|
{
|
|
|
|
set(val, chg, et);
|
|
|
|
}
|
|
|
|
|
|
|
|
TExchange::TExchange(const TRectype& rec)
|
|
|
|
{
|
|
|
|
set(rec);
|
|
|
|
}
|
|
|
|
|
1998-05-08 12:19:34 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TCurrency
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
1998-11-03 10:27:35 +00:00
|
|
|
const TString& TCurrency::get_base_val()
|
1998-10-01 13:52:27 +00:00
|
|
|
{
|
1998-11-03 10:27:35 +00:00
|
|
|
return DowJones.get_base_val();
|
|
|
|
}
|
|
|
|
|
|
|
|
const TString& TCurrency::get_firm_val()
|
|
|
|
{
|
|
|
|
return DowJones.get_firm_val();
|
1998-10-01 13:52:27 +00:00
|
|
|
}
|
|
|
|
|
1999-05-24 13:34:11 +00:00
|
|
|
const TString& TCurrency::get_euro_val()
|
|
|
|
{
|
|
|
|
return DowJones.get_euro_val();
|
|
|
|
}
|
|
|
|
|
1998-11-03 10:27:35 +00:00
|
|
|
int TCurrency::get_base_dec(bool price)
|
1998-05-08 12:19:34 +00:00
|
|
|
{
|
1998-11-03 10:27:35 +00:00
|
|
|
return DowJones.get_dec(NULL, price);
|
1998-05-08 12:19:34 +00:00
|
|
|
}
|
|
|
|
|
1998-11-03 10:27:35 +00:00
|
|
|
int TCurrency::get_firm_dec(bool price)
|
1998-05-08 12:19:34 +00:00
|
|
|
{
|
1999-01-19 09:15:17 +00:00
|
|
|
return DowJones.get_dec(get_firm_val(), price);
|
1998-05-08 12:19:34 +00:00
|
|
|
}
|
|
|
|
|
1999-05-24 13:34:11 +00:00
|
|
|
int TCurrency::get_euro_dec(bool price)
|
|
|
|
{
|
|
|
|
return DowJones.get_dec(get_euro_val(), price);
|
|
|
|
}
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
const real& TCurrency::get_firm_change(exchange_type& ce)
|
1999-07-16 14:59:11 +00:00
|
|
|
{
|
|
|
|
return DowJones.get_change("_FIRM", ce);
|
|
|
|
}
|
|
|
|
|
|
|
|
const real& TCurrency::get_euro_change()
|
1999-10-22 10:00:18 +00:00
|
|
|
{
|
|
|
|
exchange_type dummy;
|
|
|
|
return DowJones.get_change("_EURO", dummy);
|
1999-07-16 14:59:11 +00:00
|
|
|
}
|
2000-10-03 13:45:12 +00:00
|
|
|
|
|
|
|
void TCurrency::force_firm_val(const char* val)
|
|
|
|
{
|
|
|
|
DowJones.force_firm_val(val);
|
|
|
|
}
|
1999-07-16 14:59:11 +00:00
|
|
|
|
2001-04-30 15:04:10 +00:00
|
|
|
void TCurrency::force_cache_update()
|
|
|
|
{
|
|
|
|
DowJones.flush();
|
|
|
|
}
|
2000-10-03 13:45:12 +00:00
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
void TCurrency::force_value(const char* newval, const real& newchange, exchange_type newet)
|
|
|
|
{
|
|
|
|
_chg.set(newval, newchange, newet);
|
|
|
|
}
|
1999-07-16 14:59:11 +00:00
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
void TCurrency::change_value(const TExchange& exc)
|
1998-05-08 12:19:34 +00:00
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
if (!_num.is_zero() && _chg != exc)
|
|
|
|
_num = DowJones.exchange(_num, _chg, exc, is_price());
|
|
|
|
_chg = exc;
|
1998-05-08 12:19:34 +00:00
|
|
|
}
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
void TCurrency::change_value(const char* val, const real& newchange, exchange_type to_euro)
|
1998-11-03 10:27:35 +00:00
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
const TExchange exc(val, newchange, to_euro);
|
|
|
|
change_value(exc);
|
1998-11-03 10:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int TCurrency::decimals() const
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
return DowJones.get_dec(get_value(), is_price());
|
1998-11-03 10:27:35 +00:00
|
|
|
}
|
1998-05-08 12:19:34 +00:00
|
|
|
|
|
|
|
int TCurrency::compare(const TSortable& s) const
|
|
|
|
{
|
|
|
|
const TCurrency& cur = (const TCurrency&)s;
|
1998-11-03 10:27:35 +00:00
|
|
|
if (same_value_as(cur))
|
1998-05-08 12:19:34 +00:00
|
|
|
{
|
|
|
|
return _num == cur._num ? 0 : (_num > cur._num ? +1 : -1);
|
|
|
|
}
|
|
|
|
TCurrency curr(cur);
|
1999-10-22 10:00:18 +00:00
|
|
|
curr.change_value(get_value());
|
1998-05-08 12:19:34 +00:00
|
|
|
return _num == curr._num ? 0 : (_num > curr._num ? +1 : -1);
|
|
|
|
}
|
|
|
|
|
1998-11-03 10:27:35 +00:00
|
|
|
void TCurrency::copy(const TCurrency& cur)
|
1998-05-08 12:19:34 +00:00
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
_chg = cur._chg;
|
1998-05-08 12:19:34 +00:00
|
|
|
_num = cur._num;
|
1999-10-22 10:00:18 +00:00
|
|
|
_price = cur._price;
|
1998-05-08 12:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* TCurrency::string(bool dotted) const
|
|
|
|
{
|
|
|
|
if (dotted)
|
|
|
|
{
|
1998-11-03 10:27:35 +00:00
|
|
|
TString16 picture;
|
|
|
|
picture.format(".%d", decimals());
|
|
|
|
return _num.string(picture);
|
|
|
|
}
|
2001-04-30 15:04:10 +00:00
|
|
|
return _num.stringa(0, decimals());
|
1998-11-03 10:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TCurrency& TCurrency::operator+=(const TCurrency& cur)
|
|
|
|
{
|
|
|
|
CHECK(is_price() == cur.is_price(), "Somma di pere e mele!");
|
1999-10-22 10:00:18 +00:00
|
|
|
if (!cur._num.is_zero())
|
|
|
|
{
|
|
|
|
if (same_value_as(cur))
|
|
|
|
{
|
|
|
|
_num += cur._num;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
real n = DowJones.exchange(cur._num, cur._chg, _chg, is_price());
|
|
|
|
_num += n;
|
|
|
|
}
|
|
|
|
}
|
1998-11-03 10:27:35 +00:00
|
|
|
return *this;
|
1998-05-08 12:19:34 +00:00
|
|
|
}
|
|
|
|
|
1998-11-03 10:27:35 +00:00
|
|
|
TCurrency TCurrency::operator+(const TCurrency& num) const
|
|
|
|
{
|
|
|
|
TCurrency cur(*this);
|
|
|
|
cur += num;
|
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
TCurrency& TCurrency::operator-=(const TCurrency& cur)
|
|
|
|
{
|
|
|
|
CHECK(is_price() == cur.is_price(), "Sottrazione di pere e mele!");
|
|
|
|
if (same_value_as(cur))
|
|
|
|
_num -= cur._num;
|
|
|
|
else
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
real n = DowJones.exchange(cur._num, cur._chg, _chg, is_price());
|
1998-11-03 10:27:35 +00:00
|
|
|
_num -= n;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
TCurrency TCurrency::operator-(const TCurrency& num) const
|
|
|
|
{
|
|
|
|
TCurrency cur(*this);
|
|
|
|
cur -= num;
|
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
|
1998-11-03 10:27:35 +00:00
|
|
|
TCurrency& TCurrency::operator*=(const real& num)
|
1998-10-01 13:52:27 +00:00
|
|
|
{
|
1998-11-03 10:27:35 +00:00
|
|
|
_num *= num;
|
1999-10-22 10:00:18 +00:00
|
|
|
_num.round(decimals());
|
1998-11-03 10:27:35 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
TCurrency TCurrency::operator*(const real& num) const
|
|
|
|
{
|
|
|
|
TCurrency cur(*this);
|
|
|
|
cur *= num;
|
|
|
|
return cur;
|
1998-10-01 13:52:27 +00:00
|
|
|
}
|
|
|
|
|
2000-05-05 15:25:49 +00:00
|
|
|
TCurrency TCurrency::abs() const
|
|
|
|
{
|
|
|
|
if (_num.sign() < 0)
|
|
|
|
{
|
|
|
|
TCurrency k(-_num, _chg, is_price());
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1998-11-03 10:27:35 +00:00
|
|
|
bool TCurrency::is_base_value() const
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
return get_base_val() == get_value();
|
1998-11-03 10:27:35 +00:00
|
|
|
}
|
1998-10-01 13:52:27 +00:00
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
bool TCurrency::is_firm_value() const
|
1998-05-08 12:19:34 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
return _chg.is_firm_value();
|
1998-05-08 12:19:34 +00:00
|
|
|
}
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
TCurrency::TCurrency(const real& num, const char* val, const real& exchg, exchange_type et, bool price)
|
1998-11-03 10:27:35 +00:00
|
|
|
: _num(num), _price(price)
|
1998-05-08 12:19:34 +00:00
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
force_value(val, exchg, et);
|
2000-05-05 15:25:49 +00:00
|
|
|
_num.round(decimals());
|
1998-05-08 12:19:34 +00:00
|
|
|
}
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
TCurrency::TCurrency(const real& num, const TExchange& exc, bool price)
|
|
|
|
: _num(num), _chg(exc), _price(price)
|
2000-05-05 15:25:49 +00:00
|
|
|
{
|
|
|
|
_num.round(decimals());
|
|
|
|
}
|
1999-10-22 10:00:18 +00:00
|
|
|
|
2001-04-30 15:04:10 +00:00
|
|
|
bool same_values(const char * valuea, const char * valueb)
|
|
|
|
{
|
|
|
|
if (valuea == NULL || *valuea == '\0')
|
|
|
|
valuea = TCurrency::get_firm_val();
|
|
|
|
if (valueb == NULL || *valueb == '\0')
|
|
|
|
valueb = TCurrency::get_firm_val();
|
|
|
|
|
|
|
|
return stricmp(valuea, valueb) == 0;
|
|
|
|
}
|
1999-10-22 10:00:18 +00:00
|
|
|
|
2002-10-23 14:14:55 +00:00
|
|
|
|
|
|
|
real change_currency(const real& num,
|
|
|
|
const char* fromval, const real& fromchg, exchange_type fromeuro,
|
|
|
|
const char* toval, const real& tochg, exchange_type toeuro,
|
|
|
|
int price)
|
|
|
|
{
|
|
|
|
return DowJones.exchange(num, fromval, fromchg, fromeuro, toval, tochg, toeuro, price);
|
|
|
|
}
|