zoukankan      html  css  js  c++  java
  • 有限状态机

    有限状态机

    #include<iostream>
    #include<vector>
    using namespace std;
    
    typedef struct Context{
        int iNext;
    }Context_t;
    
    
    
    void processor(Context_t &context,vector<int>& requests,vector<int>& results){
        switch(context.iNext){
        case 1:
        {
            cout<<"11111111111111"<<endl;
            requests.push_back(1);
            cout<<"22222222222222"<<endl;        
            requests.push_back(2);
            context.iNext = 2;
        }
        break;
        case 2:
        {
            if(results.size()<2){
                //cout<<"get resulsts error"<<endl;
                //return;
            }
            for(size_t i=0;i<results.size();i++){
                cout<<"get resulsts"<<results[i]<<endl;
            }
            requests.push_back(2);
            cout<<"33333333333333333333"<<endl;
            context.iNext = 3;
        }
        break;    
        case 3:
        {
            if(results.size()<1){
                //cout<<"get results error"<<endl;
                //return;
            }
            for(size_t i=0;i<results.size();i++){
                cout<<"get results"<<results[i]<<endl;
            }
            context.iNext = -1;
        }
        break;
        }
    }
    
    
    
    int main()
    {
        vector<int> requests;
        vector<int> results;
        Context_t context;
        context.iNext = 1;
        do
        {    
            processor(context,requests,results);
            results.clear();
            for(size_t i=0;i<requests.size();i++){
                results.push_back(i);
            }
            requests.clear();
        }while(context.iNext != -1);
    }
  • 相关阅读:
    转Vtype扩展
    Can't connect to MySQL server on 'ip' (13)
    观察者+js 模式
    (转)ASP.NET架构分析
    sql得到时间
    Js+XML 操作 (转)
    js中的math对象
    property和attribute的区别
    CSS样式定义
    linux 开启 mount
  • 原文地址:https://www.cnblogs.com/xloogson/p/2804464.html
Copyright © 2011-2022 走看看