Deck.h

Go to the documentation of this file.
00001 /*
00002  * carddeck is an implementation of a deck of cards.
00003  *
00004  * Copyright (C) 2008 Thomas Repantis <trep@cs.ucr.edu>
00005  * 
00006  * This file is part of carddeck.
00007  *
00008  * carddeck is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 3 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * carddeck is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with carddeck.  If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 //
00026 //
00027 
00028 #ifndef __DECK_H__
00029 #define __DECK_H__
00030 
00031 #include <iostream>
00032 #include <vector>
00033 #include <string>
00034 #include <algorithm>
00035 #include "Exception.h"
00036 #include "Card.h"
00037 #include "NumberCard.h"
00038 #include "LetterCard.h"
00039 #include "CardFactory.h"
00040 
00041 namespace deck {
00042 
00044   class Deck {
00045   public:
00047     enum DeckType { 
00048       STANDARD = 1 
00049     };
00050 
00051     Deck(enum DeckType = STANDARD) throw(error::Exception);
00053     
00054     virtual ~Deck();
00056     
00057     Card *deal() throw(error::Exception);
00059 
00060     void shuffle();
00062 
00063     void reset();
00065 
00066     std::string view() const;
00068 
00069   private:
00071     void clear_();
00072 
00074     void createCards_(enum Card::SuitType suit);
00075 
00076     std::vector<Card *> cards_;
00078     // Storing the cards in a vector gives constant time access of random 
00079     // elements for shuffling, and constant amortized time removal of the 
00080     // last element for dealing.  
00081 
00082     enum DeckType type_;
00084 
00085     CardFactory<NumberCard> numberCardFactory_;
00087     
00088     CardFactory<LetterCard> letterCardFactory_;
00090 
00092     static const int STANDARD_CARDS_NUM_ = 52;
00093   };
00094 
00095   inline std::ostream &operator<<(std::ostream &out, const Deck &deck) {
00096     return out << deck.view();
00097   }
00099   
00100 }
00101 
00102 #endif

Generated on Thu Mar 6 09:44:38 2008 for carddeck by  doxygen 1.5.3