campo-sirio/include/currency.h
alex 6c73d4919e Patch level : xx.7.054
Files correlati     :
Ricompilazione Demo : [ ]
Commento            :
Riportata la verione 1.7 patch 054 aga sul main trunk.


git-svn-id: svn://10.65.10.50/trunk@9656 c028cbd2-c16b-5b4b-a496-9718f37d4682
2001-04-30 15:04:10 +00:00

142 lines
5.5 KiB
C++
Executable File

#ifndef __CURRENCY_H
#define __CURRENCY_H
#ifndef __REAL_H
#include <real.h>
#endif
#ifndef __RECTYPES_H
class TRectype;
#endif
enum exchange_type { _exchange_base, _exchange_contro, _exchange_undefined };
class TExchange : public TSortable
{
char _val[4]; // Codice valuta
real _exchange; // Cambio personalizzato
exchange_type _et;// Cambio normale o contro euro
protected:
void copy(const TExchange& exc);
public:
virtual int compare(const TSortable& obj) const;
bool same_value_as(const TExchange& exc) const;
TExchange& operator=(const TExchange& exc) { copy(exc); return *this; }
TExchange& operator=(const TRectype& rec) { set(rec); return *this; }
void set(const char* val = NULL, const real& exc = ZERO, exchange_type et = _exchange_undefined);
void set(const TRectype& rec);
exchange_type get_type() const { return _et; }
bool is_firm_value() const;
bool is_euro_value() const;
const char* get_value() const { return _val; }
const real& get_change(exchange_type& et) const;
real get_base_change() const;
real get_contro_change() const;
TExchange(const char* val = NULL, const real& exc = ZERO, exchange_type et = _exchange_undefined);
TExchange(const TExchange& exc) { copy(exc); }
TExchange(const TRectype& rec);
virtual ~TExchange() { }
};
class TCurrency : public TSortable
{
TExchange _chg; // Cambio
real _num; // Valore dell'importo
bool _price; // Prezzo unitario o no
protected:
virtual int compare(const TSortable& s) const;
void copy(const TCurrency& cur);
public:
static const TString& get_base_val();
static const TString& get_firm_val();
static const TString& get_euro_val();
static int get_base_dec(bool price = FALSE);
static int get_firm_dec(bool price = FALSE);
static int get_euro_dec(bool price = FALSE);
static const real& get_firm_change(exchange_type& ce);
static const real& get_euro_change();
// serve per la personalizzazione cgp4, per stampare il bilancio in euro
static void force_firm_val(const char* val);
static void force_cache_update(); // Azzeramento cache
void set_price(bool p) { _price = p; }
bool is_price() const { return _price; }
void force_value(const char* newval, const real& newchange = ZERO, exchange_type et = _exchange_undefined);
void change_value(const TExchange& exc);
void change_value(const char* newval, const real& newchange = ZERO, exchange_type et = _exchange_undefined);
void change_to_base_val() { change_value(get_base_val()); }
void change_to_firm_val() { change_value(get_firm_val()); }
void change_to_euro_val() { change_value(get_euro_val()); }
const char* get_value() const { return _chg.get_value(); }
bool is_base_value() const;
bool is_firm_value() const;
bool same_value_as(const TCurrency& cur) const { return _chg.same_value_as(cur._chg); }
void set_num(const real& num) { _num = num; _num.round(decimals()); }
const real& get_num() const { return _num; }
void set_exchange(const TExchange& exc) { _chg = exc; }
const TExchange& get_exchange() const { return _chg; }
const real& get_change(exchange_type& et) const { return _chg.get_change(et); }
real get_base_change() const { return _chg.get_base_change(); }
real get_contro_change() const { return _chg.get_contro_change(); }
const TCurrency& operator=(const TCurrency& cur) { copy(cur); return *this; }
TCurrency& operator += (const TCurrency& num);
TCurrency operator - (const TCurrency& num) const;
TCurrency& operator -= (const TCurrency& num);
TCurrency operator + (const TCurrency& num) const;
TCurrency& operator *= (const real& num);
TCurrency operator * (const real& num) const;
TCurrency& operator /= (const real& num);
TCurrency operator / (const real& num) const;
TCurrency operator - () const { TCurrency c(*this); c._num = -c._num; return c; }
bool is_zero() const { return _num.is_zero(); }
int sign() const { return _num.sign(); }
TCurrency abs() const;
const char* string(bool dotted = FALSE) const;
void read(const TRectype& rec, const char* field, const char *val = NULL, const char *exchange = NULL, const char* et = NULL);
void write(TRectype& rec, const char* field, const char *val = NULL, const char *exchange = NULL, const char* et = NULL, bool forceval = FALSE) const;
int decimals() const;
TCurrency(bool price = FALSE) : _price(price) { }
TCurrency(const TCurrency& cur) { copy(cur); }
TCurrency(const real& num, const char* val = "", const real& exchg = ZERO, exchange_type et = _exchange_undefined, bool price = FALSE);
TCurrency(const real& num, const TExchange& chg, bool price = FALSE);
virtual ~TCurrency() { }
};
class TPrice : public TCurrency
{
public:
const TPrice& operator=(const TPrice& cur) { copy(cur); return *this; }
TPrice() : TCurrency(TRUE) { }
TPrice(const TPrice& price) { copy(price); }
TPrice(const real& num, const char* val = "", const real& exc = ZERO, exchange_type ext = _exchange_undefined)
: TCurrency(num, val, exc, ext, TRUE) { }
virtual ~TPrice() { }
};
inline bool is_firm_value(const char * value) { return value == NULL || *value == '\0' || TCurrency::get_firm_val() == value;}
inline bool is_true_value(const char * value) { return !is_firm_value(value);}
inline bool is_euro_value(const char * value) { return (value && *value) ? TCurrency::get_euro_val() == value : TCurrency::get_euro_val() == TCurrency::get_firm_val();}
bool same_values(const char * valuea, const char * valueb);
#endif