00001 /* 00002 * Copyright (c) 2010 Ferruccio Vitale <unixo@devzero.it> 00003 * All rights reserved. 00004 * 00005 * $Id: Product.h 72 2010-08-03 16:43:52Z 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 00027 class ProductProxy; 00028 00029 class Product : public ManagedObject 00030 { 00031 public: 00032 Product(); 00033 Product(Row & aRow); 00034 ~Product(); 00035 00036 static Product * factory(string aName, int aCid, float aPrice, 00037 string aDescr = "empty", int aQty = 0, 00038 bool isDel = false); 00039 static Product * productByID(int aPid); 00040 static void showCompatibleProducts(int aPid); 00041 00042 auto_ptr<Category> getCategory(); 00043 float getPrice(); 00044 string primaryKey(); 00045 00046 friend ostream& operator<<(ostream &, Product &); 00047 }; 00048 00049 00060 class ProductProxy 00061 { 00062 private: 00063 Product *_theProduct; 00064 int _pid; 00065 00066 protected: 00067 Product *getProduct(); 00068 00069 public: 00070 ProductProxy(int aPid); 00071 ~ProductProxy(); 00072 00073 static vector<ProductProxy *> & catalog(int aCid = 0); 00074 00075 auto_ptr<Category> getCategory(); 00076 int uniqueID() const; 00077 float getPrice(); 00078 string getName(); 00079 string getDescr(); 00080 int getAvailability(); 00081 00082 friend ostream& operator<<(ostream &, ProductProxy &); 00083 }; 00084 00085 00086 #endif /* __PRODUCT_H__ */