Program: bbtk
Module: $RCSfile: bbtkExecuter.cxx,v $ $
Language: C++
- Date: $Date: 2008/03/07 11:15:15 $
- Version: $Revision: 1.14 $
+ Date: $Date: 2008/03/26 08:27:19 $
+ Version: $Revision: 1.15 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
namespace bbtk
{
-/**
- *
- */
+ //=======================================================================
Executer::Executer()
:
mFactory(0),
Reset();
bbtkDebugDecTab("Kernel",9);
}
+ //=======================================================================
-/**
- *
- */
+ //=======================================================================
Executer::~Executer()
{
- //std::cout << "===================================== delete Executer\n";
bbtkDebugMessageInc("Kernel",9,"Executer::~Executer()" <<std::endl);
if (mRootCBB)
{
bbtkDebugDecTab("Kernel",9);
}
+ //=======================================================================
+
+ //=======================================================================
+ /// Loads a package
+ void Executer::LoadPackage(const std::string &name )
+ {
+ GetFactory()->LoadPackage(name);
+ }
+ //=======================================================================
+
+ //=======================================================================
+ /// Unloads a package
+ void Executer::UnLoadPackage(const std::string &name )
+ {
+ GetFactory()->UnLoadPackage(name);
+ }
+ //=======================================================================
-
-/**
- *
- */
+ //=======================================================================
void Executer::Reset()
{
bbtkDebugMessageInc("Kernel",9,"Executer::Reset()" <<std::endl);
bbtkDebugDecTab("Kernel",9);
}
+ //=======================================================================
+ //=======================================================================
/// changes the workspace name
void Executer::SetWorkspaceName( const std::string& n )
{
mRootPackage->ChangeBlackBoxName( mRootCBB->GetTypeName(), n );
}
-
+ //=======================================================================
+
+ //=======================================================================
void Executer::BeginPackage (const std::string &name)
{
bbtkDebugMessageInc("Kernel",9,"Executer::BeginPackage(\""<<name<<"\")"
}
mOpenPackage.push_back(p);
}
+ //=======================================================================
+ //=======================================================================
void Executer::EndPackage()
{
if (mOpenPackage.size()>1) mOpenPackage.pop_back();
}
+ //=======================================================================
+ //=======================================================================
void Executer::Define (const std::string &name,
const std::string &pack,
const std::string &scriptfilename)
bbtkDebugDecTab("Kernel",9);
}
+ //=======================================================================
+ //=======================================================================
/// Sets the file name to use for the current definition
/// (Used to set it after the Define command)
void Executer::SetCurrentFileName (const std::string &name )
{
mOpenDefinition.back().box->SetScriptFileName(name);
}
+ //=======================================================================
+ //=======================================================================
void Executer::EndDefine ()
{
bbtkDebugMessageInc("Kernel",9,"Executer::EndDefine(\""
mOpenDefinition.pop_back();
}
-
+ //=======================================================================
+ //=======================================================================
void Executer::Create ( const std::string& nodeType,
const std::string& nodeName)
{
Current()->Add(nodeType,nodeName);
}
+ //=======================================================================
- /*
- void Executer::Remove (const std::string &nodeName)
+ //=======================================================================
+ void Executer::Destroy(const std::string &boxName)
{
- // Current()->RemoveBlackBox(nodeName);
+ bbtkError("Executer::Destroy : NOT IMPLEMENTED !");
}
- */
+ //=======================================================================
-/**
- *
- */
+ //=======================================================================
void Executer::Connect (const std::string &nodeFrom,
const std::string &outputLabel,
const std::string &nodeTo,
{
Current()->Connect(nodeFrom, outputLabel, nodeTo, inputLabel);
}
+ //=======================================================================
- /**
- *
- */
- void Executer::Update (const std::string &nodeName) // would 'Execute' be more meaningfull ?
+ //=======================================================================
+ void Executer::Execute (const std::string &nodeName)
{
- // if in root
+ // if in root
if (Current()==mRootCBB)
{
if (!mNoExecMode)
Current()->AddToExecutionList(nodeName) ;
}
}
+ //=======================================================================
-/**
- *
- */
+ //=======================================================================
void Executer::DefineInput ( const std::string &name,
const std::string &box,
const std::string &input,
Current()->DefineInput(name,box,input,help);
}
+ //=======================================================================
- /**
- *
- */
+ //=======================================================================
void Executer::DefineOutput ( const std::string &name,
const std::string &box,
const std::string &output,
{
Current()->DefineOutput(name,box,output,help);
}
+ //=======================================================================
- /**
- *
- */
+ //=======================================================================
void Executer::Set (const std::string &box,
const std::string &input,
const std::string &value)
b->bbSetInput(input,v);
}
}
+ //=======================================================================
- /**
- *
- */
+ //=======================================================================
std::string Executer::Get(const std::string &box,
const std::string &output)
{
// b->bbSetInput(input,&v);
}
}
+ //=======================================================================
-
+ //=======================================================================
void Executer::Author(const std::string &authorName)
{
Current()->AddToAuthor(authorName,Current()==mRootCBB);
}
+ //=======================================================================
+ //=======================================================================
void Executer::Category(const std::string &category)
{
Current()->AddToCategory(category,Current()==mRootCBB);
}
+ //=======================================================================
+ //=======================================================================
void Executer::Description(const std::string &d)
{
Current()->AddToDescription(d,Current()==mRootCBB);
}
+ //=======================================================================
-
+ //=======================================================================
/// prints the list of the boxes of the current descriptor
void Executer::PrintBoxes()
{
Current()->PrintBlackBoxes();
bbtkDecTab("Help",1);
}
+ //=======================================================================
+ //=======================================================================
std::string Executer::ShowGraph(const std::string &nameblackbox,
const std::string &detailStr,
const std::string &levelStr,
*/
return page;
}
+ //=======================================================================
+ //=======================================================================
/// Generate a png file with the actual pipeline (Graphviz-dot needed)
std::string Executer::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
bool system_display)
}
return page;
}
+ //=======================================================================
-void Executer::ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr)
+ //=======================================================================
+ void Executer::ShowRelations(const std::string &nameblackbox,
+ const std::string &detailStr,
+ const std::string &levelStr)
{
- bool found=false;
+ bool found=false;
+
+ int detail = atoi(detailStr.c_str());
+ int level = atoi(levelStr.c_str());
+ BlackBox* blackbox=NULL;
+ if (nameblackbox.compare(".")==0)
+ {
+ blackbox=Current()->GetPrototype();
+ }
+ else
+ {
+ blackbox = Current()->GetPrototype()->bbFindBlackBox(nameblackbox);
+ }
+
+ if (blackbox)
+ {
+ found=true;
+ blackbox->bbShowRelations(blackbox,detail,level); //,mFactory);
+ }
+
+ if (!found)
+ {
+ bbtkError("Blackbox Name not found.. <" <<nameblackbox<<">");
+ }
+ }
+ //=======================================================================
- int detail = atoi(detailStr.c_str());
- int level = atoi(levelStr.c_str());
- BlackBox* blackbox=NULL;
- if (nameblackbox.compare(".")==0)
- {
- blackbox=Current()->GetPrototype();
- } else {
- blackbox = Current()->GetPrototype()->bbFindBlackBox(nameblackbox);
- }
+ //=======================================================================
+ /// sets the level of message
+ void Executer::SetMessageLevel(const std::string &kind,
+ int level)
+ {
+ bbtk::MessageManager::SetMessageLevel(kind,level);
+ }
+ //=======================================================================
+
+ //=======================================================================
+ /// Prints help on the messages
+ void Executer::HelpMessages()
+ {
+ bbtk::MessageManager::PrintInfo();
+ }
+ //=======================================================================
+
+ //=======================================================================
+ ///
+ void Executer::Print(const std::string &str)
+ {
+ if (GetNoExecMode() && (Current()==mRootCBB) ) return;
+ if (Current()!=mRootCBB) return;
+
+ bbtkDebugMessageInc("Interpreter",9,"Interpreter::Print(\""<<str<<"\")"<<std::endl);
+
+ // TO DO :
+ // InterpretLine ("load std")
+ // InterpretLine("new ConcatStrings _C_ ") -> trouver un nom unique : # commande
+ // InterpretLine("new Print _P_")
+ // InterpretLine("connect _C_.Out _P_.In")
+ // int num = 1
+
+
+ std::vector<std::string> chains;
+ std::string delimiters("$");
- if (blackbox)
+ // Skip delimiters at beginning.
+ std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
+ bool is_text = true;
+ if (lastPos>0) is_text = false;
+
+ // Find first delimiter.
+ std::string::size_type pos = str.find_first_of(delimiters, lastPos);
+
+ while (std::string::npos != pos || std::string::npos != lastPos)
+ {
+ if (is_text)
{
- found=true;
- blackbox->bbShowRelations(blackbox,detail,level); //,mFactory);
+ // Found a text token, add it to the vector.
+ chains.push_back(str.substr(lastPos, pos - lastPos));
+ // std::string token = str.substr(lastPos, pos - lastPos)
+ // InterpretLine("set _C_.In%num% %token%")
+
}
-
- if (!found)
+ else
{
- bbtkError("Blackbox Name not found.. <" <<nameblackbox<<">");
+
+ // is an output (between $$) : decode
+ std::string tok,box,output;
+ tok = str.substr(lastPos, pos - lastPos);
+ Utilities::SplitAroundFirstDot(tok,box,output);
+ chains.push_back( Get(box,output) );
+
+// InterpretLine("connect %tok% _C_.In%num%")
+
}
- }
+ // Skip delimiters. Note the "not_of"
+ lastPos = str.find_first_not_of(delimiters, pos);
+ // Find next delimiter
+ pos = str.find_first_of(delimiters, lastPos);
+ //
+ is_text = !is_text;
+// num ++;
+ }
+// InterpretLine("exec _P_")
+// if (IS_IN_WORKSPACE) InterpretLine("delete _C_; delete _P_");
- /*
- /// sets the level of message
- void Executer::Message(const std::string &kind,
- const std::string& level)
- {
- int l;
- sscanf(level.c_str(),"%d",&l);
- bbtk::MessageManager::SetMessageLevel(kind,l);
+ std::vector<std::string>::iterator i;
+ for (i= chains.begin(); i!=chains.end(); ++i)
+ {
+ // bbtkMessage("Echo",1,*i);
+ Utilities::SubsBackslashN(*i);
+ bbtkMessage("Output",1,*i);
+ }
+ bbtkMessage("Output",1,std::endl);
}
- */
-
}//namespace