From: <bl...@us...> - 2003-04-29 22:02:59
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv29682/src/rftaparser Modified Files: KeyedString.h Log Message: * added getKeyedRange() * refactored a bit Index: KeyedString.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/KeyedString.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** KeyedString.h 28 Apr 2003 11:05:20 -0000 1.2 --- KeyedString.h 29 Apr 2003 22:02:42 -0000 1.3 *************** *** 9,12 **** --- 9,13 ---- #include <map> #include <string> + #include <rfta/parser/SourceRange.h> *************** *** 18,37 **** 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; 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_; ! 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_; }; --- 19,54 ---- public: KeyedString& operator<< (std::string characters); + operator std::string () const; + KeyedString& addKeyed (std::string key , std::string word ); + std::string asString() const; + + SourceRange getKeyedRange( const std::string &key, int index ) const; + 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_; ! typedef std::map<std::string,std::vector<int> > WordIndexes; ! WordIndexes wordIndex_; ! WordIndexes wordLen_; ! typedef std::map<std::string,std::vector<std::string> > Words; ! Words word_; }; *************** *** 54,62 **** } 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; } --- 71,87 ---- } + + inline SourceRange + KeyedString::getKeyedRange( const std::string &key, int index ) const + { + return SourceRange( getKeyedIndex( key, index), getKeyedLen( key, index ) ); + } + + inline std::vector<int> KeyedString::getKeyedIndex(std::string key) const { ! WordIndexes::const_iterator it = wordIndex_.find(key); ! if (it == wordIndex_.end()) ! return std::vector<int>(); return (*it).second; } *************** *** 64,69 **** 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; --- 89,93 ---- inline std::vector<int> KeyedString::getKeyedLen(std::string key) const { ! WordIndexes::const_iterator it = wordLen_.find(key); if (it == wordLen_.end()) return std::vector<int>(); return (*it).second; *************** *** 72,101 **** 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]; } --- 96,118 ---- inline int KeyedString::getKeyedIndex(std::string key, int index) const { ! WordIndexes::const_iterator it = wordIndex_.find(key); ! if (it == wordIndex_.end()) ! throw std::logic_error("No string registered for key:" + key); ! return (*it).second.at(index); } inline int KeyedString::getKeyedLen(std::string key, int index) const { ! WordIndexes::const_iterator it = wordLen_.find(key); ! if (it == wordLen_.end()) throw std::logic_error("No string registered for key:" + key); ! return (*it).second.at(index); } inline std::string KeyedString::getWord(std::string key, int index) const { ! Words::const_iterator it = word_.find(key); if (it == word_.end()) ! throw std::logic_error("No string registered for key:" + key); ! return it->second.at(index); } |