Basket Class Reference

The class Basket represents the basket of the customer who wants to buy one or more products: it's intended to be used by User class only. More...

#include <Basket.h>

Inheritance diagram for Basket:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 Basket ()
 Default constructor.
 ~Basket ()
 Default destructor.
bool addProduct (Product *p, int aQty=1)
 Add product to basket.
bool addProduct (ProductProxy *p, int aQty=1)
 Add product to basket.
float total () const
 Return the total cost of the basket.
void empty ()
 Empty the basket.
void removeProduct (Product *p, int aQty=1)
 Remove a product from the basket.
int itemCount ()
 Items count.

Private Member Functions

void _realAddProduct (int pid, int qty)
 Real add product.

Private Attributes

float _tot

Friends

std::ostream & operator<< (std::ostream &, Basket &)

Detailed Description

The class Basket represents the basket of the customer who wants to buy one or more products: it's intended to be used by User class only.


Constructor & Destructor Documentation

Basket::Basket (  ) 

Default constructor.

References _tot, and LOG_CTOR.

Basket::~Basket (  ) 

Default destructor.

References LOG_DTOR.


Member Function Documentation

void Basket::_realAddProduct ( int  pid,
int  qty 
) [private]

Real add product.

This function must not be used directly, but only called by addProduct() - that's why it's private. It adds the chosen product and requested quantity to the map, by first looking for an equal entry: in this case only quantity is increased.

Parameters:
[in] pid Product ID to add
[in] qty Requested quantity

Referenced by addProduct().

bool Basket::addProduct ( ProductProxy p,
int  aQty = 1 
)

Add product to basket.

Add a product to the basket. It's possibile to specify how many pieces of the same product. A check against product availability is done before adding it to the basket.

Parameters:
[in] p An instance to ProductProxy
[in] aQty How many pieces of the same product (default is 1)
Returns:
True if successful, false otherwise

References _realAddProduct(), _tot, ProductProxy::getAvailability(), ProductProxy::getPrice(), and ProductProxy::uniqueID().

bool Basket::addProduct ( Product p,
int  aQty = 1 
)

Add product to basket.

Add a product to the basket. It's possibile to specify how many pieces of the same product. A check against product availability is done before adding it to the basket.

Parameters:
[in] p An instance to Product
[in] aQty How many pieces of the same product (default is 1)
Returns:
True if successful, false otherwise

References _realAddProduct(), _tot, Product::getAvailability(), Product::getPrice(), ManagedObject::intForKey(), and Product::primaryKey().

Referenced by UserMenu::placeNewOrder().

void Basket::empty (  ) 

Empty the basket.

References _tot.

int Basket::itemCount (  ) 

Items count.

Return the number of item currently present in the basket.

Returns:
Number of items

Referenced by UserMenu::placeNewOrder().

void Basket::removeProduct ( Product p,
int  aQty = 1 
)

Remove a product from the basket.

The function looks for the given product and decreases the quantity: if this value goes down below or equal to zero, the product is removed; otherwise only quantity is decreased.

Parameters:
[in] p Pointer to Product to be removed
[in] aQty Requested quantity to remove

References ManagedObject::intForKey(), and Product::primaryKey().

float Basket::total (  )  const

Return the total cost of the basket.

Returns:
The total, expressed as float

References _tot.

Referenced by Order::create(), and UserMenu::placeNewOrder().


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  aStream,
Basket p 
) [friend]

Member Data Documentation

float Basket::_tot [private]

Referenced by addProduct(), Basket(), empty(), and total().


The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.2