From: <net...@us...> - 2003-04-28 02:45:05
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv27286/src/rftaparser Added Files: KeyedString.h Log Message: -- Util class for testing --- NEW FILE: KeyedString.h --- // ////////////////////////////////////////////////////////////////////////// // (c)Copyright 2003, Andre Baresel // Created: 2003/04/28 // ////////////////////////////////////////////////////////////////////////// #ifndef RFTA_KEYEDSTRING_H #define RFTA_KEYEDSTRING_H #include <vector> #include <map> #include <string> namespace Refactoring { namespace Testing { class KeyedString { public: KeyedString& operator<< (std::string characters); operator std::string () const; KeyedString& addKeyed (std::string key , std::string word ); std::string asString() const; std::vector<int> getKeyedIndex(std::string key) const; std::vector<int> getKeyedLen(std::string key) const; std::string getWord(std::string key, int index) const; int length() const; protected: std::string sequence_; std::map<std::string,std::vector<int> > wordIndex_; std::map<std::string,std::vector<int> > wordLen_; std::map<std::string,std::vector<std::string> > word_; }; // INLINED MEMBERS: inline KeyedString& KeyedString::operator<<(std::string characters) { sequence_.append(characters); return *this; } inline KeyedString::operator std::string() const { return sequence_; } inline std::string KeyedString::asString() const { return sequence_; } inline std::vector<int> KeyedString::getKeyedIndex(std::string key) const { std::map<std::string,std::vector<int> >::const_iterator it; it = wordIndex_.find(key); if (it == wordIndex_.end()) return std::vector<int>(); return (*it).second; } inline std::vector<int> KeyedString::getKeyedLen(std::string key) const { std::map<std::string,std::vector<int> >::const_iterator it; it = wordLen_.find(key); if (it == wordLen_.end()) return std::vector<int>(); return (*it).second; } inline std::string KeyedString::getWord(std::string key, int index) const { std::map<std::string,std::vector<std::string> >::const_iterator it; it = word_.find(key); if (it == word_.end()) return std::string(); return ((*it).second)[index]; } inline KeyedString& KeyedString::addKeyed(std::string key,std::string word) { wordIndex_[key].push_back(sequence_.length()); wordLen_[key].push_back(word.length()); word_[key].push_back(word); sequence_.append(word); return *this; } inline int KeyedString::length() const { return sequence_.length(); } } // namespace Testing } // namespace Refactoring #endif // RFTA_KEYEDSTRING_H |