concordia-library/concordia/word_map.hpp
2015-05-01 14:52:53 +02:00

56 lines
1.2 KiB
C++

#ifndef WORD_MAP_HDR
#define WORD_MAP_HDR
#include <string>
#include <map>
#include "concordia/concordia_exception.hpp"
#include "concordia/common/config.hpp"
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/map.hpp>
/*!
Class representing dictionary for word to integer encoding.
*/
class WordMap {
public:
/*!
Constructor.
*/
explicit WordMap() throw(ConcordiaException);
/*! Destructor.
*/
virtual ~WordMap();
/*!
Gets the integer code of a token. If the token is found in
the dictionary, the dictionary code is returned. If not,
the word is added to the dictionary and its newly created
code is returned.
\param word token to generate the code
\returns code of the token
*/
INDEX_CHARACTER_TYPE getWordCode(const std::string & word)
throw(ConcordiaException);
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
ar & _map;
ar & _nextFree;
}
std::map<std::string, INDEX_CHARACTER_TYPE> _map;
INDEX_CHARACTER_TYPE _nextFree;
};
#endif