concordia-library/concordia/word_map.cpp
rjawor 4b921decae limits control
Former-commit-id: 83d90cb63b3f1447938d16010e66f4345dfe0617
2014-03-14 11:30:17 +01:00

27 lines
618 B
C++

#include "concordia/word_map.hpp"
WordMap::WordMap() throw(ConcordiaException) {
_nextFree = 0;
}
WordMap::~WordMap() {
}
INDEX_CHARACTER_TYPE WordMap::getWordCode(const string & word)
throw(ConcordiaException) {
if (_map.find(word) == _map.end()) {
if (_nextFree == INDEX_CHARACTER_TYPE_MAX_VALUE) {
throw ConcordiaException("Word map capacity limit reached!");
}
INDEX_CHARACTER_TYPE newCode = _nextFree;
_map[word] = newCode;
_nextFree++;
return newCode;
} else {
return _map[word];
}
}