Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

这是一个非常简单小巧的有限自动状态机。使用C++11开发,仅仅由一个头文件构成

NotificationsYou must be signed in to change notification settings

galaxy1978/tinyStm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

tinystm is finite automation use c++ 11

sample:#include #include #include "stm.hpp"

int main( int argc , const char * argv[] ){int ret = 0;

stm<std::string , int >  mach;try{// add two status node p_s1 as start , and p_s2 as end;stm<std::string,  int >::stStatus * p_s1 = mach.add( "ready" ); // specify the start node which id is 0mach.startStatus();stm<std::string , int > :: stStatus *p_s2 = mach.add("end" );// specify the end node with node pointer.mach.endStatus( p_s2 );// add convert arc , which trigged by a interger number of 1mach.addArc( p_s1 , p_s2 , 1 );// 从这里开始int data;while( true ){  // 通过键盘输入状态转换命令std::cout << "Input command: ";std::cin >> data;stm<std::string , int >::stStatus * f = nullptr, * e = nullptr;bool isOK = false;  // 触发状态转换mach.trigger( data , [&isOK ,  &f , &e ]( bool isTransOk , stm<std::string , int >::stStatus * from , stm<std::string, int >::stStatus * end ){   // do something before convert;   isOK = isTransOk;   f = from;   e = end;                           });// do something after convert;std::cerr << "CURRENT STATUS: " << mach.getCurrent() << std::endl;if( mach.isEnd( e ) == true ){std::cerr << "the machine is finished" << std::endl;break;}  }}catch( std::bad_alloc& e ){std::cerr << "Allocate memory fail" << std::endl;ret = -1;}return ret;

}


[8]ページ先頭

©2009-2025 Movatter.jp