]> rtime.felk.cvut.cz Git - boost-statechart-viewer.git/commitdiff
Add support for orthogonal states.
authorpetr000 <silhavik.p@gmail.com>
Thu, 11 Aug 2011 09:06:07 +0000 (11:06 +0200)
committerpetr000 <silhavik.p@gmail.com>
Thu, 11 Aug 2011 09:06:07 +0000 (11:06 +0200)
The orthogonal states are correctly printed into the output file and also into the transition table

Add method test_start that tests all start states in that context.

src/iooper.h
src/stringoper.h

index f85ed6444e38d2a63ee0f8ae35a694af80b94af8..4ce36580c664002dea9fb924c5ecbac5a685326c 100644 (file)
@@ -104,33 +104,62 @@ class IO_operations
        {
                this->outputFilename = outputFilename;
        }
+
+       bool test_start(const string *sState, const string state, const int num)
+       {
+               for(int i = 0; i<num;i++)
+               {
+                       if (state.compare(0,sState[i].length(), sState[i])==0 && sState[i].length()==state.length()) return true;
+               }
+               return false;
+       }
        
        bool write_states(ofstream& filestr) /** This method write states to the output file and also to transition table. */
        {
-               int pos1, pos2, cnt, subs;
+               int pos1, pos2, cnt, subs, num_start, orto = 0;
                nState = 1;
-               string context, state, ctx, sState, str;
+               string context, state, ctx, *sState, str;
                list<string> nstates = states;
                context = name_of_machine;
                table[0] = "S";
                table[1] = "Context";
                table[2] = "State";
+               cnt = count(name_of_first_state,',');
+               sState = new string [cnt+1];
+               str = name_of_first_state;
+               if(cnt>0) str = get_params(str);
+               num_start = cnt+1;
+               for(int i = 0;i<=cnt;i++)
+               {
+                       if(i == cnt) sState[i] = str;
+                       else 
+                       {
+                               sState[i] = str.substr(0,str.find(','));
+                               str = str.substr(str.find(',')+1);
+                       }
+               }               
                for(list<string>::iterator i = nstates.begin();i!=nstates.end();i++) // write all states in the context of the automaton
                {
                        state = *i;
                        cnt = count(state,',');
-                       if(cnt==1)
+                       if(count(state,'>')==1) //ortho states
+                       {
+                               orto = 1;
+                               if(cnt>1)cnt = 2;
+                       }
+                       if(cnt==1) 
                        {
                                pos1 = state.find(",");
-                               ctx = cut_namespaces(state.substr(pos1+1));
+                               if(orto == 1) ctx = cut_namespaces(cut_namespaces(state.substr(pos1+1),1));                             
+                               else ctx = cut_namespaces(state.substr(pos1+1));                        
                                if(ctx.compare(0,context.length(),context)==0 && context.length()==ctx.length())
                                {
                                        str = cut_namespaces(state.substr(0,pos1));
-                                       if(str.compare(0,name_of_first_state.length(),name_of_first_state)==0 && name_of_first_state.length()==str.length()) 
+                                       if(test_start(sState,str,num_start)) 
                                        {
                                                filestr<<str<<" [peripheries=2];\n";
                                                table[cols*nState] = "*";
-                                       }                                       
+                                       }                       
                                        else filestr<<str<<"\n";
                                        table[cols*nState+2] = str;
                                        table[cols*nState+1] = context;
@@ -139,15 +168,16 @@ class IO_operations
                                        i--;
                                }
                        }
-                       if(cnt==2)
+                       if(cnt==2) //ORTHO OK
                        {
                                pos1 = state.find(",");
-                               pos2 = state.rfind(",");
+                               pos2 = state.substr(pos1+1).find(",")+pos1+1;
                                ctx = cut_namespaces(state.substr(pos1+1,pos2-pos1-1));
+                               cout<<ctx<<endl;                        
                                if(ctx.compare(0,context.length(),context)==0 && context.length()==ctx.length())
                                {                               
                                        str = cut_namespaces(state.substr(0,pos1));
-                                       if(str.compare(0,name_of_first_state.length(),name_of_first_state)==0 && name_of_first_state.length()==str.length()) 
+                                       if(test_start(sState,str,num_start)) 
                                        {
                                                filestr<<str<<" [peripheries=2];\n";
                                                table[cols*nState] = "*";
@@ -159,30 +189,50 @@ class IO_operations
                                }
                        }
                }
+               delete [] sState;
                subs = 0;
                while(!nstates.empty()) // substates ?
                {
                        state = nstates.front();
                        filestr<<"subgraph cluster"<<subs<<" {\n";                      
                        pos1 = state.find(",");
-                       pos2 = state.rfind(",");
+                       pos2 = state.substr(pos1+1).find(",")+pos1+1;
                        if(pos1 == pos2) return false;
                        context = cut_namespaces(state.substr(0,pos1));
                        filestr<<"label=\""<<context<<"\";\n";
-                       sState = cut_namespaces(state.substr(pos2+1));
-                       nstates.pop_front();    
+                       cnt = count(state.substr(pos2+1),',');
+                       sState = new string [cnt+1];
+                       str = state.substr(pos2+1);
+                       if(cnt>0) str = get_params(str);
+                       num_start = cnt+1;
+                       for(int i = 0;i<=cnt;i++)
+                       {
+                               if(i == cnt) sState[i] = str;
+                               else 
+                               {
+                                       sState[i] = str.substr(0,str.find(','));
+                                       str = str.substr(str.find(',')+1);
+                               }
+                       }       
+                       nstates.pop_front();
                        for(list<string>::iterator i = nstates.begin();i!=nstates.end();i++)
                        {
                                state = *i;
                                cnt = count(state,',');
+                               if(count(state,'>')==1) //ortho states
+                               {
+                                       orto = 1;
+                                       if(cnt>1)cnt = 2;
+                               }                               
                                if(cnt==1)
                                {
                                        pos1 = state.find(",");
-                                       ctx = cut_namespaces(state.substr(pos1+1));
+                                       if(orto == 1) ctx = cut_namespaces(cut_namespaces(state.substr(pos1+1),1));                             
+                                       else ctx = cut_namespaces(state.substr(pos1+1));
                                        if(ctx.compare(0,context.length(),context)==0 && context.length()==ctx.length())
                                        {
                                                str = cut_namespaces(state.substr(0,pos1));
-                                               if(str.compare(0,sState.length(),sState)==0 && sState.length()==str.length())
+                                               if(test_start(sState,str,num_start))
                                                {
                                                        filestr<<str<<" [peripheries=2];\n";
                                                        table[cols*nState]="*";
@@ -203,11 +253,11 @@ class IO_operations
                                        if(ctx.compare(0,context.length(),context)==0 && context.length()==ctx.length())
                                        {
                                                str = cut_namespaces(state.substr(0,pos1));
-                                               if(str.compare(0,sState.length(),sState)==0 && sState.length()==str.length())
+                                               if(test_start(sState,str,num_start))
                                                {
                                                        filestr<<str<<" [peripheries=2];\n";
                                                        table[cols*nState]="*";
-                                               }                                               
+                                               }                                       
                                                else filestr<<str<<"\n";
                                                table[cols*nState+2] = str;
                                                table[cols*nState+1] = context;
@@ -216,7 +266,8 @@ class IO_operations
                                }
                        }
                        filestr<<"}\n";
-                       subs+=1;        
+                       subs+=1;
+                       delete [] sState;       
                }
                return true;
        }
index e2727da893836a8d873b8a165442f943db295c86..b2a9095df5077789e371690afc9f83f54f8c9878 100644 (file)
@@ -88,6 +88,24 @@ string cut_namespaces(string line) /** Cut namespaces from the declarations. */
        return line.substr(i+1);
 }
 
+string cut_namespaces(string line, int ortho) /** Cut namespaces ORTHOGONAL STATES. */
+{
+       int i;
+       int brackets = 0;
+       for(i = line.length()-1;i>0;i--)
+       {
+               if(line[i]=='<') brackets+=1;
+               if(line[i]=='>') brackets-=1;
+               if(line[i]==':' && line[i-1]==':')
+               {
+                       if(brackets == 0) break;
+                       else i--;
+               }
+       }
+       if(i==0) return line;
+       return line.substr(0,i-1);
+}
+
 bool is_derived(const string line) /** Test whether this struct or class is derived */
 {
        unsigned i;
@@ -234,7 +252,7 @@ bool test_model(const string line, const string model) /** Test the string to ha
 string get_params(string line) /** Return parameters of the specified transition */
 {
        int pos_front = line.find("<")+1;
-       int pos_end = line.find(">");
+       int pos_end = line.rfind(">");
        return line.substr(pos_front,pos_end-pos_front);
 }