00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "stock.h"
00019 #include "config.h"
00020
00024 Stock::Stock() {
00025 }
00026
00036 Stock::Stock(const string & name, const string & wkn, const string & buyingDate,
00037 const int & amount, const float & buyingRate, const float & purchaseCost,
00038 const float & currentMarketPrice) {
00039 Stock::name = name;
00040 Stock::wkn = wkn;
00041 Stock::buyingDate = buyingDate;
00042 Stock::amount = amount;
00043 Stock::buyingRate = buyingRate;
00044 Stock::purchaseCost = purchaseCost;
00045 Stock::currentMarketPrice = currentMarketPrice;
00046 Stock::currentMarketPriceDayBefore = buyingRate;
00047 #ifdef DEBUG
00048 cout << name.c_str() << " " << wkn.c_str() << " " << amount << " " << buyingRate << " " << purchaseCost << endl;
00049 #endif
00050 }
00051
00062 Stock::Stock(const string & name, const string & wkn, const string & buyingDate,
00063 const int & amount, const float & buyingRate, const float & purchaseCost,
00064 const float & currentMarketPrice, const vector <float> & values) {
00065 Stock::name = name;
00066 Stock::wkn = wkn;
00067 Stock::buyingDate = buyingDate;
00068 Stock::amount = amount;
00069 Stock::buyingRate = buyingRate;
00070 Stock::purchaseCost = purchaseCost;
00071 float f;
00072 for (int i = 0; i < values.size(); i++) {
00073 f = values[i];
00074 Stock::values.push_back(f);
00075 }
00076 Stock::currentMarketPrice = currentMarketPrice;
00077 if (Stock::values.size() != 0) Stock::currentMarketPriceDayBefore = Stock::values[Stock::values.size()-1];
00078 else Stock::currentMarketPriceDayBefore = buyingRate;
00079 #ifdef DEBUG
00080 cout << name.c_str() << " " << wkn.c_str() << " " << amount << " " << buyingRate << " " << purchaseCost << endl;
00081 #endif
00082 }
00083
00087 Stock::Stock(const Stock &stock) {
00088 #ifdef DEBUG
00089 cout << "Stock:: CopyConstructor" << endl;
00090 #endif
00091 name = stock.getName();
00092 wkn = stock.getWkn();
00093 buyingDate = stock.getBuyingDate();
00094 amount = stock.getAmount();
00095 buyingRate = stock.getBuyingRate();
00096 purchaseCost = stock.getPurchaseCost();
00097 currentMarketPrice = stock.getCurrentMarketPrice();
00098 currentMarketPriceDayBefore = stock.getCurrentMarketPriceDayBefore();
00099 values = stock.getValuesVector();
00100 }
00101
00102
00103
00104
00108 Stock::~Stock() {
00109 #ifdef DEBUG
00110 cout << "deleting stock" << endl;
00111 #endif
00112 values.clear();
00113 this->detachAllObservers();
00114 }
00115
00119 string Stock::getName() const {
00120 return name;
00121 }
00122
00126 string Stock::getWkn() const {
00127 return wkn;
00128 }
00129
00133 string Stock::getBuyingDate() const {
00134 return buyingDate;
00135 }
00136
00140 int Stock::getAmount() const {
00141 return amount;
00142 }
00143
00147 float Stock::getBuyingRate() const {
00148 return buyingRate;
00149 }
00150
00154 float Stock::getPurchaseCost() const {
00155 return purchaseCost;
00156 }
00157
00161 float Stock::getCurrentMarketPrice() const {
00162 return currentMarketPrice;
00163 }
00164
00165
00169 float Stock::getCurrentMarketPriceDayBefore() const {
00170 return currentMarketPriceDayBefore;
00171 }
00172
00176 vector <float> Stock::getValuesVector() const {
00177 return values;
00178 }
00179
00183 void Stock::setName(const string & name) {
00184 Stock::name = name;
00185 notify();
00186 }
00187
00191 void Stock::setWkn(const string & wkn) {
00192 Stock::wkn = wkn;
00193 notify();
00194 }
00195
00199 void Stock::setBuyingDate(const string & buyingDate) {
00200 Stock::buyingDate = buyingDate;
00201 notify();
00202 }
00203
00207 void Stock::setAmount(const int & amount) {
00208 Stock::amount = amount;
00209 notify();
00210 }
00211
00215 void Stock::setBuyingRate(const float & buyingRate) {
00216 Stock::buyingRate = buyingRate;
00217 notify();
00218 }
00219
00223 void Stock::setPurchaseCost(const float & purchaseCost) {
00224 Stock::purchaseCost = purchaseCost;
00225 notify();
00226 }
00227
00231 void Stock::setCurrentMarketPrice(const float & currentMarketPrice) {
00232 Stock::currentMarketPrice = currentMarketPrice;
00233 notify();
00234 }
00235
00239 void Stock::setCurrentMarketPriceDayBefore(const float & currentMarketPriceDayBefore) {
00240 Stock::currentMarketPriceDayBefore = currentMarketPriceDayBefore;
00241 notify();
00242 }
00243
00249 int operator!=(const Stock &x, const Stock &y) {
00250 #ifdef DEBUG
00251 cout << "Stock::Operator != is called" << endl;
00252 #endif
00253 if (x.getName() != y.getName()) return 1;
00254 if (x.getWkn() != y.getWkn()) return 1;
00255 if (x.getBuyingDate() != y.getBuyingDate()) return 1;
00256 if (x.getBuyingRate() != y.getBuyingRate()) return 1;
00257 if (x.getPurchaseCost() != y.getPurchaseCost()) return 1;
00258 if (x.getCurrentMarketPrice() != y.getCurrentMarketPrice()) return 1;
00259 return 0;
00260 }
00261
00267 int operator==(const Stock &x, const Stock &y) {
00268 #ifdef DEBUG
00269 cout << "Stock::Operator == is called" << endl;
00270 #endif
00271 if (x.getName() != y.getName()) return 0;
00272 if (x.getWkn() != y.getWkn()) return 0;
00273 if (x.getBuyingDate() != y.getBuyingDate()) return 0;
00274 if (x.getBuyingRate() != y.getBuyingRate()) return 0;
00275 if (x.getPurchaseCost() != y.getPurchaseCost()) return 0;
00276 if (x.getCurrentMarketPrice() != y.getCurrentMarketPrice()) return 0;
00277 return 1;
00278 }
00279
00280
00286 bool operator<(const Stock &x, const Stock &y) {
00287 #ifdef DEBUG
00288 cout << "Stock::Operator < is called" << endl;
00289 #endif
00290 if (x.getName() != y.getName()) return x.getName() < y.getName();
00291 if (x.getWkn() != y.getWkn()) return x.getWkn() < y.getWkn();
00292 if (x.getBuyingDate() != y.getBuyingDate()) return x.getBuyingDate() < y.getBuyingDate();
00293 if (x.getBuyingRate() != y.getBuyingRate()) return x.getBuyingRate() < y.getBuyingRate();
00294 if (x.getPurchaseCost() != y.getPurchaseCost()) return x.getPurchaseCost() < y.getPurchaseCost();
00295 return x.getCurrentMarketPrice() < y.getCurrentMarketPrice();
00296 }