• 有限状态机


    有限状态机

    #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);
    }
  • 相关阅读:
    构建之法阅读笔记05
    构建之法阅读笔记04
    构建之法阅读笔记03
    构建之法阅读笔记02
    构建之法阅读笔记01
    管理系统的简单解析---web
    Java中的异常处理
    多态
    重写与重载
    抽象类与接口
  • 原文地址:https://www.cnblogs.com/xloogson/p/2804464.html
Copyright © 2020-2023  润新知