#ifndef CONFIG__H #define CONFIG__H #include <memory> #include <string> #include <vector> #include <boost/flyweight.hpp> #include <boost/circular_buffer.hpp> #include "util.hpp" class Config { protected : static constexpr const char * EOSColName = "EOS"; static constexpr const char * EOSSymbol1 = "1"; static constexpr const char * EOSSymbol0 = "0"; static constexpr int nbHypothesesMax = 1; public : using String = boost::flyweight<std::string>; using Utf8String = boost::flyweight<util::utf8string>; using ValueIterator = std::vector<String>::iterator; using ConstValueIterator = std::vector<String>::const_iterator; private : std::vector<String> lines; public : const Utf8String & rawInput; std::size_t wordIndex{0}; std::size_t characterIndex{0}; String state{"NONE"}; boost::circular_buffer<String> history{10}; protected : Config(const Utf8String & rawInput); public : virtual std::size_t getNbColumns() const = 0; virtual std::size_t getColIndex(const std::string & colName) const = 0; virtual bool hasColIndex(const std::string & colName) const = 0; virtual std::size_t getFirstLineIndex() const = 0; virtual const std::string & getColName(int colIndex) const = 0; std::size_t getIndexOfLine(int lineIndex) const; std::size_t getIndexOfCol(int colIndex) const; std::size_t getNbLines() const; void addLines(unsigned int nbLines); void resizeLines(unsigned int nbLines); bool has(int colIndex, int lineIndex, int hypothesisIndex) const; String & get(int colIndex, int lineIndex, int hypothesisIndex); const String & getConst(int colIndex, int lineIndex, int hypothesisIndex) const; String & getLastNotEmpty(int colIndex, int lineIndex); const String & getLastNotEmptyConst(int colIndex, int lineIndex) const; ValueIterator getIterator(int colIndex, int lineIndex, int hypothesisIndex); ConstValueIterator getConstIterator(int colIndex, int lineIndex, int hypothesisIndex) const; public : virtual ~Config() {} void print(FILE * dest) const; void printForDebug(FILE * dest) const; bool has(const std::string & colName, int lineIndex, int hypothesisIndex) const; String & get(const std::string & colName, int lineIndex, int hypothesisIndex); const String & getConst(const std::string & colName, int lineIndex, int hypothesisIndex) const; String & getLastNotEmpty(const std::string & colName, int lineIndex); const String & getLastNotEmptyConst(const std::string & colName, int lineIndex) const; bool hasLetter(int letterIndex) const; util::utf8char getLetter(int letterIndex) const; void addToHistory(const std::string & transition); }; #endif