本文整理汇总了C++中States::is_element方法的典型用法代码示例。如果您正苦于以下问题:C++ States::is_element方法的具体用法?C++ States::is_element怎么用?C++ States::is_element使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类States
的用法示例。
在下文中一共展示了States::is_element方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: validate
/* Name: validate
* Purpose: To find if the all of the transtions are valid.
* Operation: This method it checks that each transition is based on the class States,
Tape_Alphabet, and moves R or L.
*/
void Transition_Function::validate(const Tape_Alphabet &tape_alphabet, States states, bool & valid){
// Prevent two transitions from having the same source_state and Read_Character
for (unsigned int i = 0; i < transitions.size(); i++){
for(unsigned int z = i + 1; z < transitions.size(); z++){
if(transitions[i].Source_State() == transitions[z].Source_State()
&& transitions[i].Read_Character() == transitions[z].Read_Character()){
valid = false;
cout << "Error: Two transitions have the same source state '" << transitions[i].Source_State() << "' and read character '" << transitions[i].Read_Character() << "'.\n";
}
}
}
// Validate the the tape alphabet elements.
for (unsigned int i = 0; i < transitions.size(); i++){
// The read character is not contained within the tape alphabet.
if (!tape_alphabet.is_element(transitions[i].Read_Character())){
cout << "Error: Transition read character '" << transitions[i].Read_Character() << "' is not in tape alphabet.\n";
valid = false;
}
// The write character is not contained within the tape alphabet.
if (!tape_alphabet.is_element(transitions[i].Write_Character())){
cout << "Error: Transition write character '" << transitions[i].Write_Character() << "' is not in tape alphabet.\n";
valid = false;
}
}
// Validate that all of the states are in the list of states.
for (unsigned int i = 0; i < transitions.size(); i++){
// The source state is not in the list of states.
if (!states.is_element(transitions[i].Source_State())){
cout << "Error: Transition source state '" << transitions[i].Source_State() << "' is not in states.\n";
valid = false;
}
// The destination state is not in the list of states.
if (!states.is_element(transitions[i].Destination_State())){
cout << "Error: Transition destination state '" << transitions[i].Destination_State() << "' is not in states.\n";
valid = false;
}
}
}