Card Class Reference

#include <card.h>

List of all members.


Detailed Description

This is used to represent the properties of a general playing card.
Note:
The current assumption is that the card is a standard US or UK pack.
Todo:
Create a generic card interface.
Author:
John Schneiderman

Public Types

enum  CardColour { RED, BLACK, COLOUR_ERR }
enum  CardConstants { NUMBER_OF_SUITS = 4, NUMBER_OF_RANKS = 13 }
enum  Rank {
  ACE, TWO, THREE, FOUR,
  FIVE, SIX, SEVEN, EIGHT,
  NINE, TEN, JACK, QUEEN,
  KING, JOKER, RANK_ERR
}
enum  Suit {
  SPADES, HEARTS, CLUBS, DIAMONDS,
  NO_SUIT, SUIT_ERR
}

Public Member Functions

 Card (Rank rank, Suit suit)
 Card ()
CardColour colour () const
bool isEmpty () const
bool lessThanSuit (const Card &card) const
bool operator!= (const Card &card) const
int operator+ (const Card &card)
int operator- (const Card &card)
bool operator< (const Card &card) const
Cardoperator= (const Card &card)
bool operator== (const Card &card) const
bool operator> (const Card &card) const
Rank rank () const
void setCard (Rank rank, Suit suit)
void setCard (const QString &card)
void setRank (Rank rank)
void setSuit (Suit suit)
Suit suit () const
QString toString () const

Friends

QDebug & operator<< (QDebug &out, const Card &card)
QTextStream & operator<< (QTextStream &out, const Card &card)
ostream & operator<< (ostream &out, const Card &card)
QTextStream & operator>> (QTextStream &in, Card &card)
istream & operator>> (istream &in, Card &card)

Member Enumeration Documentation

These are the colours a card can have.

Parameters:
RED is the colour of HEARTS and DIAMONDS.
BLACK is the colour of SPADES and CLUBS.
COLOUR_ERR is a colour error.

These are constants used by this class and fellow classes.

Parameters:
NUMBER_OF_SUITS this is how many suits are in a deck.
NUMBER_OF_RANKS this is how many ranks are in a deck.

enum Card::Rank

These are the names of the available ranks for a card.

Note:
that the order of the ranks starts with ace as being low and joker highest.
Parameters:
RANK_ERR indicates an error for a rank.

enum Card::Suit

These are the names of the available suits for a card.

Note:
that the order of the suits is according to their traditional colours.
Parameters:
NO_SUIT indicates that the card contains no suit.
SUIT_ERR indicates an error for a suit.


Constructor & Destructor Documentation

Card::Card (  ) 

This constructor creates a card whose rank and suit are RANK_ERR and SUIT_ERR, respectively.

Card::Card ( Rank  rank,
Suit  suit 
)

This is constructor creates a specific card.

Parameters:
rank is the rank of the card.
suit is the suit of the card.
Exceptions:
KardsGTError if rank or suit are out of scope for their respective types.


Member Function Documentation

Card::CardColour Card::colour (  )  const

This gives the colour of the card suit.

Returns:
the colour of the card suit.

bool Card::isEmpty (  )  const

This determines if a card is empty.

Note:
We assume that a card is empty if it is missing either a suit or a rank.
Returns:
true if the card is missing its suit or rank, false elsewise.

bool Card::lessThanSuit ( const Card card  )  const

This determines if one card is less than the other by suit.

Parameters:
card is the card to determine if *this is less than.
Note:
The suits are sorted by the ordering in suit_t
Returns:
true if the suit of *this is less than card, false elsewise.

bool Card::operator!= ( const Card card  )  const

This determines if two cards are not equal to each other.

Parameters:
card is the card to compare to *this.
Returns:
true if both the suits and ranks are not the same, false elsewise.

int Card::operator+ ( const Card card  ) 

This gives the result of adding two card's rank values together.

Note:
This addition is done based on the ordering in Rank.
Parameters:
card is the card whose rank is to be added to *this's rank.
Returns:
the result of the two cards.

int Card::operator- ( const Card card  ) 

This gives the result of subtracting two card's rank values from each other.

Note:
This subtraction is done based on the ordering in Rank.
Parameters:
card is the card whose rank is to be subtracted from *this's rank.
Returns:
the result of the two cards.

bool Card::operator< ( const Card card  )  const

This determines if one card's rank is less than the another.

Note:
This comparison is done based on the ordering in Rank.
Parameters:
card is the card to determine if *this is less than.
Returns:
true if the rank of *this is less than card, false elsewise.

Card & Card::operator= ( const Card card  ) 

This sets two cards equal to each other.

Parameters:
card is the card to set *this equal to.
Returns:
*this.

bool Card::operator== ( const Card card  )  const

This determines if two cards are equal to each other.

Parameters:
card is the card to compare to *this.
Returns:
true if both the suits and ranks are the same, false elsewise.

bool Card::operator> ( const Card card  )  const

This determines if one card's rank is greater than the another.

Note:
This comparison is done based on the ordering in Rank.
Parameters:
card is the card to determine if *this is greater than.
Returns:
true if the rank of *this is greater than card, false elsewise.

Card::Rank Card::rank (  )  const

This gives the rank of the card.

Returns:
the rank of the card.

void Card::setCard ( Rank  rank,
Suit  suit 
)

This will set our card to a specific card value.

Parameters:
rank is the rank for the card.
suit is the suit for the card.
Exceptions:
KardsGTError if rank or suit are out of scope for their respective types.

void Card::setCard ( const QString &  card  ) 

This will set our card to a specific card value.

Parameters:
card is the 2 character string representing a card, based on toString().
Note:
the input is not checked for validity, use at your own risk.

void Card::setRank ( Rank  rank  ) 

This will set the rank of a the card.

Parameters:
rank is the rank to set the card to.

void Card::setSuit ( Suit  suit  ) 

This will set the suit of the card.

Parameters:
suit is the suit to set the card to.

Card::Suit Card::suit (  )  const

This gives the suit of the card.

Returns:
the suit of the card.

QString Card::toString (  )  const

This gives a human readable string representation of a card.
The format of the card is RankSuit. With one character for each, i.e. an ace of spades would be AS, and a nine of clubs would be 9C.

Returns:
the formatted card.


Friends And Related Function Documentation

QDebug& operator<< ( QDebug &  out,
const Card card 
) [friend]

This is the stream insertion for a card.

Parameters:
out is the stream to output the card to in the format of RankSuit as described in toString().
card is the card to output.
Returns:
out.

QTextStream& operator<< ( QTextStream &  out,
const Card card 
) [friend]

This is the stream insertion for a card.

Parameters:
out is the stream to output the card to in the format of RankSuit as described in toString().
card is the card to output.
Returns:
out.

ostream& operator<< ( ostream &  out,
const Card card 
) [friend]

This is the stream insertion for a card.

Parameters:
out is the stream to output the card to in the format of RankSuit as described in toString().
card is the card to output.
Returns:
out.

QTextStream& operator>> ( QTextStream &  in,
Card card 
) [friend]

This is the stream extraction for a card.

Parameters:
in is the stream to read the card from in the format of RankSuit as described in toString().
card is the card to read into.
Returns:
in.

istream& operator>> ( istream &  in,
Card card 
) [friend]

This is the stream extraction for a card.

Parameters:
in is the stream to read the card from in the format of RankSuit as described in toString().
card is the card to read into.
Returns:
in.


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

Generated on Tue Aug 12 23:24:00 2008 for KardsGT by  doxygen 1.5.5