00001 /* 00002 * Copyright (c) 2010 Ferruccio Vitale <unixo@devzero.it> 00003 * All rights reserved. 00004 * 00005 * $Id: Product.h 75 2010-09-13 09:25:53Z unixo $ 00006 */ 00007 00008 #ifndef __PRODUCT_H__ 00009 #define __PRODUCT_H__ 00010 00011 #include "common.h" 00012 #include "ManagedObject.h" 00013 #include "Category.h" 00014 00015 #define KEY_PRD_PID "pid" 00016 #define KEY_PRD_CID "cid" 00017 #define KEY_PRD_NAME "name" 00018 #define KEY_PRD_DESCR "descr" 00019 #define KEY_PRD_PRICE "price" 00020 #define KEY_PRD_AVAILABILITY "availability" 00021 #define KEY_PRD_DELETED "deleted" 00022 00023 using namespace std; 00024 using namespace mysqlpp; 00025 00026 // forward declaration 00027 class ProductProxy; 00028 00041 class Product : public ManagedObject 00042 { 00043 public: 00044 Product(); 00045 Product(Row & aRow); 00046 ~Product(); 00047 00048 static Product * factory(string aName, int aCid, float aPrice, 00049 string aDescr = "empty", int aQty = 0, 00050 bool isDel = false); 00051 static Product * productByID(int aPid); 00052 static void showCompatibleProducts(int aPid); 00053 00054 auto_ptr<Category> getCategory(); 00055 float getPrice(); 00056 int getAvailability(); 00057 string primaryKey(); 00058 00059 friend ostream& operator<<(ostream &, Product &); 00060 }; 00061 00062 00073 class ProductProxy 00074 { 00075 private: 00076 Product *_theProduct; 00077 int _pid; 00078 00079 protected: 00080 Product *getProduct() throw (InvalidArgument); 00081 00082 public: 00083 ProductProxy(const ProductProxy & pp); 00084 ProductProxy(int aPid); 00085 ~ProductProxy(); 00086 00087 static vector<ProductProxy *> & catalog(int aCid = 0); 00088 00089 auto_ptr<Category> getCategory(); 00090 int uniqueID() const; 00091 float getPrice(); 00092 string getName(); 00093 string getDescr(); 00094 int getAvailability(); 00095 bool isValid(); 00096 00097 ProductProxy & operator=(const ProductProxy&); 00098 friend ostream& operator<<(ostream &, ProductProxy &); 00099 }; 00100 00101 00102 #endif /* __PRODUCT_H__ */