Skip to content

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 0
	mach.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 1
	mach.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;

}

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy