Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Интерпретатор / _sources / MyLanguage / LookupTable
.hpp#ifndef LOOKUPTABLE_HPP_
#define LOOKUPTABLE_HPP_
#include <string>
#include <vector>
#include <map>
#include <utility>
namespace Parser_impl {
template <class T> class LookupTable {
private:
typedef std::map<std::string, int> Map;
typedef std::vector<T> Vector;
Vector items;
Map index;
public:
void clearIndex()
{
index.clear();
}
bool contains(const std::string& str)
{
Map::iterator pos = index.find(str);
if (pos != index.end() )
return true;
return false;
}
int put(const std::string& str, const T& item)
{
items.push_back(item);
index.insert(std::make_pair(str, items.size() - 1 ));
return items.size() - 1;
}
int getPos(const std::string& str)
{
return index[str];
}
T& get(const std::string& str)
{
return items[index[str]];
}
T& get(int i)
{
return items[i];
}
int getSize() const
{
return items.size();
}
};
}
#endif /*LOOKUPTABLE_HPP_*/
Соседние файлы в папке MyLanguage