// // card.h // cards-proof // // Created by Ethan Miller on 3/9/12. // #ifndef cards_proof_card_h #define cards_proof_card_h #include #include #include #include "Cost.h" class card { public: card() { string_attributes_ = default_strings; numeric_attributes_ = default_ints; } card( std::string name ) { string_attributes_["name"] = name; } std::string name() { return string_attributes_["name"]; } cost manacost() const { return cost_; } // get methods working on maps do not create keys if the key // does not exist std::string get_string_attribute( std::string attribute); int get_numeric_attribute( std::string attribute); // set methods working on maps do not create keys if the key // does not exist. Is generic so people can just set both maps // without worrying about implementation. template void set_attribute(std::string key, t new_value) { // This isn't very efficient (does the search twice) // TODO make more efficient. if (string_attributes_.find(key) != string_attributes_.end() ) { string_attributes_[key] = new_value; } } static void set_default(std::istream & in); private: // Implementing attributes as maps to allow for different games // to have different attributes. Needed quick random access, and // access by key. Map chosen over vectors or lists. std::map string_attributes_; std::map numeric_attributes_; // cost_ is own data member because most things will have a cost // and because Cost is its own class, so can't be in a map with // the rest. class cost cost_; static std::map default_strings; static std::map default_ints; static bool default_card_is_set; }; std::istream & operator>>( std::istream & in, card & c ); #endif