From: <net...@us...> - 2003-04-28 11:05:23
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv10023/src/rftaparser Modified Files: KeyedString.h Log Message: -- code cleanup Index: KeyedString.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/KeyedString.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** KeyedString.h 28 Apr 2003 02:45:01 -0000 1.1 --- KeyedString.h 28 Apr 2003 11:05:20 -0000 1.2 *************** *** 23,28 **** --- 23,32 ---- std::vector<int> getKeyedIndex(std::string key) const; std::vector<int> getKeyedLen(std::string key) const; + int getKeyedIndex(std::string key,int index) const; + int getKeyedLen(std::string key,int index) const; std::string getWord(std::string key, int index) const; int length() const; + KeyedString& setKeyStart(std::string key); + KeyedString& setKeyEnd(std::string key); protected: std::string sequence_; *************** *** 66,74 **** } 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]; } --- 70,100 ---- } + inline int KeyedString::getKeyedIndex(std::string key, int index) const + { + std::map<std::string,std::vector<int> >::const_iterator it; + it = wordIndex_.find(key); + if (it == wordIndex_.end()) throw std::logic_error("No string registered for this key."); + if ((*it).second.size()<index) throw std::logic_error("Index out of range."); + return (*it).second[index]; + } + + inline int KeyedString::getKeyedLen(std::string key, int index) const + { + std::map<std::string,std::vector<int> >::const_iterator it; + it = wordLen_.find(key); + if (it == wordLen_.end()) throw std::logic_error("No string registered for this key."); + if ((*it).second.size()<index) throw std::logic_error("Index out of range."); + return (*it).second[index]; + } + 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()) ! throw std::logic_error("No string registered for this key."); ! if ((*it).second.size() < index) ! throw std::logic_error("Index out of range."); ! return ((*it).second)[index]; } *************** *** 86,89 **** --- 112,135 ---- { return sequence_.length(); + } + + inline KeyedString& KeyedString::setKeyStart(std::string key) + { + wordIndex_[key].push_back(sequence_.length()); + wordLen_[key].push_back(0); + word_[key].push_back(""); + return *this; + } + + inline KeyedString& KeyedString::setKeyEnd(std::string key) + { + std::vector<int>& v1_ref = wordIndex_[key]; + std::vector<int>& v2_ref = wordLen_[key]; + if ( v1_ref.empty() || v2_ref.empty() || v2_ref.size() != v1_ref.size() ) + throw std::logic_error("Key was not initialized correctly."); + + int idx = v1_ref.size()-1; + v2_ref[idx] = sequence_.length() - v1_ref[idx]; + return *this; } |