]> rtime.felk.cvut.cz Git - boost-statechart-viewer.git/commitdiff
Add simple support for deffering events (not written as custom_reaction). In transiti...
authorpetr000 <silhavik.p@gmail.com>
Sun, 18 Sep 2011 14:32:37 +0000 (16:32 +0200)
committerpetr000 <silhavik.p@gmail.com>
Sun, 18 Sep 2011 14:32:37 +0000 (16:32 +0200)
Transition table is now able to show multiple reactions for one event in one state. Each of the possibilities is printed in one row.

src/iooper.h
src/stringoper.h
src/visualizer.cpp

index 4ce36580c664002dea9fb924c5ecbac5a685326c..8565a92f68e5a0d3d9b66bcacf91ba07025768ff 100644 (file)
@@ -172,8 +172,7 @@ class IO_operations
                        {
                                pos1 = state.find(",");
                                pos2 = state.substr(pos1+1).find(",")+pos1+1;
-                               ctx = cut_namespaces(state.substr(pos1+1,pos2-pos1-1));
-                               cout<<ctx<<endl;                        
+                               ctx = cut_namespaces(state.substr(pos1+1,pos2-pos1-1)); 
                                if(ctx.compare(0,context.length(),context)==0 && context.length()==ctx.length())
                                {                               
                                        str = cut_namespaces(state.substr(0,pos1));
@@ -282,14 +281,25 @@ class IO_operations
                        if(count(params,',')==2)
                        {                       
                                pos1 = params.find(",");
-                               state = cut_namespaces(params.substr(0,pos1));
-                               filestr<<state<<"->";
-                               pos2 = params.rfind(",");
-                               dest = cut_namespaces(params.substr(pos2+1));
-                               filestr<<dest;
-                               event = cut_namespaces(params.substr(pos1+1,pos2-pos1-1));
-                               filestr<<"[label=\""<<event<<"\"];\n";
-                               table[find_place(state,2)*cols+find_place(event,1)]=dest;
+                               if(pos1==0) 
+                               {
+                                       dest = "(deferred)";
+                                       pos2 = params.rfind(",");
+                                       event = cut_namespaces(params.substr(pos2+1));
+                                       state = cut_namespaces(params.substr(1,pos2-1));
+                               }
+                               else
+                               {
+                                       state = cut_namespaces(params.substr(0,pos1));
+                                       filestr<<state<<"->";
+                                       pos2 = params.rfind(",");
+                                       dest = cut_namespaces(params.substr(pos2+1));
+                                       filestr<<dest;
+                                       event = cut_namespaces(params.substr(pos1+1,pos2-pos1-1));
+                                       filestr<<"[label=\""<<event<<"\"];\n";
+                               }
+                               dest.append(",");
+                               table[find_place(state,2)*cols+find_place(event,1)]+=dest;
                        }
                }               
                return;
@@ -337,13 +347,24 @@ class IO_operations
                cout<<"\nTRANSITION TABLE\n";
                unsigned * len = new unsigned[cols];
                len[0] = 1;
-               string line = "-|---|-";
+               int nbr, multiline;
+               string line = "-|---|-", str;
                for(int i = 1; i<cols; i++)
                {
                        len[i] = 0;
                        for(int j = 0;j<rows;j++)
                        {
-                               if(len[i]<table[j*cols+i].length()) len[i] = table[j*cols+i].length();
+                               nbr = count(table[j*cols+i],',');
+                               if(nbr>1)
+                               {
+                                       str = table[j*cols+i];
+                                       for(int k = 1; k<nbr;k++)
+                                       {
+                                               if(len[i]<str.find(",")) len[i] = str.find(",");
+                                               str.substr(str.find(",")+1);
+                                       }
+                               }
+                               else if(len[i]<table[j*cols+i].length()) len[i] = table[j*cols+i].length();
                        }
                        for(unsigned k = 0; k<len[i]; k++)
                        {
@@ -354,14 +375,33 @@ class IO_operations
                cout<<line<<"\n";
                for(int i = 0; i<rows; i++)
                {
-                       cout<<" | ";            
+                       cout<<" | ";
+                       multiline = 0;
                        for(int j = 0;j<cols;j++)
                        {
                                cout.width(len[j]);
-                               cout<<left<<table[i*cols+j]<<" | ";
+                               str = table[i*cols+j];
+                               nbr = count(str,',');
+                               if(nbr>0)
+                               {                               
+                                       cout<<left<<str.substr(0,str.find(","))<<" | ";
+                                       if(nbr>1) 
+                                       {
+                                               table[i*cols+j] = str.substr(str.find(",")+1);
+                                               multiline = 1;
+                                       }
+                                       else table[i*cols+j]="";
+                                               
+                               }
+                               else 
+                               {
+                                       cout<<left<<str<<" | ";
+                                       table [i*cols+j]="";
+                               }
                        }
                        cout<<"\n";
-                       cout<<line<<"\n";
+                       if(multiline == 0)      cout<<line<<"\n";
+                       else i--;
                }
                delete [] len;
        }
index b2a9095df5077789e371690afc9f83f54f8c9878..48f337e317e52fade87d7224af46d3e29d5542e3 100644 (file)
@@ -162,7 +162,6 @@ string get_first_base(const string line) /** Get the first super class of this d
 
 bool is_state(const string line) /** Test if this declaration is a state. It is used to test the base classes. */
 {
-       cout<<cut_namespaces(line)<<endl;
        if(cut_namespaces(line).compare(0,12,"simple_state")==0)
        {
                return true;    
@@ -237,15 +236,27 @@ string get_inner_part(const string line) /** Get inner part of the list. */
        return str.substr(0,i);
 }
 
-bool test_model(const string line, const string model) /** Test the string to has a specified model. */
+int get_model(const string line) /** Test the string to has a specified model. */
 {
-       if(cut_namespaces(line).compare(0,model.length(),model)==0)
+       string str = cut_namespaces(line);
+       if(str.find("<")<str.length()) str = str.substr(0,str.find("<"));
+       switch(str.length())
        {
-               return true;    
-       }
-       else
-       {
-               return false;
+               case 5 : if(str.compare(0,5,"event")==0) return 1;
+                                       break;
+               case 6 : if(str.compare(0,6,"result")==0) return 5;
+                                       break;
+               case 7 :        if(str.compare(0,7,"transit")==0) return 6;
+                                       break;
+               case 8 :        if(str.compare(0,8,"deferral")==0) return 13;
+                                       break;          
+               case 10 : if(str.compare(0,10,"transition")==0) return 11;
+                                        break;
+               case 13 : if(str.compare(0,13,"state_machine")==0) return 3;
+                                        break;
+               case 15 : if(str.compare(0,15,"custom_reaction")==0) return 12;
+                                        break;
+               default : return -1;
        }
 }
 
@@ -296,7 +307,7 @@ string find_name_of_machine(const CXXRecordDecl *cRecDecl, string line) /** Find
                {
                        if(i!=cRecDecl->getNumBases()-1) base = get_first_base(super_class);
                        else base = super_class;
-                       if(test_model(base,"state_machine"))
+                       if(get_model(base)==3)
                        {
                                params = get_params(base);
                        }
@@ -308,7 +319,7 @@ string find_name_of_machine(const CXXRecordDecl *cRecDecl, string line) /** Find
        }
        else
        { 
-               if(test_model(super_class,"state_machine"))
+               if(get_model(super_class)==3)
                {
                        params = get_params(super_class);
                }
@@ -332,33 +343,18 @@ string find_transitions (const string name_of_state, string line) /** Traverse a
        {
                if(j!=num-1) base = get_first_base(line);                       
                else base = line;
-               if(test_model(base,"transition"))
-               {
-                       dest = name_of_state;
-                       params = get_params(base);
-                       //cout<<params<<"\n";
-                       dest.append(",");                                                       
-                       dest.append(params);
-                       line = get_next_base(line);
-                       trans.append(dest);
-                       if(j+1!=num) trans.append(";");
-               }
-               else if(test_model(base,"custom_reaction"))
+               if(get_model(base)>10)
                {
-                       dest = ";";
+                       if(get_model(base)==12) dest = ";";
+                       else if (get_model(base) == 13) dest = ",";
                        dest.append(name_of_state);
                        params = get_params(base);
-                       //cout<<params<<"\n";
                        dest.append(",");                                                       
                        dest.append(params);
-                       line = get_next_base(line);
                        trans.append(dest);
                        if(j+1!=num) trans.append(";");
                }
-               else
-               {
-                       line = get_next_base(line);
-               }
+               line = get_next_base(line);
        }
        if(trans[trans.length()-1]==';') return trans.substr(0,trans.length()-1);
        else return trans;      
@@ -373,7 +369,7 @@ bool find_events(const CXXRecordDecl *cRecDecl, string line) /** This function p
                {
                        if(i!=cRecDecl->getNumBases()-1) base = get_first_base(super_class);
                        else base = super_class;
-                       if(test_model(base,"event")) return true;
+                       if(get_model(base)==1) return true;
                        else
                        {
                                super_class = get_next_base(super_class);
@@ -382,7 +378,7 @@ bool find_events(const CXXRecordDecl *cRecDecl, string line) /** This function p
        }
        else
        { 
-               if(test_model(super_class,"event"))return true;
+               if(get_model(super_class)==1)return true;
        }
        return false;
 }
index 0a034896a3f165f2e4061fe004ab1b2046b763d6..b920127bf9aa338af7d2a21a9b58ce54c28d2f8c 100644 (file)
@@ -335,11 +335,11 @@ class FindStates : public ASTConsumer
                {
                        decl->print(x);
                        line = get_return(x.str());
-                       if(test_model(line,"result"))
+                       if(get_model(line)==5)
                        {
                                const FunctionDecl *fDecl = dyn_cast<FunctionDecl>(decl);
                                const ParmVarDecl *pvd = fDecl->getParamDecl(0);
-                                QualType qt = pvd->getOriginalType();
+                               QualType qt = pvd->getOriginalType();
                                event = qt.getAsString();
                                if(event[event.length()-1]=='&') event = event.substr(0,event.length()-2);
                                event = event.substr(event.rfind(" ")+1);
@@ -393,7 +393,7 @@ class FindStates : public ASTConsumer
                        case 98 :       line = sman.getCharacterData(dyn_cast<ReturnStmt>(stmt)->getReturnLoc()); 
                                                        line = get_line_of_code(line).substr(6);
                                                        line = line.substr(0,line.find("("));
-                                                       if(test_model(line,"transit"))
+                                                       if(get_model(line)==6)
                                                        {
                                                                param = get_params(line);
                                                                transitions.push_back(event.append(",").append(param));