24 if (letters_.find(st.
getLetter()) == letters_.end())
27 throw Exception(
"AbstractAlphabet::updateMaps_. A state with the same character code already exists! " + st.
getLetter() +
".");
28 if (nums_.find(st.
getNum()) == nums_.end())
39 alphabet_.push_back(st);
41 updateMaps_(alphabet_.size() - 1, *st);
48 if (pos > alphabet_.size())
51 if (alphabet_[pos] != 0)
52 delete alphabet_[pos];
56 updateMaps_(pos, *st);
63 map<string, size_t>::const_iterator it = letters_.find(letter);
64 if (it == letters_.end())
65 throw BadCharException(letter,
"AbstractAlphabet::getState(string): Specified base unknown",
this);
66 return *(alphabet_[it->second]);
73 map<string, size_t>::const_iterator it = letters_.find(letter);
74 if (it == letters_.end())
75 throw BadCharException(letter,
"AbstractAlphabet::getStateIndex(string): Specified base unknown",
this);
83 map<int, size_t>::const_iterator it = nums_.find(num);
84 if (it == nums_.end())
85 throw BadIntException(num,
"AbstractAlphabet::getState(int): Specified base unknown",
this);
86 return *(alphabet_[it->second]);
93 map<int, size_t>::const_iterator it = nums_.find(num);
94 if (it == nums_.end())
95 throw BadIntException(num,
"AbstractAlphabet::getStateIndex(int): Specified base unknown",
this);
103 map<string, size_t>::iterator it = letters_.find(letter);
104 if (it == letters_.end())
105 throw BadCharException(letter,
"AbstractAlphabet::getState(string): Specified base unknown",
this);
106 return *(alphabet_[it->second]);
113 map<int, size_t>::iterator it = nums_.find(num);
114 if (it == nums_.end())
115 throw BadIntException(num,
"AbstractAlphabet::getState(int): Specified base unknown",
this);
116 return *(alphabet_[it->second]);
123 if (pos > alphabet_.size())
125 return *(alphabet_[pos]);
132 if (pos > alphabet_.size())
134 return *(alphabet_[pos]);
141 return (getState(state)).getName();
148 return (getState(state)).getName();
155 return getState(state).getNum();
162 return (getState(state)).getLetter();
169 map<int, size_t>::const_iterator it = nums_.find(state);
170 if (it != nums_.end())
179 map<string, size_t>::const_iterator it = letters_.find(state);
180 if (it != letters_.end())
189 if (state1 < 0 || !isIntInAlphabet(state1))
190 throw BadIntException(state1,
"AbstractAlphabet::isResolvedIn(int, int): Specified base " + intToChar(state1) +
" is unknown.",
this);
192 if (state2 < 0 || !isIntInAlphabet(state2))
193 throw BadIntException(state2,
"AbstractAlphabet::isResolvedIn(int, int): Specified base " + intToChar(state2) +
" is unknown.",
this);
195 if (isUnresolved(state2))
196 throw BadIntException(state2,
"AbstractAlphabet::isResolvedIn(int, int): Unresolved base " + intToChar(state2),
this);
198 return state1 == state2;
205 if (!isIntInAlphabet(state))
206 throw BadIntException(state,
"AbstractAlphabet::getAlias(int): Specified base unknown.",
this);
216 if (!isCharInAlphabet(state))
217 throw BadCharException(state,
"AbstractAlphabet::getAlias(char): Specified base unknown.",
this);
228 for (
size_t i = 0; i < states.size(); ++i)
230 vector<int> tmp_s = this->getAlias(states[i]);
231 for (
size_t j = 0; j < tmp_s.size(); ++j)
239 for (
size_t i = 0; i < ve.size(); ++i)
241 if (!isIntInAlphabet(ve[i]))
242 throw BadIntException(ve[i],
"AbstractAlphabet::getGeneric(const vector<int>): Specified base unknown.",
this);
252 v = this->getUnknownCharacterCode();
262 for (
size_t i = 0; i < states.size(); ++i)
264 vector<string> tmp_s = this->getAlias(states[i]);
265 for (
size_t j = 0; j < tmp_s.size(); ++j)
273 for (
size_t i = 0; i < ve.size(); ++i)
275 if (!isCharInAlphabet(ve[i]))
276 throw BadCharException(ve[i],
"AbstractAlphabet::getAlias(const vector<string>): Specified base unknown.",
this);
295 if (intList_.size() != alphabet_.size())
297 intList_.resize(alphabet_.size());
298 charList_.resize(alphabet_.size());
299 for (
size_t i = 0; i < alphabet_.size(); ++i)
301 intList_[i] = alphabet_[i]->getNum();
302 charList_[i] = alphabet_[i]->getLetter();
312 if (charList_.size() != alphabet_.size())
314 intList_.resize(alphabet_.size());
315 charList_.resize(alphabet_.size());
316 for (
size_t i = 0; i < alphabet_.size(); ++i)
318 intList_[i] = alphabet_[i]->getNum();
319 charList_[i] = alphabet_[i]->getLetter();
330 for (
size_t i = 0; i < alphabet_.size(); ++i)
333 if (!isGap(alphabet_[i]->getLetter()) and !isUnresolved(alphabet_[i]->getLetter()))
334 charList_.push_back(alphabet_[i]->getLetter());
std::string getName(const std::string &state) const
Get the complete name of a state given its string description.
const std::vector< int > & getSupportedInts() const
void updateMaps_(size_t pos, const AlphabetState &st)
Update the private maps letters_ and nums_ when adding a state.
virtual AlphabetState & getStateAt(size_t stateIndex)
Get a state at a position in the alphabet_ vector.
const std::vector< std::string > & getResolvedChars() const
const AlphabetState & getState(const std::string &letter) const
Get a state by its letter.
virtual void setState(size_t pos, AlphabetState *st)
Set a state in the Alphabet.
std::string intToChar(int state) const
Give the string description of a state given its int description.
const std::vector< std::string > & getSupportedChars() const
size_t getStateIndex(int state) const
virtual void registerState(AlphabetState *st)
Add a state to the Alphabet.
int charToInt(const std::string &state) const
Give the int description of a state given its string description.
bool isResolvedIn(int state1, int state2) const
Tells if a given (potentially unresolved) state can be resolved in another resolved state.
int getGeneric(const std::vector< int > &states) const
Get the generic state that match a set of states.
std::vector< int > getAlias(int state) const
Get all resolved states that match a generic state.
bool isIntInAlphabet(int state) const
Tell if a state (specified by its int description) is allowed by the the alphabet.
bool isCharInAlphabet(const std::string &state) const
Tell if a state (specified by its string description) is allowed by the the alphabet.
This is the base class to describe states in an Alphabet.
const std::string & getLetter() const
Get the letter(s) corresponding to the state.
int getNum() const
Get the state's number.
An alphabet exception thrown when trying to specify a bad char to the alphabet.
An alphabet exception thrown when trying to specify a bad int to the alphabet.
Exception thrown in case no character is available for a certain state in an alphabet.
std::string toString(T t)
This alphabet is used to deal NumericAlphabet.