]> Creatis software - bbtk.git/blob - kernel/src/bbtkExecuter.cxx
Bug #1754
[bbtk.git] / kernel / src / bbtkExecuter.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkExecuter.cxx,v $
4   Language:  C++
5   Date:      $Date: 2012/11/14 07:12:00 $
6   Version:   $Revision: 1.33 $
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         void Executer::SetTypeOfScript_Application ()
225         {
226                 mOpenDefinition.back().box->SetTypeOfScript_Application();
227         }
228         
229         
230         
231   //=======================================================================
232   void Executer::Clear()
233   {
234     bbtkDebugMessage("kernel",9,"==> Executer::Clear()" <<std::endl);
235     GetCurrentDescriptor()->GetPrototype()->Clear();
236     bbtkDebugMessage("kernel",9,"<== Executer::Clear()" <<std::endl);
237   }
238   //=======================================================================
239
240   //=======================================================================
241   void Executer::EndDefine ()
242   {
243     bbtkDebugMessage("kernel",9,"==> Executer::EndDefine(\""
244                      <<GetCurrentDescriptor()->GetTypeName()<<"\")" 
245                      <<std::endl);
246     // Does current package exist ?
247     Package::Pointer p;
248     std::string pname(mOpenDefinition.back().package);
249     if (pname.size()>0)
250       {
251         try
252           {
253             p = GetFactory()->GetPackage(pname);
254           }
255         catch (Exception e)
256           {
257             p = Package::New(pname,"","","");
258             GetFactory()->InsertPackage(p);
259           }
260       }
261     else
262       {
263         p = mOpenPackage.back().lock();
264       }
265     // Register the descriptor in the current package
266     p->Register(GetCurrentDescriptor());
267     
268     bbtkDebugMessage("kernel",9,"<== Executer::EndDefine(\""
269                      <<GetCurrentDescriptor()->GetTypeName()<<"\")" 
270                      <<std::endl);
271     mOpenDefinition.pop_back();
272   }
273   //======================================================================= 
274
275   //=======================================================================  
276   void Executer::Kind(const std::string& kind)
277   {
278     if (kind=="ADAPTOR")
279       {
280         GetCurrentDescriptor()->AddToCategory("adaptor");
281         GetCurrentDescriptor()->SetKind(bbtk::BlackBoxDescriptor::ADAPTOR);
282       }
283     else if (kind=="DEFAULT_ADAPTOR")
284       {
285         GetCurrentDescriptor()->AddToCategory("adaptor");
286         GetCurrentDescriptor()->SetKind(bbtk::BlackBoxDescriptor::DEFAULT_ADAPTOR);
287       }
288     if (kind=="GUI")
289       {
290         GetCurrentDescriptor()->AddToCategory("gui");
291         GetCurrentDescriptor()->SetKind(bbtk::BlackBoxDescriptor::GUI);
292       }
293     else if (kind=="DEFAULT_GUI")
294       {
295         GetCurrentDescriptor()->AddToCategory("gui");
296         GetCurrentDescriptor()->SetKind(bbtk::BlackBoxDescriptor::DEFAULT_GUI);
297       }
298     else
299       {
300         bbtkError("Unknown box kind : '"<<kind<<"'. "
301                   <<"Valid kinds are 'ADAPTOR','DEFAULT_ADAPTOR',"
302                   <<"'GUI','DEFAULT_GUI'");
303       }
304   }
305   //=======================================================================
306
307   //=======================================================================
308   void Executer::Create ( const std::string& nodeType, 
309                           const std::string& nodeName)
310   {
311      GetCurrentDescriptor()->Add(nodeType,nodeName);
312   }
313   //=======================================================================
314
315   //=======================================================================
316   void Executer::Destroy(const std::string &boxName)
317   {
318     GetCurrentDescriptor()->Remove(boxName,true);
319   }
320   //=======================================================================
321
322   //=======================================================================
323   void Executer::Connect (const std::string &nodeFrom,
324                           const std::string &outputLabel,
325                           const std::string &nodeTo, 
326                           const std::string &inputLabel)
327   {
328     GetCurrentDescriptor()->Connect(nodeFrom, outputLabel, nodeTo, inputLabel);
329   }
330   //=======================================================================
331
332   //=======================================================================
333   void Executer::Execute (const std::string &nodeName) 
334   {
335     // if in root
336     if (GetCurrentDescriptor()==GetWorkspace()) 
337      {
338         if (!mNoExecMode) 
339         {
340            GetCurrentDescriptor()->GetPrototype()->bbGetBlackBox(nodeName)->bbExecute(true);
341         }
342      }
343      else 
344      {
345         GetCurrentDescriptor()->AddToExecutionList(nodeName) ;
346      }
347   }
348   //=======================================================================
349
350   //=======================================================================
351   void Executer::DefineInput ( const std::string &name,
352                                const std::string &box,
353                                const std::string &input,
354                                const std::string& help)
355   {
356     // If the input is defined in the Root box
357     if (GetCurrentDescriptor()==GetWorkspace()) 
358       {
359       // If the dialog mode is set to NoDialog
360       // and the user passed the name in the Inputs map 
361       // then the associated value is set to the box.input
362       // This is the way command line parameters are passed to the Root box
363          if (mDialogMode == NoDialog) 
364          {
365          // find if name is in mInputs
366             std::map<std::string,std::string>::iterator i;
367             i = mInputs.find(name);
368             if (i!=mInputs.end()) {
369                Set(box,input,(*i).second);
370             }
371          }
372         // If the dialog mode is set to TextDialog
373         // The user is prompted for the value
374         else if (mDialogMode == TextDialog) 
375         {
376            std::cout << name << "=";
377            std::string ans;
378            std::cin >> ans;
379            Set(box,input,ans);
380         }
381 #ifdef USE_WXWIDGETS
382        // If the dialog mode is set to GraphicalDialog
383        // A dialog box is pop up
384        else if (mDialogMode == GraphicalDialog) 
385        {
386           std::string mess("Enter the value of '");
387           mess += name;
388           mess += "' (";
389           mess += help;
390           mess += ")";
391           std::string title(name);
392           title += " ?";
393           std::string ans = wx2std ( wxGetTextFromUser( std2wx (mess), std2wx(title)));
394           Set(box,input,ans); 
395        }
396 #endif
397     }
398
399     GetCurrentDescriptor()->DefineInput(name,box,input,help);
400
401   }
402   //=======================================================================
403
404   //=======================================================================
405    void Executer::DefineOutput ( const std::string &name,
406                                  const std::string &box,
407                                  const std::string &output,
408                                  const std::string& help)
409   {
410     GetCurrentDescriptor()->DefineOutput(name,box,output,help);
411   }
412   //=======================================================================
413
414   //=======================================================================
415   void Executer::Set (const std::string &box,
416                       const std::string &input,
417                       const std::string &value)
418   {
419     BlackBox::Pointer b = GetCurrentDescriptor()->GetPrototype()->bbGetBlackBox(box);
420     // Looks for the adaptor
421
422     if ( ( b->bbGetInputType(input) != typeid(bbtk::any<bbtk::thing>) )&&
423          ( b->bbGetInputType(input) != typeid(std::string) ) )
424       {
425         BlackBox::Pointer a =
426            GetFactory()->NewAdaptor(typeid(std::string),
427                                     b->bbGetInputType(input),
428                                     "tmp");
429          if (!a) 
430            {
431              bbtkError("No <"<<
432                        TypeName(b->bbGetInputType(input))
433                        <<"> to <std::string> found");
434            }
435          std::string v(value);
436          a->bbSetInput("In",v);
437          a->bbExecute();
438          b->bbSetInput(input,a->bbGetOutput("Out"));
439          //         a->Delete();
440       }
441     else 
442       {
443       std::string v(value);
444       b->bbSetInput(input,v);
445       }
446   }
447   //=======================================================================
448
449   //=======================================================================
450   std::string Executer::Get(const std::string &box,
451                             const std::string &output)
452   {
453     BlackBox::Pointer b = GetCurrentDescriptor()->GetPrototype()->bbGetBlackBox(box);
454     // Looks for the adaptor
455     if (b->bbGetOutputType(output) != typeid(std::string)) 
456       {
457         BlackBox::Pointer a =
458           GetFactory()->NewAdaptor(
459                                    b->bbGetOutputType(output),
460                                    typeid(std::string),
461                                    "tmp");
462         if (!a) 
463           {
464             bbtkError("No <"<<
465                       TypeName(b->bbGetOutputType(output))
466                       <<"> to <std::string> found");
467           }
468         b->bbExecute();
469         
470         a->bbSetInput("In",b->bbGetOutput(output));
471         a->bbExecute();
472         std::string r = a->bbGetOutput("Out").unsafe_get<std::string>();
473         //std::string v = *((std::string*)a->bbGetOutput("Out")) ;
474         //   std::cout << a->bbGetOutput("Out").unsafe_get<std::string>() 
475         //             << std::endl;
476         //std::string v(value);
477         //b->bbSetInput(input,a->bbGetOutput("Out"));
478         //        a->bbDelete();
479         return r;
480       }
481     else
482       {
483         b->bbExecute();
484         return b->bbGetOutput(output).unsafe_get<std::string>();
485         // std::string v = *((std::string*)b->bbGetOutput(output)) ;
486         // std::cout << b->bbGetOutput("Out").unsafe_get<std::string>() 
487         //   << std::endl;
488         // b->bbSetInput(input,&v);
489       }
490   }
491   //=======================================================================
492
493   //=======================================================================
494   void Executer::Author(const std::string &authorName)
495   {
496     GetCurrentDescriptor()->AddToAuthor(authorName,GetCurrentDescriptor()==GetWorkspace());
497   }
498   //=======================================================================
499
500   //=======================================================================
501   void Executer::Category(const std::string &category)
502   {
503     GetCurrentDescriptor()->AddToCategory(category,GetCurrentDescriptor()==GetWorkspace());
504   }
505   //=======================================================================
506
507   //=======================================================================
508   void Executer::Description(const std::string &d)
509   {
510     GetCurrentDescriptor()->AddToDescription(d,GetCurrentDescriptor()==GetWorkspace());
511   }
512   //=======================================================================
513
514
515
516   //=======================================================================
517   /// prints the list of the boxes of the current descriptor
518   void Executer::PrintHelpListBoxes()
519   {
520     bbtkMessage("help",1,"The black box descriptor \""
521                 <<GetCurrentDescriptor()->GetTypeName()<<"\" contains : "<<std::endl);
522     GetCurrentDescriptor()->PrintBlackBoxes();
523  }
524   //=======================================================================
525
526   //=======================================================================
527   std::string Executer::ShowGraph(const std::string &nameblackbox, 
528                                   const std::string &detailStr, 
529                                   const std::string &levelStr,
530                                   const std::string &output_html,
531                                   const std::string &custom_header,
532                                   const std::string &custom_title,
533                                   bool system_display )
534   {
535     int detail  =       atoi(detailStr.c_str());
536     int level   =       atoi(levelStr.c_str());
537           bool relative_link = true;
538
539     Package::Pointer p;
540     try
541     {
542        p = GetFactory()->GetPackage(nameblackbox);
543     }
544     catch (Exception e)
545     {
546       p = GetUserPackage();
547     }
548           
549       std::string doc_path = bbtk::ConfigurationFile::GetInstance().Get_doc_path();
550       doc_path += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
551       doc_path += "bbdoc";
552       doc_path += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
553           
554           std::string pack_name(p->GetName());
555           std::string pack_path = doc_path + pack_name;
556           // Creating directory
557           if ( ! bbtk::Utilities::FileExists(pack_path) )
558           {
559                   std::string command("mkdir \"" +pack_path+ "\"");
560                   system( command.c_str() );
561           }
562           std::string pack_index(pack_path);
563           pack_index += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
564           pack_index += "index.html"; 
565           
566           
567     // Generating documentation-help of workspace
568         p->SetDocURL(pack_index);
569     p->SetDocRelativeURL("index.html");
570         p->CreateHtmlPage(pack_index,"bbtk","user package",custom_header,custom_title,detail,level,relative_link);
571           
572     /*
573     try 
574     {
575        ShowGraphTypes(nameblackbox);
576     }
577     catch (bbtk::Exception a)
578     {
579        std::cout <<"EXC"<<std::endl;
580        page = ShowGraphInstances(nameblackbox,detail,level,system_display);
581     }
582     */
583     return pack_index;
584   }
585   //=======================================================================
586
587   //=======================================================================
588   /// Generate a png file with the actual pipeline (Graphviz-dot needed)
589   std::string Executer::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
590                                            bool system_display)
591   {
592
593     BlackBox::Pointer blackbox;
594     if (nameblackbox==".")
595     {
596        blackbox = GetCurrentDescriptor()->GetPrototype();
597     }
598     else
599     {
600        blackbox = GetCurrentDescriptor()->GetPrototype()->bbFindBlackBox(nameblackbox);
601     }
602     
603     std::string page;
604
605     if (blackbox)
606       {      
607         // Don't pollute the file store with  "temp_dir" directories ...
608         std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
609         char c = default_doc_dir.c_str()[strlen(default_doc_dir.c_str())-1];
610
611         std::string directory = default_doc_dir; 
612         if (c != '/' && c !='\\') directory = directory + "/";
613
614         directory = directory +  "temp_dir";
615         //std::string directory("temp_dir");
616         std::string filename(directory + "/" + "bbtk_graph_pipeline");
617         std::string filename_html(filename+".html");
618         std::string command0("mkdir \""+directory + "\"");
619
620 #if defined(_WIN32)
621         std::string command2("start ");
622 #else 
623         std::string command2("gnome-open ");
624 #endif
625
626         command2=command2+filename_html;
627         page = filename_html;
628         // 1. Generate Html Diagram
629         std::ofstream s;
630         s.open(filename_html.c_str());
631         if (s.good()) 
632           {
633             s << "<html><head><title>BBtk graph diagram</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head>\n";
634             s << "<body bgcolor=\"#FFFFFF\" text=\"#000000\"> \n\n";
635             if ( blackbox->bbGetName()=="workspacePrototype" )
636               {
637                 s << "<center>Current workspace</center>";
638               } else {
639               s << "<center>" << blackbox->bbGetName()<< "</center>";
640             } 
641             blackbox->bbInsertHTMLGraph( s, detail, level, true, directory, false );
642             s << "</body></html>\n";
643           }
644         s.close();
645         
646         // 2. Starting Browser
647         if (system_display) system( command2.c_str() );      
648       } 
649     else 
650       {
651         bbtkMessage("help",1,"No black box: \""
652                     <<nameblackbox<<"\" " <<std::endl);
653       }
654     return page;
655   }
656   //=======================================================================
657
658   //=======================================================================
659   void Executer::PrintHelpBlackBox(const std::string &nameblackbox, 
660                                const std::string &detailStr, 
661                                const std::string &levelStr)
662   {
663     bool found=false;
664     
665     int detail = atoi(detailStr.c_str());
666     int level  = atoi(levelStr.c_str());
667     BlackBox::Pointer blackbox;
668     if (nameblackbox.compare(".")==0)
669       {
670         blackbox=GetCurrentDescriptor()->GetPrototype();
671       } 
672     else 
673       {
674         blackbox = GetCurrentDescriptor()->GetPrototype()->bbFindBlackBox(nameblackbox);
675       }
676     
677     if (blackbox)
678       {
679         found=true;
680         blackbox->bbPrintHelp(blackbox,detail,level); //,mFactory);
681       }
682     
683     if (!found) 
684       {
685         bbtkError("box with name '"  <<nameblackbox<<"' unknown");
686       }
687   }
688   //=======================================================================
689
690   //=======================================================================
691   /// sets the level of message
692   void Executer::SetMessageLevel(const std::string &kind,
693                                  int level)
694   {
695     bbtk::MessageManager::SetMessageLevel(kind,level);
696   }
697   //=======================================================================
698
699   //=======================================================================
700   /// Prints help on the messages
701   void  Executer::HelpMessages()
702   {
703     bbtk::MessageManager::PrintInfo();
704   }
705   //=======================================================================
706
707   //=======================================================================
708   ///
709   void Executer::Print(const std::string &str)
710   {  
711     if (GetNoExecMode() &&  (GetCurrentDescriptor()==GetWorkspace()) ) return;
712     if (GetCurrentDescriptor()!=GetWorkspace()) return;
713
714     bbtkDebugMessage("kernel",9,"Executer::Print(\""<<str<<"\")"<<std::endl);
715
716  // TO DO :
717  // InterpretLine ("load std")
718  // InterpretLine("new ConcatStrings _C_ ") -> trouver un nom unique : # commande 
719  // InterpretLine("new Print _P_") 
720  // InterpretLine("connect _C_.Out _P_.In")
721  // int num = 1
722  
723
724     std::vector<std::string> chains;
725     std::string delimiters("$");
726
727     // Skip delimiters at beginning.
728     std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
729     bool is_text = true;
730     if (lastPos>0) is_text = false;
731
732     // Find first delimiter.
733     std::string::size_type pos     = str.find_first_of(delimiters, lastPos);
734
735     while (std::string::npos != pos || std::string::npos != lastPos)
736     {
737        if (is_text) 
738        {
739           // Found a text token, add it to the vector.
740           chains.push_back(str.substr(lastPos, pos - lastPos));
741  // std::string token = str.substr(lastPos, pos - lastPos)
742  // InterpretLine("set _C_.In%num% %token%")
743  
744        }
745        else 
746        {
747
748        // is an output (between $$) : decode 
749          std::string tok,box,output;
750          tok = str.substr(lastPos, pos - lastPos);
751          Utilities::SplitAroundFirstDot(tok,box,output);
752          chains.push_back( Get(box,output) );
753
754 // InterpretLine("connect %tok% _C_.In%num%") 
755
756        }
757         // Skip delimiters.  Note the "not_of"
758        lastPos = str.find_first_not_of(delimiters, pos);
759         // Find next delimiter
760        pos = str.find_first_of(delimiters, lastPos);
761     //
762        is_text = !is_text;
763 // num ++;
764      }
765 // InterpretLine("exec _P_")
766 // if (IS_IN_WORKSPACE) InterpretLine("delete _C_; delete _P_");
767
768     std::vector<std::string>::iterator i;
769     for (i= chains.begin(); i!=chains.end(); ++i) 
770       {
771         Utilities::SubsBackslashN(*i);
772         bbtkMessage("output",1,*i);
773       }
774     bbtkMessage("output",1,std::endl);
775   }
776   //==========================================================================
777
778   //==========================================================================
779   std::string Executer::GetObjectName() const
780   {
781     return std::string("Executer");
782   }
783   //==========================================================================
784   
785   //==========================================================================
786   std::string  Executer::GetObjectInfo() const 
787   {
788     std::stringstream i;
789     return i.str();
790   }
791   //==========================================================================
792   //==========================================================================
793 size_t  Executer::GetObjectSize() const 
794 {
795   size_t s = Superclass::GetObjectSize();
796   s += Executer::GetObjectInternalSize();
797   return s;
798   }
799   //==========================================================================
800   //==========================================================================
801 size_t  Executer::GetObjectInternalSize() const 
802 {
803   size_t s = sizeof(Executer);
804   return s;
805   }
806   //==========================================================================
807   //==========================================================================
808   size_t  Executer::GetObjectRecursiveSize() const 
809   {
810     size_t s = Superclass::GetObjectRecursiveSize();
811     s += Executer::GetObjectInternalSize();
812     s += mFactory->GetObjectRecursiveSize();
813     return s;
814   }
815   //==========================================================================
816 }//namespace