#ifndef __CURRENCY_H #define __CURRENCY_H #ifndef __REAL_H #include #endif #ifndef __RECTYPES_H class TRectype; #endif class TCurrency : public TSortable { real _num; // Valore assoluto char _val[4]; // Codice valuta real _exchange; // Cambio personalizzato bool _price; 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 int get_base_dec(bool price = FALSE); static int get_firm_dec(bool price = FALSE); void set_price(bool p) { _price = p; } bool is_price() const { return _price; } void force_value(const char* newval, const real& newchange = ZERO); void change_value(const char* newval, const real& newchange = ZERO); void change_to_base_val() { change_value(get_base_val()); } void change_to_firm_val() { change_value(get_firm_val()); } const char* get_value() const { return _val; } bool is_base_value() const; bool same_value_as(const TCurrency& cur) const; void set_num(const real& num) { _num = num; } const real& get_num() const { return _num; } 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; const char* string(bool dotted = FALSE) const; void read(const TRectype& rec, const char* field, const char *val = NULL, const char *exchange = NULL); void write(TRectype& rec, const char* field, const char *val = NULL, const char *exchange = NULL, bool forceval = FALSE) const; int decimals() const; TCurrency(bool price = FALSE) : _price(price) { _val[0] = '\0'; } TCurrency(const TCurrency& cur) { copy(cur); } TCurrency(const real& num, const char* val = "", const real& exchg = ZERO, 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) : TCurrency(num, val, exc, TRUE) { } virtual ~TPrice() { } }; #endif