2013-11-12 22:08:37 +01:00
|
|
|
#include "concordia/word_map.hpp"
|
2015-04-09 22:17:19 +02:00
|
|
|
#include <climits>
|
2013-11-12 22:08:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
WordMap::WordMap() throw(ConcordiaException) {
|
|
|
|
_nextFree = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
WordMap::~WordMap() {
|
|
|
|
}
|
|
|
|
|
2015-04-15 14:14:10 +02:00
|
|
|
INDEX_CHARACTER_TYPE WordMap::getWordCode(const std::string & word)
|
2014-03-14 11:30:17 +01:00
|
|
|
throw(ConcordiaException) {
|
2013-11-14 15:44:50 +01:00
|
|
|
if (_map.find(word) == _map.end()) {
|
2014-03-14 11:30:17 +01:00
|
|
|
if (_nextFree == INDEX_CHARACTER_TYPE_MAX_VALUE) {
|
2014-04-29 14:46:04 +02:00
|
|
|
throw ConcordiaException("Word map capacity limit reached!");
|
2014-03-14 11:30:17 +01:00
|
|
|
}
|
2013-12-06 22:29:25 +01:00
|
|
|
INDEX_CHARACTER_TYPE newCode = _nextFree;
|
2013-11-12 22:08:37 +01:00
|
|
|
_map[word] = newCode;
|
|
|
|
_nextFree++;
|
|
|
|
return newCode;
|
|
|
|
} else {
|
2013-11-14 15:44:50 +01:00
|
|
|
return _map[word];
|
2013-11-12 22:08:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|