]> Creatis software - bbtk.git/blob - kernel/src/bbtkExecuter.cxx
72ad0de9a8952f9d1b5fba55e75ff42a1174219e
[bbtk.git] / kernel / src / bbtkExecuter.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkExecuter.cxx,v $
4   Language:  C++
5   Date:      $Date: 2010/06/18 14:43:19 $
6   Version:   $Revision: 1.32 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  *  \file 
33  *  \brief class Executer: level 0 of script execution (code)
34  */
35
36 #include "bbtkExecuter.h"
37 #include "bbtkMessageManager.h"
38 #include "bbtkFactory.h"
39 #include "bbtkUtilities.h"
40 //#include "bbtkWx.h"
41 #include <fstream>
42
43 #ifdef USE_WXWIDGETS
44 #include <wx/textdlg.h>
45 #endif
46
47 #include "bbtkWxBlackBox.h"
48
49 #include "bbtkConfigurationFile.h"
50
51 namespace bbtk
52 {
53   //=======================================================================
54   Executer::Pointer Executer::New()
55   {
56     bbtkDebugMessage("object",9,"Executer::New()"<<std::endl);
57     return MakePointer(new Executer());
58   }
59   //=======================================================================
60
61   //=======================================================================
62   Executer::Executer()
63     : 
64     mFactory(),
65     mRootPackage(),
66     mRootCBB(),
67     mNoExecMode(false),
68     mDialogMode(NoDialog),
69     mNoErrorMode(false)
70   {
71     bbtkDebugMessage("object",2,"==> Executer()" <<std::endl);
72     mFactory = Factory::New();
73     // The smart pointer on this is not made yet (is made by New) 
74     // -> create it to pass it to the factory
75     // We have to "lock" the smart pointer because the factory
76     // only keeps a weak pointer on the executer
77     // -> this would auto-destroy !!
78     mFactory->SetExecuter(MakePointer(this,true));
79     Reset();
80     bbtkDebugMessage("object",2,"<== Executer()" <<std::endl);
81   }
82   //=======================================================================
83
84   //=======================================================================
85   Executer::~Executer()
86   {
87      bbtkDebugMessage("object",2,"==> ~Executer()" <<std::endl);
88      mOpenDefinition.clear();
89      mOpenPackage.clear();
90      mFactory->Reset();
91      mFactory.reset();
92      bbtkDebugMessage("object",2,"<== ~Executer()" <<std::endl);
93   }
94   //=======================================================================
95
96   //=======================================================================
97    /// Loads a package
98     void Executer::LoadPackage(const std::string &name )
99    {
100      GetFactory()->LoadPackage(name);
101    }
102   //=======================================================================
103
104   //=======================================================================
105     /// Unloads a package
106     void Executer::UnLoadPackage(const std::string &name )
107     {
108       GetFactory()->UnLoadPackage(name);
109     }
110   //=======================================================================
111
112   //=======================================================================
113   void Executer::Reset()
114   {
115     bbtkDebugMessage("kernel",9,"==> Executer::Reset()" <<std::endl);
116
117     //    GetFactory()->Check();
118  
119     mOpenDefinition.clear();
120     mOpenPackage.clear();
121
122     //  Wx::DestroyTopWindow();
123
124     GetFactory()->Reset();
125 #if(USE_WXWIDGETS)
126     Wx::ProcessPendingEvents();
127 #endif
128  
129     // Create user package
130     Package::Pointer p =
131       Package::New("user","internal","User defined black boxes","");
132     // Insert the user package in the factory
133     GetFactory()->InsertPackage(p);
134     // And in the list of open packages
135     mOpenPackage.push_back(p);
136     mRootPackage = p;
137
138     // Create user workspace
139     ComplexBlackBoxDescriptor::Pointer r = 
140       ComplexBlackBoxDescriptor::New("workspace"); 
141     //    mRootCBB->Reference();
142     r->SetFactory(GetFactory());
143     r->AddToAuthor("bbtk");
144     r->AddToDescription("User's workspace");
145     mOpenDefinition.push_back(CBBDefinition(r,"user"));
146     // Register it into the user package
147     p->Register(r);
148     mRootCBB = r;
149
150     //    Object::PrintObjectListInfo();
151     //  GetFactory()->CheckPackages();
152     bbtkDebugMessage("kernel",9,"<== Executer::Reset()" <<std::endl);
153   }
154   //=======================================================================
155
156
157   //=======================================================================
158   /// changes the workspace name
159   void Executer::SetWorkspaceName( const std::string& n )
160   {
161     GetUserPackage()->ChangeDescriptorName( GetWorkspace()->GetTypeName(), n );
162   }
163   //=======================================================================
164
165   //=======================================================================
166   void Executer::BeginPackage (const std::string &name)
167   {
168      bbtkDebugMessage("kernel",9,"==> Executer::BeginPackage(\""<<name<<"\")"
169                         <<std::endl);
170      Package::Pointer p;
171      try 
172       {
173          p = GetFactory()->GetPackage(name);
174       }
175     catch (Exception e)
176       {
177         p = Package::New(name,"","","");
178         GetFactory()->InsertPackage(p);
179       }
180      mOpenPackage.push_back(p);
181
182      bbtkDebugMessage("kernel",9,"<== Executer::BeginPackage(\""<<name<<"\")"
183                       <<std::endl);
184   }
185   //=======================================================================
186
187   //=======================================================================
188   void Executer::EndPackage()
189   {
190     if (mOpenPackage.size()>1) mOpenPackage.pop_back();
191   }
192   //=======================================================================
193
194   //=======================================================================
195   void Executer::Define (const std::string &name,
196                          const std::string &pack,
197                          const std::string &scriptfilename)
198   {
199     bbtkDebugMessage("kernel",9,"==> Executer::Define(\""<<name<<
200                      ","<<pack<<"\")"
201                      <<std::endl);
202
203     ComplexBlackBoxDescriptor::Pointer b 
204       = ComplexBlackBoxDescriptor::New(name);
205     b->SetFactory(GetFactory());
206     b->SetScriptFileName(scriptfilename);
207     mOpenDefinition.push_back( CBBDefinition( b, pack ) );
208     
209     bbtkDebugMessage("kernel",9,"<== Executer::Define(\""<<name<<
210                      ","<<pack<<"\")"
211                      <<std::endl);
212   }
213   //=======================================================================
214
215   //=======================================================================
216   /// Sets the file name to use for the current definition
217   /// (Used to set it after the Define command)
218   void Executer::SetCurrentFileName (const std::string &name )
219   {
220     mOpenDefinition.back().box->SetScriptFileName(name);
221   }
222   //=======================================================================
223
224   //=======================================================================
225   void Executer::Clear()
226   {
227     bbtkDebugMessage("kernel",9,"==> Executer::Clear()" <<std::endl);
228     GetCurrentDescriptor()->GetPrototype()->Clear();
229     bbtkDebugMessage("kernel",9,"<== Executer::Clear()" <<std::endl);
230   }
231   //=======================================================================
232
233   //=======================================================================
234   void Executer::EndDefine ()
235   {
236     bbtkDebugMessage("kernel",9,"==> Executer::EndDefine(\""
237                      <<GetCurrentDescriptor()->GetTypeName()<<"\")" 
238                      <<std::endl);
239     // Does current package exist ?
240     Package::Pointer p;
241     std::string pname(mOpenDefinition.back().package);
242     if (pname.size()>0)
243       {
244         try
245           {
246             p = GetFactory()->GetPackage(pname);
247           }
248         catch (Exception e)
249           {
250             p = Package::New(pname,"","","");
251             GetFactory()->InsertPackage(p);
252           }
253       }
254     else
255       {
256         p = mOpenPackage.back().lock();
257       }
258     // Register the descriptor in the current package
259     p->Register(GetCurrentDescriptor());
260     
261     bbtkDebugMessage("kernel",9,"<== Executer::EndDefine(\""
262                      <<GetCurrentDescriptor()->GetTypeName()<<"\")" 
263                      <<std::endl);
264     mOpenDefinition.pop_back();
265   }
266   //======================================================================= 
267
268   //=======================================================================  
269   void Executer::Kind(const std::string& kind)
270   {
271     if (kind=="ADAPTOR")
272       {
273         GetCurrentDescriptor()->AddToCategory("adaptor");
274         GetCurrentDescriptor()->SetKind(bbtk::BlackBoxDescriptor::ADAPTOR);
275       }
276     else if (kind=="DEFAULT_ADAPTOR")
277       {
278         GetCurrentDescriptor()->AddToCategory("adaptor");
279         GetCurrentDescriptor()->SetKind(bbtk::BlackBoxDescriptor::DEFAULT_ADAPTOR);
280       }
281     if (kind=="GUI")
282       {
283         GetCurrentDescriptor()->AddToCategory("gui");
284         GetCurrentDescriptor()->SetKind(bbtk::BlackBoxDescriptor::GUI);
285       }
286     else if (kind=="DEFAULT_GUI")
287       {
288         GetCurrentDescriptor()->AddToCategory("gui");
289         GetCurrentDescriptor()->SetKind(bbtk::BlackBoxDescriptor::DEFAULT_GUI);
290       }
291     else
292       {
293         bbtkError("Unknown box kind : '"<<kind<<"'. "
294                   <<"Valid kinds are 'ADAPTOR','DEFAULT_ADAPTOR',"
295                   <<"'GUI','DEFAULT_GUI'");
296       }
297   }
298   //=======================================================================
299
300   //=======================================================================
301   void Executer::Create ( const std::string& nodeType, 
302                           const std::string& nodeName)
303   {
304      GetCurrentDescriptor()->Add(nodeType,nodeName);
305   }
306   //=======================================================================
307
308   //=======================================================================
309   void Executer::Destroy(const std::string &boxName)
310   {
311     GetCurrentDescriptor()->Remove(boxName,true);
312   }
313   //=======================================================================
314
315   //=======================================================================
316   void Executer::Connect (const std::string &nodeFrom,
317                           const std::string &outputLabel,
318                           const std::string &nodeTo, 
319                           const std::string &inputLabel)
320   {
321     GetCurrentDescriptor()->Connect(nodeFrom, outputLabel, nodeTo, inputLabel);
322   }
323   //=======================================================================
324
325   //=======================================================================
326   void Executer::Execute (const std::string &nodeName) 
327   {
328     // if in root
329     if (GetCurrentDescriptor()==GetWorkspace()) 
330      {
331         if (!mNoExecMode) 
332         {
333            GetCurrentDescriptor()->GetPrototype()->bbGetBlackBox(nodeName)->bbExecute(true);
334         }
335      }
336      else 
337      {
338         GetCurrentDescriptor()->AddToExecutionList(nodeName) ;
339      }
340   }
341   //=======================================================================
342
343   //=======================================================================
344   void Executer::DefineInput ( const std::string &name,
345                                const std::string &box,
346                                const std::string &input,
347                                const std::string& help)
348   {
349     // If the input is defined in the Root box
350     if (GetCurrentDescriptor()==GetWorkspace()) 
351       {
352       // If the dialog mode is set to NoDialog
353       // and the user passed the name in the Inputs map 
354       // then the associated value is set to the box.input
355       // This is the way command line parameters are passed to the Root box
356          if (mDialogMode == NoDialog) 
357          {
358          // find if name is in mInputs
359             std::map<std::string,std::string>::iterator i;
360             i = mInputs.find(name);
361             if (i!=mInputs.end()) {
362                Set(box,input,(*i).second);
363             }
364          }
365         // If the dialog mode is set to TextDialog
366         // The user is prompted for the value
367         else if (mDialogMode == TextDialog) 
368         {
369            std::cout << name << "=";
370            std::string ans;
371            std::cin >> ans;
372            Set(box,input,ans);
373         }
374 #ifdef USE_WXWIDGETS
375        // If the dialog mode is set to GraphicalDialog
376        // A dialog box is pop up
377        else if (mDialogMode == GraphicalDialog) 
378        {
379           std::string mess("Enter the value of '");
380           mess += name;
381           mess += "' (";
382           mess += help;
383           mess += ")";
384           std::string title(name);
385           title += " ?";
386           std::string ans = wx2std ( wxGetTextFromUser( std2wx (mess), std2wx(title)));
387           Set(box,input,ans); 
388        }
389 #endif
390     }
391
392     GetCurrentDescriptor()->DefineInput(name,box,input,help);
393
394   }
395   //=======================================================================
396
397   //=======================================================================
398    void Executer::DefineOutput ( const std::string &name,
399                                  const std::string &box,
400                                  const std::string &output,
401                                  const std::string& help)
402   {
403     GetCurrentDescriptor()->DefineOutput(name,box,output,help);
404   }
405   //=======================================================================
406
407   //=======================================================================
408   void Executer::Set (const std::string &box,
409                       const std::string &input,
410                       const std::string &value)
411   {
412     BlackBox::Pointer b = GetCurrentDescriptor()->GetPrototype()->bbGetBlackBox(box);
413     // Looks for the adaptor
414
415     if ( ( b->bbGetInputType(input) != typeid(bbtk::any<bbtk::thing>) )&&
416          ( b->bbGetInputType(input) != typeid(std::string) ) )
417       {
418         BlackBox::Pointer a =
419            GetFactory()->NewAdaptor(typeid(std::string),
420                                     b->bbGetInputType(input),
421                                     "tmp");
422          if (!a) 
423            {
424              bbtkError("No <"<<
425                        TypeName(b->bbGetInputType(input))
426                        <<"> to <std::string> found");
427            }
428          std::string v(value);
429          a->bbSetInput("In",v);
430          a->bbExecute();
431          b->bbSetInput(input,a->bbGetOutput("Out"));
432          //         a->Delete();
433       }
434     else 
435       {
436       std::string v(value);
437       b->bbSetInput(input,v);
438       }
439   }
440   //=======================================================================
441
442   //=======================================================================
443   std::string Executer::Get(const std::string &box,
444                             const std::string &output)
445   {
446     BlackBox::Pointer b = GetCurrentDescriptor()->GetPrototype()->bbGetBlackBox(box);
447     // Looks for the adaptor
448     if (b->bbGetOutputType(output) != typeid(std::string)) 
449       {
450         BlackBox::Pointer a =
451           GetFactory()->NewAdaptor(
452                                    b->bbGetOutputType(output),
453                                    typeid(std::string),
454                                    "tmp");
455         if (!a) 
456           {
457             bbtkError("No <"<<
458                       TypeName(b->bbGetOutputType(output))
459                       <<"> to <std::string> found");
460           }
461         b->bbExecute();
462         
463         a->bbSetInput("In",b->bbGetOutput(output));
464         a->bbExecute();
465         std::string r = a->bbGetOutput("Out").unsafe_get<std::string>();
466         //std::string v = *((std::string*)a->bbGetOutput("Out")) ;
467         //   std::cout << a->bbGetOutput("Out").unsafe_get<std::string>() 
468         //             << std::endl;
469         //std::string v(value);
470         //b->bbSetInput(input,a->bbGetOutput("Out"));
471         //        a->bbDelete();
472         return r;
473       }
474     else
475       {
476         b->bbExecute();
477         return b->bbGetOutput(output).unsafe_get<std::string>();
478         // std::string v = *((std::string*)b->bbGetOutput(output)) ;
479         // std::cout << b->bbGetOutput("Out").unsafe_get<std::string>() 
480         //   << std::endl;
481         // b->bbSetInput(input,&v);
482       }
483   }
484   //=======================================================================
485
486   //=======================================================================
487   void Executer::Author(const std::string &authorName)
488   {
489     GetCurrentDescriptor()->AddToAuthor(authorName,GetCurrentDescriptor()==GetWorkspace());
490   }
491   //=======================================================================
492
493   //=======================================================================
494   void Executer::Category(const std::string &category)
495   {
496     GetCurrentDescriptor()->AddToCategory(category,GetCurrentDescriptor()==GetWorkspace());
497   }
498   //=======================================================================
499
500   //=======================================================================
501   void Executer::Description(const std::string &d)
502   {
503     GetCurrentDescriptor()->AddToDescription(d,GetCurrentDescriptor()==GetWorkspace());
504   }
505   //=======================================================================
506
507
508
509   //=======================================================================
510   /// prints the list of the boxes of the current descriptor
511   void Executer::PrintHelpListBoxes()
512   {
513     bbtkMessage("help",1,"The black box descriptor \""
514                 <<GetCurrentDescriptor()->GetTypeName()<<"\" contains : "<<std::endl);
515     GetCurrentDescriptor()->PrintBlackBoxes();
516  }
517   //=======================================================================
518
519   //=======================================================================
520   std::string Executer::ShowGraph(const std::string &nameblackbox, 
521                                   const std::string &detailStr, 
522                                   const std::string &levelStr,
523                                   const std::string &output_html,
524                                   const std::string &custom_header,
525                                   const std::string &custom_title,
526                                   bool system_display )
527   {
528     int detail  =       atoi(detailStr.c_str());
529     int level   =       atoi(levelStr.c_str());
530           bool relative_link = true;
531
532     Package::Pointer p;
533     try
534     {
535        p = GetFactory()->GetPackage(nameblackbox);
536     }
537     catch (Exception e)
538     {
539       p = GetUserPackage();
540     }
541           
542       std::string doc_path = bbtk::ConfigurationFile::GetInstance().Get_doc_path();
543       doc_path += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
544       doc_path += "bbdoc";
545       doc_path += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
546           
547           std::string pack_name(p->GetName());
548           std::string pack_path = doc_path + pack_name;
549           // Creating directory
550           if ( ! bbtk::Utilities::FileExists(pack_path) )
551           {
552                   std::string command("mkdir \"" +pack_path+ "\"");
553                   system( command.c_str() );
554           }
555           std::string pack_index(pack_path);
556           pack_index += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
557           pack_index += "index.html"; 
558           
559           
560     // Generating documentation-help of workspace
561         p->SetDocURL(pack_index);
562     p->SetDocRelativeURL("index.html");
563         p->CreateHtmlPage(pack_index,"bbtk","user package",custom_header,custom_title,detail,level,relative_link);
564           
565     /*
566     try 
567     {
568        ShowGraphTypes(nameblackbox);
569     }
570     catch (bbtk::Exception a)
571     {
572        std::cout <<"EXC"<<std::endl;
573        page = ShowGraphInstances(nameblackbox,detail,level,system_display);
574     }
575     */
576     return pack_index;
577   }
578   //=======================================================================
579
580   //=======================================================================
581   /// Generate a png file with the actual pipeline (Graphviz-dot needed)
582   std::string Executer::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
583                                            bool system_display)
584   {
585
586     BlackBox::Pointer blackbox;
587     if (nameblackbox==".")
588     {
589        blackbox = GetCurrentDescriptor()->GetPrototype();
590     }
591     else
592     {
593        blackbox = GetCurrentDescriptor()->GetPrototype()->bbFindBlackBox(nameblackbox);
594     }
595     
596     std::string page;
597
598     if (blackbox)
599       {      
600         // Don't pollute the file store with  "temp_dir" directories ...
601         std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
602         char c = default_doc_dir.c_str()[strlen(default_doc_dir.c_str())-1];
603
604         std::string directory = default_doc_dir; 
605         if (c != '/' && c !='\\') directory = directory + "/";
606
607         directory = directory +  "temp_dir";
608         //std::string directory("temp_dir");
609         std::string filename(directory + "/" + "bbtk_graph_pipeline");
610         std::string filename_html(filename+".html");
611         std::string command0("mkdir \""+directory + "\"");
612
613 #if defined(_WIN32)
614         std::string command2("start ");
615 #else 
616         std::string command2("gnome-open ");
617 #endif
618
619         command2=command2+filename_html;
620         page = filename_html;
621         // 1. Generate Html Diagram
622         std::ofstream s;
623         s.open(filename_html.c_str());
624         if (s.good()) 
625           {
626             s << "<html><head><title>BBtk graph diagram</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head>\n";
627             s << "<body bgcolor=\"#FFFFFF\" text=\"#000000\"> \n\n";
628             if ( blackbox->bbGetName()=="workspacePrototype" )
629               {
630                 s << "<center>Current workspace</center>";
631               } else {
632               s << "<center>" << blackbox->bbGetName()<< "</center>";
633             } 
634             blackbox->bbInsertHTMLGraph( s, detail, level, true, directory, false );
635             s << "</body></html>\n";
636           }
637         s.close();
638         
639         // 2. Starting Browser
640         if (system_display) system( command2.c_str() );      
641       } 
642     else 
643       {
644         bbtkMessage("help",1,"No black box: \""
645                     <<nameblackbox<<"\" " <<std::endl);
646       }
647     return page;
648   }
649   //=======================================================================
650
651   //=======================================================================
652   void Executer::PrintHelpBlackBox(const std::string &nameblackbox, 
653                                const std::string &detailStr, 
654                                const std::string &levelStr)
655   {
656     bool found=false;
657     
658     int detail = atoi(detailStr.c_str());
659     int level  = atoi(levelStr.c_str());
660     BlackBox::Pointer blackbox;
661     if (nameblackbox.compare(".")==0)
662       {
663         blackbox=GetCurrentDescriptor()->GetPrototype();
664       } 
665     else 
666       {
667         blackbox = GetCurrentDescriptor()->GetPrototype()->bbFindBlackBox(nameblackbox);
668       }
669     
670     if (blackbox)
671       {
672         found=true;
673         blackbox->bbPrintHelp(blackbox,detail,level); //,mFactory);
674       }
675     
676     if (!found) 
677       {
678         bbtkError("box with name '"  <<nameblackbox<<"' unknown");
679       }
680   }
681   //=======================================================================
682
683   //=======================================================================
684   /// sets the level of message
685   void Executer::SetMessageLevel(const std::string &kind,
686                                  int level)
687   {
688     bbtk::MessageManager::SetMessageLevel(kind,level);
689   }
690   //=======================================================================
691
692   //=======================================================================
693   /// Prints help on the messages
694   void  Executer::HelpMessages()
695   {
696     bbtk::MessageManager::PrintInfo();
697   }
698   //=======================================================================
699
700   //=======================================================================
701   ///
702   void Executer::Print(const std::string &str)
703   {  
704     if (GetNoExecMode() &&  (GetCurrentDescriptor()==GetWorkspace()) ) return;
705     if (GetCurrentDescriptor()!=GetWorkspace()) return;
706
707     bbtkDebugMessage("kernel",9,"Executer::Print(\""<<str<<"\")"<<std::endl);
708
709  // TO DO :
710  // InterpretLine ("load std")
711  // InterpretLine("new ConcatStrings _C_ ") -> trouver un nom unique : # commande 
712  // InterpretLine("new Print _P_") 
713  // InterpretLine("connect _C_.Out _P_.In")
714  // int num = 1
715  
716
717     std::vector<std::string> chains;
718     std::string delimiters("$");
719
720     // Skip delimiters at beginning.
721     std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
722     bool is_text = true;
723     if (lastPos>0) is_text = false;
724
725     // Find first delimiter.
726     std::string::size_type pos     = str.find_first_of(delimiters, lastPos);
727
728     while (std::string::npos != pos || std::string::npos != lastPos)
729     {
730        if (is_text) 
731        {
732           // Found a text token, add it to the vector.
733           chains.push_back(str.substr(lastPos, pos - lastPos));
734  // std::string token = str.substr(lastPos, pos - lastPos)
735  // InterpretLine("set _C_.In%num% %token%")
736  
737        }
738        else 
739        {
740
741        // is an output (between $$) : decode 
742          std::string tok,box,output;
743          tok = str.substr(lastPos, pos - lastPos);
744          Utilities::SplitAroundFirstDot(tok,box,output);
745          chains.push_back( Get(box,output) );
746
747 // InterpretLine("connect %tok% _C_.In%num%") 
748
749        }
750         // Skip delimiters.  Note the "not_of"
751        lastPos = str.find_first_not_of(delimiters, pos);
752         // Find next delimiter
753        pos = str.find_first_of(delimiters, lastPos);
754     //
755        is_text = !is_text;
756 // num ++;
757      }
758 // InterpretLine("exec _P_")
759 // if (IS_IN_WORKSPACE) InterpretLine("delete _C_; delete _P_");
760
761     std::vector<std::string>::iterator i;
762     for (i= chains.begin(); i!=chains.end(); ++i) 
763       {
764         Utilities::SubsBackslashN(*i);
765         bbtkMessage("output",1,*i);
766       }
767     bbtkMessage("output",1,std::endl);
768   }
769   //==========================================================================
770
771   //==========================================================================
772   std::string Executer::GetObjectName() const
773   {
774     return std::string("Executer");
775   }
776   //==========================================================================
777   
778   //==========================================================================
779   std::string  Executer::GetObjectInfo() const 
780   {
781     std::stringstream i;
782     return i.str();
783   }
784   //==========================================================================
785   //==========================================================================
786 size_t  Executer::GetObjectSize() const 
787 {
788   size_t s = Superclass::GetObjectSize();
789   s += Executer::GetObjectInternalSize();
790   return s;
791   }
792   //==========================================================================
793   //==========================================================================
794 size_t  Executer::GetObjectInternalSize() const 
795 {
796   size_t s = sizeof(Executer);
797   return s;
798   }
799   //==========================================================================
800   //==========================================================================
801   size_t  Executer::GetObjectRecursiveSize() const 
802   {
803     size_t s = Superclass::GetObjectRecursiveSize();
804     s += Executer::GetObjectInternalSize();
805     s += mFactory->GetObjectRecursiveSize();
806     return s;
807   }
808   //==========================================================================
809 }//namespace