1 // Filename: KeywordList.cpp 2 #include "util/HashGenerator.h" 3 #include "KeywordList.h" 4 namespace dclass // open namespace dclass 5 { 6 7 8 // empty list constructor KeywordList()9KeywordList::KeywordList() 10 { 11 } 12 13 // copy constructor KeywordList(const KeywordList & copy)14KeywordList::KeywordList(const KeywordList& copy) : 15 m_keywords(copy.m_keywords), m_keywords_by_name(copy.m_keywords_by_name) 16 { 17 } 18 19 // copy assignment operator operator =(const KeywordList & copy)20void KeywordList::operator=(const KeywordList& copy) 21 { 22 m_keywords = copy.m_keywords; 23 m_keywords_by_name = copy.m_keywords_by_name; 24 } 25 26 // has_keyword returns true if this list includes the indicated keyword, false otherwise. has_keyword(const std::string & name) const27bool KeywordList::has_keyword(const std::string &name) const 28 { 29 return (m_keywords_by_name.find(name) != m_keywords_by_name.end()); 30 } 31 32 // get_num_keywords returns the number of keywords in the list. get_num_keywords() const33size_t KeywordList::get_num_keywords() const 34 { 35 return m_keywords.size(); 36 } 37 38 // get_keyword returns the nth keyword in the list. get_keyword(unsigned int n) const39const std::string& KeywordList::get_keyword(unsigned int n) const 40 { 41 return m_keywords[n]; 42 } 43 44 // has_matching_keywords returns true if this list has the same keywords as the other list, 45 // false if some keywords differ. Order is not considered important. has_matching_keywords(const KeywordList & other) const46bool KeywordList::has_matching_keywords(const KeywordList& other) const 47 { 48 return m_keywords_by_name == other.m_keywords_by_name; 49 } 50 51 // copy_keywords replaces this keyword list with those from the other list. copy_keywords(const KeywordList & other)52void KeywordList::copy_keywords(const KeywordList& other) 53 { 54 (*this) = other; 55 } 56 57 // add_keyword adds the indicated keyword to the list. add_keyword(const std::string & keyword)58bool KeywordList::add_keyword(const std::string& keyword) 59 { 60 bool inserted = m_keywords_by_name.insert(keyword).second; 61 if(inserted) { 62 m_keywords.push_back(keyword); 63 } 64 65 return inserted; 66 } 67 68 // generate_hash accumulates the properties of these keywords into the hash. generate_hash(HashGenerator & hashgen) const69void KeywordList::generate_hash(HashGenerator &hashgen) const 70 { 71 hashgen.add_int(m_keywords.size()); 72 for(auto it = m_keywords.begin(); it != m_keywords.end(); ++it) { 73 hashgen.add_string(*it); 74 } 75 } 76 77 78 } // close namespace dclass 79