Program: bbtk
Module: $RCSfile: bbtkConfigurationFile.h,v $
Language: C++
- Date: $Date: 2008/03/10 06:24:12 $
- Version: $Revision: 1.6 $
+ Date: $Date: 2008/03/26 08:27:19 $
+ Version: $Revision: 1.7 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See doc/license.txt or
inline const std::string& Get_rsc_path() const
{ return mRsc_path;}
+ inline const std::string& Get_root_bbs_path() const
+ { return mBbs_path;}
inline const std::vector<std::string>& Get_bbs_paths() const
{ return mBbs_paths;}
inline const std::vector<std::string>& Get_package_paths() const
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
Program: bbtk
Module: $RCSfile: bbtkExecuter.h,v $ $
Language: C++
- Date: $Date: 2008/03/07 08:40:14 $
- Version: $Revision: 1.10 $
+ Date: $Date: 2008/03/26 08:27:19 $
+ Version: $Revision: 1.11 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
/// Sets the mode of dialog of the executer for Root inputs
void SetDialogMode(DialogModeType t) { mDialogMode = t; }
+
+
+ //=================================================================
+ /// Loads a package
+ void LoadPackage(const std::string &name );
+
+ /// Unloads a package
+ void UnLoadPackage(const std::string &name );
+
/// Starts a package block
void BeginPackage (const std::string &name );
const std::string &boxto,
const std::string &input);
- /// Updates the box
- /// would 'Execute' be more meaningfull ?
- void Update (const std::string &box);
+ /// Executes the box
+ void Execute (const std::string &box);
/// Defines an input of the current complex box
void DefineInput (const std::string &name,
const std::string &custom_title,
bool system_display = true);
- /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
+ /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true);
+
+ /// Description of the actual pipeline
+ void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr);
+
+ /// Resets the workspace : destroys all boxes / unloads all packages
+ void Reset();
- /// Description of the actual pipeline
- void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr);
+ /// Sets the level of message for kind
+ void SetMessageLevel(const std::string &kind,
+ int level);
+
+ /// Prints help on the messages
+ void HelpMessages();
+
- void Reset();
+ void Print(const std::string & message);
// static const std::string& GetObjectDescription();
// { static std::string s("Executer"); return s; }
Program: bbtk
Module: $RCSfile: bbtkInterpreter.cxx,v $ $
Language: C++
- Date: $Date: 2008/03/25 15:47:54 $
- Version: $Revision: 1.54 $
+ Date: $Date: 2008/03/26 08:27:19 $
+ Version: $Revision: 1.55 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
break;
case cDelete :
- // TO DO !!
- // mExecuter->Remove(words[1]);
+ mExecuter->Destroy(words[1]);
break;
case cConnect :
break;
case cPrint :
- Print(words[1]); /// \todo use generate command
+ mExecuter->Print(words[1]);
break;
case cExec :
else if (words[1]=="unfreeze")
mExecuter->SetNoExecMode(false);
else
- mExecuter->Update(words[1]);
+ mExecuter->Execute(words[1]);
break;
case cInput :
case cMessage :
if (words.size()<3)
{
- bbtk::MessageManager::PrintInfo();
+ mExecuter->HelpMessages();
}
else
{
- sscanf(words[2].c_str(),"%d",&level);
- bbtk::MessageManager::SetMessageLevel(words[1],level);
+ sscanf(words[2].c_str(),"%d",&level);
+ mExecuter->SetMessageLevel(words[1],level);
}
break;
break;
case cLoad:
- GetExecuter()->GetFactory()->LoadPackage(words[1]);
+ GetExecuter()->LoadPackage(words[1]);
break;
case cUnload:
- GetExecuter()->GetFactory()->UnLoadPackage(words[1]);
+ GetExecuter()->UnLoadPackage(words[1]);
break;
case cQuit :
delete mExecuter;
throw QuitException();
break;
-
+ /* obsolete
case cWorkspace :
if (words.size() == 2)
{
mExecuter->SetWorkspaceName(words[2]);
}
break;
-
+ */
default:
bbtkInternalError("should not reach here !!!");
}
//=======================================================================
- //=======================================================================
- // Replaces substrings "\\n" by a real carriage return "\n"
- void SubsBackslashN ( std::string& s )
- {
- std::string ss("\\n");
- std::string::size_type pos = 0;
- pos = s.find(ss,0);
- char* cr = "\n";
- while ( pos != std::string::npos )
- {
- s.replace(pos,2,cr,1);
- pos = s.find(ss, pos-1);
- }
- }
- //=======================================================================
-
+
//=======================================================================
/**
*
*/
+ /*
void Interpreter::Print( const std::string& str)
{
if (mExecuter->GetNoExecMode()) return;
for (i= chains.begin(); i!=chains.end(); ++i)
{
// bbtkMessage("Echo",1,*i);
- SubsBackslashN(*i);
+ Utilities::SubsBackslashN(*i);
std::cout << *i;
}
std::cout << std::endl;
bbtkDebugDecTab("Interpreter",9);
}
+*/
//=======================================================================
/**
bbtkMessage("Interpreter",1,
"look for : [" << name
<< "]" << std::endl);
- script_paths = ConfigurationFile::GetInstance().Get_bbs_paths();
+
std::string upath;
pkgname = Utilities::ExtractScriptName(name,upath);
bool fullnameGiven = false;
bool foundFile = false;
- if(pkgname == "*") // =========================================== load all boxes (e.g. std/boxes/*)
- {
- int nbBssFiles;
-
- std::stringstream* stream = new std::stringstream;
- //if (upath.size()!=0) // avoid troubles for "*"
-
- if (upath[0]=='/' || upath[1] == ':' ) // ==== absolute name, load all .bbs files
+ // ==== "*" provided : load all scripts in given path
+ // relative (e.g. std/boxes/*) or absolute
+ if (pkgname == "*")
{
- int nbFiles = Utilities::Explore(upath, false, Filenames);
- nbBssFiles = 0;
- for (std::vector<std::string>::iterator i = Filenames.begin(); i!= Filenames.end(); ++i)
- {
- int lgr = (*i).size();
- if (lgr < 5)
- continue; // ignore non .bbs file
- if ((*i).substr(lgr-4, 4) != ".bbs")
- continue;
-
-printf("EED Interpreter::SwitchToFile flag01 %s \n", (*i).c_str() );
- (*stream) << "include \"" << *i << "\"\n";
-
- nbBssFiles++;
- } // for vector
- if (nbBssFiles==0){
- bbtkMessage("Interpreter",2,
- "WARNING : No '.bbs' file found in ["
- << upath << "]" << std::endl);
- } else {
- SwitchToStream(stream);
- }
- return;
- } // if upath
-
- std::string path;
- std::vector<std::string>::iterator i;
- std::string fullDirectoryName;
- for (i=script_paths.begin();i!=script_paths.end();i++)// ==== relative name, iterate + load all .bbs files
- {
- path = *i;
-
- // we *really* want '.' to be the current working directory
- if (path == ".") {
- char buf[2048]; // for getcwd
- char * currentDir = getcwd(buf, 2048);
- std::string cwd(currentDir);
- path = currentDir;
- } // if path
-
- fullDirectoryName = Utilities::MakePkgnameFromPath(path, upath, false);
-
- // without last slash "\"
- std::string fullDirectoryNameClean = fullDirectoryName.substr(0,fullDirectoryName.size()-1);
-
- // Check if library exists
- if ( ! Utilities::IsDirectory( fullDirectoryNameClean ) )
- {
- // The following is *NOT* a debug time message :
- // It's a user intended message.
- // Please don't remove it.
- bbtkMessage("Interpreter",1," [" <<fullDirectoryName
- <<"] : doesn't exist" <<std::endl);
- continue; // try next path
- } // if IsDirectory
- foundFile = true;
-
- Filenames.clear();
- int nbFiles = Utilities::Explore(fullDirectoryName, false, Filenames);
+ int nbBssFiles;
+
+ std::stringstream* stream = new std::stringstream;
+ //if (upath.size()!=0) // avoid troubles for "*"
+
+ // ==== no path provided : look in root bbs path
+ if (upath.size()==0)
+ {
+ // bbtkMessage("Interpreter",1,
+ script_paths.push_back( ConfigurationFile::GetInstance().Get_root_bbs_path() );
+ }
+ // ==== absolute path provided
+ else if (upath[0]=='/' || upath[1] == ':' )
+ {
+ script_paths.push_back(upath);
+ }
+ // ==== relative path provided : search all bbs path appended with
+ // the relative path provided
+ else
+ {
+ std::vector<std::string>::const_iterator i;
+ for (i=ConfigurationFile::GetInstance().Get_bbs_paths().begin();
+ i!=ConfigurationFile::GetInstance().Get_bbs_paths().end();
+ i++)
+ {
+ std::string full_path(*i);
+ full_path += ConfigurationFile::GetInstance().Get_file_separator();
+ full_path += upath;
+ script_paths.push_back(full_path);
+ }
+ }
+ // === search paths list complete : now explore it
+ bbtkMessage("Interpreter",1,
+ "'*' provided. search paths : " << std::endl);
+ /*
+ int nbFiles = Utilities::Explore(upath, false, Filenames);
+ nbBssFiles = 0;
+ for (std::vector<std::string>::iterator i = Filenames.begin();
+ i!= Filenames.end(); ++i)
+ {
+ int lgr = (*i).size();
+ if (lgr < 5)
+ continue; // ignore non .bbs file
+ if ((*i).substr(lgr-4, 4) != ".bbs")
+ continue;
+ //printf("EED Interpreter::SwitchToFile flag01 %s \n", (*i).c_str() );
+ (*stream) << "include \"" << *i << "\"\n";
+
+ nbBssFiles++;
+ } // for vector
+ if (nbBssFiles==0)
+ {
+ bbtkMessage("Interpreter",2,
+ "WARNING : No '.bbs' file found in ["
+ << upath << "]" << std::endl);
+ }
+ else
+ {
+ SwitchToStream(stream);
+ }
+ return;
+ } // if upath
+ */
+ std::string path;
+ std::vector<std::string>::iterator i;
+ std::string fullDirectoryName;
+ for (i=script_paths.begin();i!=script_paths.end();i++)// ==== relative name, iterate + load all .bbs files
+ {
+ path = *i;
+
+ bbtkMessage("Interpreter",1,
+ "----> '" << path << "'" << std::endl);
+ // we *really* want '.' to be the current working directory
+ if (path == ".") {
+ char buf[2048]; // for getcwd
+ char * currentDir = getcwd(buf, 2048);
+ std::string cwd(currentDir);
+ path = currentDir;
+ } // if path
+
+ fullDirectoryName = Utilities::MakePkgnameFromPath(path, upath, false);
+
+ // without last slash "\"
+ std::string fullDirectoryNameClean = fullDirectoryName.substr(0,fullDirectoryName.size()-1);
+
+ // Check if directory exists
+ if ( ! Utilities::IsDirectory( fullDirectoryNameClean ) )
+ {
+ // The following is *NOT* a debug time message :
+ // It's a user intended message.
+ // Please don't remove it.
+ bbtkMessage("Interpreter",1," [" <<fullDirectoryName
+ <<"] : doesn't exist" <<std::endl);
+ continue; // try next path
+ } // if IsDirectory
+ foundFile = true;
+
+ Filenames.clear();
+ int nbFiles = Utilities::Explore(fullDirectoryName, false, Filenames);
+
+ nbBssFiles = 0;
+ for (std::vector<std::string>::iterator i = Filenames.begin(); i!= Filenames.end(); ++i)
+ {
+ int lgr = (*i).size();
+ if (lgr < 5)
+ continue; // ignore non .bbs file
+ if ((*i).substr(lgr-4, 4) != ".bbs")
+ continue;
+
+ // printf("EED Interpreter::SwitchToFile flag02 %s \n", (*i).c_str() );
+ (*stream) << "include \"" << *i << "\"\n";
+
+ nbBssFiles++;
+ } // for vector
+ if (nbBssFiles==0)
+ {
+ bbtkMessage("Interpreter",1,
+ "WARNING : No '.bbs' file found in ["
+ << fullDirectoryName << "]" << std::endl);
+ }
+ else
+ {
+ SwitchToStream(stream);
+ }
+
+ //break; // a directory was found; we stop iterating
+ // LG : No! We want all files included !
+ } // for vector
+ return;
+ }
+ //=============== end pkgname=="*" ===========
- nbBssFiles = 0;
- for (std::vector<std::string>::iterator i = Filenames.begin(); i!= Filenames.end(); ++i)
- {
- int lgr = (*i).size();
- if (lgr < 5)
- continue; // ignore non .bbs file
- if ((*i).substr(lgr-4, 4) != ".bbs")
- continue;
-
-printf("EED Interpreter::SwitchToFile flag02 %s \n", (*i).c_str() );
- (*stream) << "include \"" << *i << "\"\n";
-
- nbBssFiles++;
- } // for vector
- if (nbBssFiles==0){
- bbtkMessage("Interpreter",1,
- "WARNING : No '.bbs' file found in ["
- << fullDirectoryName << "]" << std::endl);
- } else {
- SwitchToStream(stream);
- }
-
- //break; // a directory was found; we stop iterating
- // LG : No! We want all files included !
- } // for vector
- return;
- } // if *
// if name starts with a / or a . or contains : user is assumed to have passed a relative/absolute name
// (not only a plain script name)
} // endif l != 0
}
else
- // =============================================================== iterate on the paths
- {
+ // =============================== iterate on the paths
+ {
+ script_paths = ConfigurationFile::GetInstance().Get_bbs_paths();
std::string path;
std::vector<std::string>::iterator i;
for (i=script_paths.begin();i!=script_paths.end();++i)
- {
- path = *i;
- // we *really* want '.' to be the current working directory
- if (path == ".") {
- char buf[2048]; // for getcwd
- char * currentDir = getcwd(buf, 2048);
- std::string cwd(currentDir);
- path = currentDir;
- }
-
- fullPathScriptName = Utilities::MakePkgnameFromPath(path, name, true);
-
- // Check if library exists
- if ( ! Utilities::FileExists(fullPathScriptName) )
- {
- // The following is *NOT* a debug time message :
- // It's a user intended message.
- // Please don't remove it.
- bbtkMessage("Interpreter",2,
- " [" <<fullPathScriptName <<"] : doesn't exist"
- <<std::endl);
- continue; // try next path
- }
- bbtkMessage("Interpreter",2,
- " [" <<fullPathScriptName
- <<"] : found" <<std::endl);
- foundFile = true;
- break; // a script was found; we stop iterating
-
- } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
+ {
+ path = *i;
+ // we *really* want '.' to be the current working directory
+ if (path == ".") {
+ char buf[2048]; // for getcwd
+ char * currentDir = getcwd(buf, 2048);
+ std::string cwd(currentDir);
+ path = currentDir;
+ }
+
+ fullPathScriptName = Utilities::MakePkgnameFromPath(path, name, true);
+
+ // Check if library exists
+ if ( ! Utilities::FileExists(fullPathScriptName) )
+ {
+ // The following is *NOT* a debug time message :
+ // It's a user intended message.
+ // Please don't remove it.
+ bbtkMessage("Interpreter",2,
+ " [" <<fullPathScriptName <<"] : doesn't exist"
+ <<std::endl);
+ continue; // try next path
+ }
+ bbtkMessage("Interpreter",2,
+ " [" <<fullPathScriptName
+ <<"] : found" <<std::endl);
+ foundFile = true;
+ break; // a script was found; we stop iterating
+
+ } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
}
-
+
if (!foundFile)
- {
- if (fullnameGiven)
- if(fullPathScriptName == "")
+ {
+ if (fullnameGiven)
+ if(fullPathScriptName == "")
bbtkError("Path ["<<upath<<"] doesn't exist");
- else
+ else
bbtkError("Script ["<<fullPathScriptName<<"] not found");
- else
+ else
bbtkError("No ["<<pkgname<<".bbs] script found");
- return;
- }
+ return;
+ }
else
LoadScript(fullPathScriptName,name);
-
+
return;
}
+ //=======================================================================
+ //=======================================================================
void Interpreter::SwitchToStream( std::stringstream* stream )
{
mFile.push_back(stream);
mIncludeFileName.push_back(buffer_name.str());
mLine.push_back(0);
}
+ //=======================================================================
//=======================================================================
Program: bbtk
Module: $RCSfile: bbtkInterpreter.h,v $ $
Language: C++
- Date: $Date: 2008/03/25 06:22:53 $
- Version: $Revision: 1.21 $
+ Date: $Date: 2008/03/26 08:27:19 $
+ Version: $Revision: 1.22 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
///
void Config() const;
///
- void Print(const std::string&);
+ // void Print(const std::string&);
void Index(const std::string& filename,
const std::string& type = "Initials");
Program: bbtk
Module: $RCSfile: bbtkTranscriptor.cxx,v $ $
Language: C++
- Date: $Date: 2008/03/07 10:21:30 $
- Version: $Revision: 1.7 $
+ Date: $Date: 2008/03/26 08:27:19 $
+ Version: $Revision: 1.8 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
}
-// ========================= Begin of Battlefield ========================================================================
-
-
-/**
- *
- */
+ // ================= Begin of Battlefield =============================
void Transcriptor::Reset()
{
m_Fp << " e->Reset( );" << std::endl;
-
- /*
- bbtkDebugMessageInc("Kernel",9,"Transcriptor::Reset()" <<std::endl);
-
- // The 'user' package must be closed before all other
- // because box destructors must not be unloaded when bb are deleted!
- // Similarly, the 'workspace' CBB must be destroyed before
- // all user defined CBB otherwise any instance
- // of a user CBB that is in the 'workspace' would try to
- // access a user CBB descriptor which has been previously freed
- if (mRoot)
- {
- mPackage->UnRegisterBlackBox(mRoot->GetTypeName());
- delete mRoot;
- }
- if (mPackage)
- {
- GetGlobalFactory()->UnLoadPackage("user");
- }
- GetGlobalFactory()->Reset();
- // Create user package
- mPackage = new Package("user","internal to bbi",
- "User defined black boxes",
- "",
- BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
- // Create user workspace
- mRoot = new ComplexBlackBoxDescriptor("workspace"); //,f);
- mRoot->AddToAuthor("bbi (internal)");
- mRoot->AddToDescription("User's workspace");
- mOpenDefinition.push_back(CBBDefinition(mRoot,"user"));
- // Register it into the user package
- mPackage->RegisterBlackBox(mRoot);
- // Insert the user package in the factory
- InsertPackage(mPackage);
- mOpenPackage.push_back(mPackage);
- bbtkDebugDecTab("Kernel",9);
- */
}
- /// changes the workspace name
void Transcriptor::SetWorkspaceName( const std::string& name )
{
- m_Fp << " e->SetWorkspaceName( \"" << name << "\" );" << std::endl;
-
- // mPackage->ChangeBlackBoxName( mRoot->GetTypeName(), name );
+ m_Fp << " e->SetWorkspaceName( \"" << name << "\" );" << std::endl;
}
void Transcriptor::BeginPackage (const std::string &name)
{
m_Fp << " e->BeginPackage( \"" << name << "\" );" << std::endl;
- /*
- bbtkDebugMessageInc("Kernel",9,"Executer::BeginPackage(\""<<name<<"\")"
- <<std::endl);
- Package* p;
- try
- {
- p = GetGlobalFactory()->GetPackage(name);
- }
- catch (Exception e)
- {
- p = new Package(name,
- "",
- "",
- "",
- BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
- InsertPackage(p);
- }
- mOpenPackage.push_back(p);
- */
}
void Transcriptor::EndPackage()
{
m_Fp << " e->EndPackage( );" << std::endl;
- // if (mOpenPackage.size()>1) mOpenPackage.pop_back();
}
void Transcriptor::Define (const std::string &name,
{
m_Fp << " e->Define(\"" << name << "\", \"" << pack << "\", \""
<< scriptfilename << "\" );" << std::endl;
- /*
- bbtkDebugMessageInc("Kernel",9,"Executer::Define(\""<<name<<
- ","<<pack<<"\")"
- <<std::endl);
-
- ComplexBlackBoxDescriptor* b = new ComplexBlackBoxDescriptor(name);
- b->SetScriptFileName(scriptfilename);
- mOpenDefinition.push_back( CBBDefinition( b, pack ) );
-
- bbtkDebugDecTab("Kernel",9);
- */
}
- /// Sets the file name to use for the current definition
- /// (Used to set it after the Define command)
void Transcriptor::SetCurrentFileName (const std::string &name )
{
m_Fp << " e->SetCurrentFileName( \"" << name << "\" );" << std::endl;
- // mOpenDefinition.back().box->SetScriptFileName(name);
}
void Transcriptor::EndDefine ()
{
m_Fp << " e->EndDefine( );" << std::endl;
-
- /*
- bbtkDebugMessageInc("Kernel",9,"Executer::EndDefine(\""
- <<Current()->GetTypeName()<<"\")"
- <<std::endl);
- // Does current package exist ?
- Package* p;
- std::string pname(mOpenDefinition.back().package);
- if (pname.size()>0)
- {
- try
- {
- p = GetGlobalFactory()->GetPackage(pname);
- }
- catch (Exception e)
- {
- p = new Package(pname,
- "",
- "",
- "",
- BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
- InsertPackage(p);
- }
- }
- else
- {
- p = mOpenPackage.back();
- }
- p->RegisterBlackBox(Current());
-
- mOpenDefinition.pop_back();
- */
-
}
void Transcriptor::Create ( const std::string& nodeType,
const std::string& nodeName)
{
- // Current()->Add(nodeType,nodeName);\"
- m_Fp << " e->Add(\"" << nodeType << "\", \"" << nodeName << "\");" << std::endl;
+ m_Fp << " e->Add(\"" << nodeType << "\", \""
+ << nodeName << "\");" << std::endl;
}
- /*
- void Transcriptor::Remove (const std::string &nodeName)
+ void Transcriptor::Destroy (const std::string &nodeName)
{
- /// \todo Remove
- // Current()->RemoveBlackBox(nodeName);
- // m_Fp << " e->Remove(" << nodeName << ");" << std::endl;
+ m_Fp << " e->Destroy(" << nodeName << ");" << std::endl;
}
- */
-/**
- *
- */
void Transcriptor::Connect (const std::string &nodeFrom,
const std::string &outputLabel,
const std::string &nodeTo,
const std::string &inputLabel)
{
- //Current()->Connect(nodeFrom, outputLabel, nodeTo, inputLabel);
- m_Fp << " e->Connect(\""<< nodeFrom << "\", \"" << outputLabel << "\", \""
- << nodeTo << "\", \"" << inputLabel<< "\");" << std::endl;
+ m_Fp << " e->Connect(\""<< nodeFrom << "\", \""
+ << outputLabel << "\", \""
+ << nodeTo << "\", \"" << inputLabel<< "\");" << std::endl;
}
- /**
- *
- */
- void Transcriptor::Update (const std::string &nodeName) // would 'Execute' be more meaningfull ?
+
+ void Transcriptor::Execute (const std::string &nodeName)
{
-
- m_Fp << " e->Update(\"" << nodeName << "\");" << std::endl;
-/*
- // if in root
- if (Current()==mRoot)
- {
- if (!mNoExecMode)
- {
- //Current()->GetPrototype()->bbGetBlackBox(nodeName)->bbExecute(true);
- m_Fp << " e->GetPrototype()->bbGetBlackBox(\"" << nodeName << "\", true );" << std::endl;
- }
- }
- else
- {
- //Current()->AddToExecutionList(nodeName) ;
- m_Fp << " e->AddToExecutionList(\"" << nodeName << "\");" << std::endl;
- }
-*/
+ m_Fp << " e->Execute(\"" << nodeName << "\");" << std::endl;
}
-/**
- *
- */
void Transcriptor::DefineInput ( const std::string &name,
const std::string &box,
const std::string &input,
m_Fp << " e->DefineInput(\""<< name << "\", " << box << ", "
<< input << ", \"" << help << "\");" << std::endl;
-
- /*
- // If the input is defined in the Root box
- if (Current()==mRoot)
- {
- // If the dialog mode is set to NoDialog
- // and the user passed the name in the Inputs map
- // then the associated value is set to the box.input
- // This is the way command line parameters are passed to the Root box
- if (mDialogMode == NoDialog)
- {
- // find if name is in mInputs
- std::map<std::string,std::string>::iterator i;
- i = mInputs.find(name);
- if (i!=mInputs.end()) {
- Set(box,input,(*i).second);
- }
- }
- // If the dialog mode is set to TextDialog
- // The user is prompted for the value
- else if (mDialogMode == TextDialog)
- {
- std::cout << name << "=";
- std::string ans;
- std::cin >> ans;
- Set(box,input,ans);
- }
-#ifdef _USE_WXWIDGETS_
- // If the dialog mode is set to GraphicalDialog
- // A dialog box is pop up
- else if (mDialogMode == GraphicalDialog)
- {
- std::string mess("Enter the value of '");
- mess += name;
- mess += "' (";
- mess += help;
- mess += ")";
- std::string title(name);
- title += " ?";
- std::string ans = wx2std ( wxGetTextFromUser( std2wx (mess), std2wx(title)));
- Set(box,input,ans);
- }
-#endif
- }
-
- Current()->DefineInput(name,box,input,help);
-*/
-
}
- /**
- *
- */
- void Transcriptor::DefineOutput ( const std::string &name,
- const std::string &box,
- const std::string &output,
- const std::string& help)
+
+ void Transcriptor::DefineOutput ( const std::string &name,
+ const std::string &box,
+ const std::string &output,
+ const std::string& help)
{
- // Current()->DefineOutput(name,box,output,help);
- m_Fp << " e->DefineOutput(\""<< name << "\", \"" << box << "\", \""
- << output << "\", \"" << help << "\");" << std::endl;
+ m_Fp << " e->DefineOutput(\""<< name << "\", \"" << box << "\", \""
+ << output << "\", \"" << help << "\");" << std::endl;
}
- /**
- *
- */
+
void Transcriptor::Set (const std::string &box,
const std::string &input,
const std::string &value)
{
- m_Fp << " e->Set(\""<< box << "\", \"" << input<< "\", \"" << value << "\");"
+ m_Fp << " e->Set(\""<< box << "\", \"" << input
+ << "\", \"" << value << "\");"
<< std::endl;
-
-/*
- BlackBox* b = Current()->GetPrototype()->bbGetBlackBox(box);
- // Looks for the adaptor
-
- if ( b->bbGetInputType(input) != typeid(std::string) )
- {
- BlackBox* a =
- NewAdaptor(typeid(std::string),
- b->bbGetInputType(input),
- "tmp");
- if (!a)
- {
- bbtkError("No <"<<
- TypeName(b->bbGetInputType(input))
- <<"> to <std::string> found");
- }
- std::string v(value);
- a->bbSetInput("In",v);
- a->bbExecute();
- b->bbSetInput(input,a->bbGetOutput("Out"));
- a->bbDelete();
- }
- else
- {
- std::string v(value);
- b->bbSetInput(input,v);
- }
-*/
}
- /**
- *
- */
std::string Transcriptor::Get(const std::string &box,
const std::string &output)
{
m_Fp << " e->Get(\""<< box << "\", \"" << output << "\");"
<< std::endl;
-/*
- BlackBox* b = Current()->GetPrototype()->bbGetBlackBox(box);
- // Looks for the adaptor
- if (b->bbGetOutputType(output) != typeid(std::string))
- {
- BlackBox* a =
- NewAdaptor(
- b->bbGetOutputType(output),
- typeid(std::string),
- "tmp");
- if (!a)
- {
- bbtkError("No <"<<
- TypeName(b->bbGetOutputType(output))
- <<"> to <std::string> found");
- }
- b->bbExecute();
-
- a->bbSetInput("In",b->bbGetOutput(output));
- a->bbExecute();
- std::string r = a->bbGetOutput("Out").unsafe_get<std::string>();
- //std::string v = *((std::string*)a->bbGetOutput("Out")) ;
- // std::cout << a->bbGetOutput("Out").unsafe_get<std::string>()
- // << std::endl;
- //std::string v(value);
- //b->bbSetInput(input,a->bbGetOutput("Out"));
- a->bbDelete();
- return r;
- }
- else
- {
- b->bbExecute();
- return b->bbGetOutput(output).unsafe_get<std::string>();
- // std::string v = *((std::string*)b->bbGetOutput(output)) ;
- // std::cout << b->bbGetOutput("Out").unsafe_get<std::string>()
- // << std::endl;
- // b->bbSetInput(input,&v);
- }
-*/
-// EED Windows
-return "";
+ return "";
}
void Transcriptor::Author(const std::string &authorName)
{
-
- m_Fp << " e->AddToAuthor(\"" << authorName << "\")" << std::endl;
- return; // just to see
-
- //Current()->AddToAuthor(authorName,Current()==mRoot);
+
+ m_Fp << " e->AddToAuthor(\"" << authorName << "\")" << std::endl;
}
void Transcriptor::Category(const std::string &category)
{
- m_Fp << " e->AddToCategory(\"" << category << "\")" << std::endl;
- //Current()->AddToCategory(category,Current()==mRoot);
+ m_Fp << " e->AddToCategory(\"" << category << "\")" << std::endl;
}
void Transcriptor::Description(const std::string &d)
{
- m_Fp << " e->AddToDescription(\"" << d << "\")" << std::endl;
- // Current()->AddToDescription(d,Current()==mRoot);
+ m_Fp << " e->AddToDescription(\"" << d << "\")" << std::endl;
}
/// prints the list of the boxes of the current descriptor
void Transcriptor::PrintBoxes()
{
m_Fp << " e->PrintBoxes( )" << std::endl;
- /*
- bbtkMessageInc("Help",1,"The black box descriptor \""
- <<Current()->GetTypeName()<<"\" contains : "<<std::endl);
- Current()->PrintBlackBoxes();
- bbtkDecTab("Help",1);
- */
}
// =========================End of Battlefield ========================================================================
bool system_display )
{
- m_Fp << " e->DefineOutput(\"" << nameblackbox << "\", \""
+ m_Fp << " e->ShowGraph(\"" << nameblackbox << "\", \""
<< detailStr << "\", \""
<< levelStr << "\", \""
<< output_html << "\", \""
<< custom_header << "\", \""
<< custom_title << "\");"
<< std::endl;
- /*
- int detail = atoi(detailStr.c_str());
- int level = atoi(levelStr.c_str());
-
- std::string filename_rootHtml (output_html) ;
- std::string simplefilename_rootHtml ( Utilities::get_file_name(output_html));
-
- bool relative_link = true;
-
- // No output provided : automatic generation
- if (output_html.length() == 0)
- {
- // Don't pollute the file store with "temp_dir" directories ...
- std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
-
- char c = default_doc_dir.c_str()[strlen(default_doc_dir.c_str())-1];
-
- std::string directory = default_doc_dir;
- if (c != '/' && c !='\\') directory = directory + "/";
- directory = directory + "temp_dir";
-
- filename_rootHtml = directory + "/" + "User.html";
- simplefilename_rootHtml = "User.html" ;
-
- // Creating directory
- std::string command0("mkdir \"" +directory + "\"");
- system( command0.c_str() );
-
- relative_link = false;
- }
-
- Package* p;
- try
- {
- p = GetGlobalFactory()->GetPackage(nameblackbox);
- }
- catch (Exception e)
- {
- p = mPackage;
- }
- // Generating documentation-help of workspace
- p->SetDocURL(filename_rootHtml);
- p->SetDocRelativeURL(simplefilename_rootHtml);
-
- p->CreateHtmlPage(filename_rootHtml,"bbi","user package",custom_header,custom_title,detail,level,relative_link);
-
- std::string page = filename_rootHtml;
- /*
- try
- {
- ShowGraphTypes(nameblackbox);
- }
- catch (bbtk::Exception a)
- {
- std::cout <<"EXC"<<std::endl;
- page = ShowGraphInstances(nameblackbox,detail,level,system_display);
- }
- */
- //return page;
- return ""; // to avoid warnings
+
+ return "";
}
- /// Generate a png file with the actual pipeline (Graphviz-dot needed)
- std::string Transcriptor::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
+ std::string Transcriptor::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
bool system_display)
{
-
- BlackBox* blackbox=NULL;
- if (nameblackbox==".")
- {
- blackbox=Current()->GetPrototype();
- }
- else
- {
- blackbox = Current()->GetPrototype()->bbFindBlackBox(nameblackbox);
- }
-
- std::string page;
-
- if (blackbox)
- {
- // Don't pollute the file store with "temp_dir" directories ...
- std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
- char c = default_doc_dir.c_str()[strlen(default_doc_dir.c_str())-1];
-
- std::string directory = default_doc_dir;
- if (c != '/' && c !='\\') directory = directory + "/";
-
- directory = directory + "temp_dir";
- //std::string directory("temp_dir");
- std::string filename(directory + "/" + "bbtk_graph_pipeline");
- std::string filename_html(filename+".html");
- std::string command0("mkdir \""+directory + "\"");
-
-#if defined(_WIN32)
- std::string command2("start ");
-#else
- std::string command2("gnome-open ");
-#endif
-
- command2=command2+filename_html;
- page = filename_html;
- // 1. Generate Html Diagram
- std::ofstream s;
- s.open(filename_html.c_str());
- if (s.good())
- {
- s << "<html><head><title>BBtk graph diagram</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head>\n";
- s << "<body bgcolor=\"#FFFFFF\" text=\"#000000\"> \n\n";
- if ( blackbox->bbGetName()=="workspacePrototype" )
- {
- s << "<center>Current workspace</center>";
- } else {
- s << "<center>" << blackbox->bbGetName()<< "</center>";
- }
-
- blackbox->bbInsertHTMLGraph( s, detail, level, true, directory, false );
- s << "</body></html>\n";
- }
- s.close();
-
- // 2. Starting Browser
- if (system_display) system( command2.c_str() );
- }
- else
- {
- bbtkMessageInc("Help",1,"No black box: \""
- <<nameblackbox<<"\" " <<std::endl);
- }
- return page;
+ return "";
+
}
void Transcriptor::ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr)
{
- 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<<">");
- }
+
+ }
+
+ void Transcriptor::Print(const std::string & message)
+ {
+ m_Fp << " e->Print(\"" <<message<<"\")"<<std::endl;
}
- /*
- /// sets the level of message
- void Transcriptor::Message(const std::string &kind,
- const std::string& level)
+
+
+ void Transcriptor::SetMessageLevel(const std::string &kind,
+ int level)
+ {
+ m_Fp << " e->SetMessageLevel(\"" <<kind<<"\","<<level<<")"<<std::endl;
+ }
+
+
+ void Transcriptor::HelpMessages()
+ {
+ m_Fp << " e->HelpMessages()"<<std::endl;
+ }
+
+ void Transcriptor::LoadPackage(const std::string &name )
{
- int l;
- sscanf(level.c_str(),"%d",&l);
- bbtk::MessageManager::SetMessageLevel(kind,l);
+ m_Fp << " e->LoadPackage(\"" <<name<<"\")"<<std::endl;
}
- */
+
+
+ void Transcriptor::UnLoadPackage(const std::string &name )
+ {
+ m_Fp << " e->UnLoadPackage(\"" <<name<<"\")"<<std::endl;
+ }
+
}//namespace
Program: bbtk
Module: $RCSfile: bbtkTranscriptor.h,v $ $
Language: C++
- Date: $Date: 2008/02/20 11:58:32 $
- Version: $Revision: 1.6 $
+ Date: $Date: 2008/03/26 08:27:19 $
+ Version: $Revision: 1.7 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
/// Sets the mode of dialog of the executer for Root inputs
void SetDialogMode(DialogModeType t) { mDialogMode = t; }
+ /// Loads a package
+ void LoadPackage(const std::string &name );
+
+ /// Unloads a package
+ void UnLoadPackage(const std::string &name );
+
/// Starts a package block
void BeginPackage (const std::string &name );
const std::string &input);
/// Updates the box
- /// would 'Execute' be more meaningfull ?
- void Update (const std::string &box);
+ void Execute(const std::string &box);
/// Defines an input of the current complex box
void DefineInput (const std::string &name,
void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr);
void Reset();
+
+ /// Sets the level of message for kind
+ void SetMessageLevel(const std::string &kind,
+ int level);
+
+ /// Prints help on the messages
+ void HelpMessages();
+
+ /// Prints the string ... MORE : TO EXPLAIN
+ void Print(const std::string & message);
// static const std::string& GetObjectDescription()
// { static std::string s("Executer"); return s; }
Program: bbtk
Module: $RCSfile: bbtkUtilities.h,v $
Language: C++
- Date: $Date: 2008/03/10 06:24:13 $
- Version: $Revision: 1.13 $
+ Date: $Date: 2008/03/26 08:27:19 $
+ Version: $Revision: 1.14 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See doc/license.txt or
/// Holds various usefull methods
struct BBTK_EXPORT Utilities
{
-
-// ===================================================================================
-
- // See : http://www.techbytes.ca/techbyte103.html for more O.S.
- static inline bool FileExists(std::string strFilename)
- {
- struct stat stFileInfo;
+
+ // ======================================================================
+ // See : http://www.techbytes.ca/techbyte103.html for more O.S.
+ static inline bool FileExists(std::string strFilename)
+ {
+ struct stat stFileInfo;
bool blnReturn;
int intStat;
-
+
// Attempt to get the file attributes
intStat = stat(strFilename.c_str(),&stFileInfo);
- if(intStat == 0) {
- // We were able to get the file attributes
- // so the file obviously exists.
- blnReturn = true;
- } else {
- // We were not able to get the file attributes.
- // This may mean that we don't have permission to
- // access the folder which contains this file. If you
- // need to do that level of checking, lookup the
- // return values of stat which will give you
- // more details on why stat failed.
- blnReturn = false;
- }
-
+ if(intStat == 0)
+ {
+ // We were able to get the file attributes
+ // so the file obviously exists.
+ blnReturn = true;
+ }
+ else
+ {
+ // We were not able to get the file attributes.
+ // This may mean that we don't have permission to
+ // access the folder which contains this file. If you
+ // need to do that level of checking, lookup the
+ // return values of stat which will give you
+ // more details on why stat failed.
+ blnReturn = false;
+ }
+
return(blnReturn);
- }
-
-
-// ===================================================================================
-
- static std::string ExtractPackageName(const std::string &name,
- std::string& path)
- {
- std::string pkgname;
- path = "";
-
- std::string::size_type slash_position = name.find_last_of("/\\");
- if (slash_position != std::string::npos)
- {
- pkgname = name.substr(slash_position+1,std::string::npos);
- path = name.substr(0,slash_position);
- // std::cout << "F:P='"<<path<<"'"<<std::endl;//+1,std::string::npos);
}
- else
+
+
+ // =====================================================================
+
+ static std::string ExtractPackageName(const std::string &name,
+ std::string& path)
{
- pkgname = name;
- }
-
- // remove {.so | dll} if any
- std::string::size_type dot_position = pkgname.find_last_of('.');
- if (dot_position != std::string::npos){
- pkgname = pkgname.substr(0,dot_position);
- }
+ std::string pkgname;
+ path = "";
+
+ std::string::size_type slash_position = name.find_last_of("/\\");
+ if (slash_position != std::string::npos)
+ {
+ pkgname = name.substr(slash_position+1,std::string::npos);
+ path = name.substr(0,slash_position);
+ // std::cout << "F:P='"<<path<<"'"<<std::endl;//+1,std::string::npos);
+ }
+ else
+ {
+ pkgname = name;
+ }
+
+ // remove {.so | dll} if any
+ std::string::size_type dot_position = pkgname.find_last_of('.');
+ if (dot_position != std::string::npos){
+ pkgname = pkgname.substr(0,dot_position);
+ }
#if defined(__GNUC__)
-
- // GCC mechanism
- // shared lib name = libbb<name>.so
-
+
+ // GCC mechanism
+ // shared lib name = libbb<name>.so
+
// remove {libbb} if any
- if (memcmp ( pkgname.c_str(), "libbb", 5) == 0) {
- pkgname = pkgname.substr(5, pkgname.length());
- }
+ if (memcmp ( pkgname.c_str(), "libbb", 5) == 0) {
+ pkgname = pkgname.substr(5, pkgname.length());
+ }
/*
- /// \ \todo what would happen if (stupid) user names his package 'libbb' ?!?
+ /// \ \todo what would happen if (stupid) user names his package 'libbb' ?!?
/// \ --> Should be forbidden!
*/
#elif defined(_WIN32)
-
- // WIN 32 mechanism
- // shared lib name = <name>.dll
-
-// EED Problem loading package call bbtkTools
-// // remove {bb} if any
- if (memcmp (pkgname.c_str(), "bb", 2) == 0) {
- pkgname = pkgname.substr(2, pkgname.length());
- }
-
- /*
+
+ // WIN 32 mechanism
+ // shared lib name = <name>.dll
+
+ // EED Problem loading package call bbtkTools
+ // // remove {bb} if any
+ if (memcmp (pkgname.c_str(), "bb", 2) == 0) {
+ pkgname = pkgname.substr(2, pkgname.length());
+ }
+
+ /*
/// \ \todo what would happen if (stupid) user names his package 'bb' ?!?
/// \ --> Should be forbidden!
*/
#else
- bbtkError("neither __GNUC__ nor _WIN32 ?!? How did you compile ?");
+ bbtkError("neither __GNUC__ nor _WIN32 ?!? How did you compile ?");
#endif
- return pkgname;
- }
-
-// ===================================================================================
-
- static std::string ExtractScriptName(const std::string &name,
- std::string& path)
- {
- std::string pkgname;
-
- std::string::size_type slash_position = name.find_last_of("/\\");
- if (slash_position != std::string::npos) {
- pkgname =name.substr(slash_position+1,std::string::npos);
- path = name.substr(0,slash_position);
- } else {
- pkgname = name;
- }
- // remove {.bbs } if any
- std::string::size_type dot_position = pkgname.find_last_of('.');
- if (dot_position != std::string::npos){
- pkgname = pkgname.substr(0,dot_position);
+ return pkgname;
}
- return pkgname;
- }
-
-// ===================================================================================
-
- static std::string ExpandLibName(const std::string &name, bool verbose)
- {
- // ----- Think of expanding path name ( ./ ../ ../../ )
-
- char buf[2048]; // for getcwd
- char * currentDir = getcwd(buf, 2048);
- std::string cwd(currentDir);
- std::string libname(name);
- std::string fileSeparator;
- fileSeparator = ConfigurationFile::GetInstance().Get_file_separator();
- // tooHigh : true is user supplies a library pathname with too many "../"
- bool tooHigh = false;
-//std::cout << "------------------cwd [" << cwd << "] name [" << name << "]" << std::endl;
-
- if ( name[0] == '/' || name[1] == ':' ) // Linux or Windows absolute name
- {
- return(libname);
- }
- else if ( name =="." )
+ //=====================================================================
+ static std::string ExtractScriptName(const std::string &name,
+ std::string& path)
{
- libname = cwd + fileSeparator;
- return(libname);
- }
- else if (name[0] == '.' && (name[1] == '/' || name[1] == '\\') )
- {
- libname = cwd + fileSeparator + name.substr(2, name.length());
- return(libname);
+ std::string pkgname;
+
+ std::string::size_type slash_position = name.find_last_of("/\\");
+ if (slash_position != std::string::npos) {
+ pkgname =name.substr(slash_position+1,std::string::npos);
+ path = name.substr(0,slash_position);
+ } else {
+ pkgname = name;
+ }
+ // remove {.bbs } if any
+ std::string::size_type dot_position = pkgname.find_last_of('.');
+ if (dot_position != std::string::npos){
+ pkgname = pkgname.substr(0,dot_position);
+ }
+ return pkgname;
}
- else if ( name[0] == '.' && name[1] == '.' /* && (name[2] == '/' || name[2] == '\\') */ )
+
+ // ========================================================================
+
+ static std::string ExpandLibName(const std::string &name, bool verbose)
{
- if ( IsAtRoot(cwd) ) // hope it gets / (for Linux), C: D: (for Windows)
+ // ----- Think of expanding path name ( ./ ../ ../../ )
+
+ char buf[2048]; // for getcwd
+ char * currentDir = getcwd(buf, 2048);
+ std::string cwd(currentDir);
+ std::string libname(name);
+ std::string fileSeparator;
+ fileSeparator = ConfigurationFile::GetInstance().Get_file_separator();
+ // tooHigh : true is user supplies a library pathname with too many "../"
+ bool tooHigh = false;
+
+ //std::cout << "------------------cwd [" << cwd << "] name [" << name << "]" << std::endl;
+
+ if ( name[0] == '/' || name[1] == ':' ) // Linux or Windows absolute name
+ {
+ return(libname);
+ }
+ else if ( name =="." )
+ {
+ libname = cwd + fileSeparator;
+ return(libname);
+ }
+ else if (name[0] == '.' && (name[1] == '/' || name[1] == '\\') )
+ {
+ libname = cwd + fileSeparator + name.substr(2, name.length());
+ return(libname);
+ }
+ else if ( name[0] == '.' && name[1] == '.' /* && (name[2] == '/' || name[2] == '\\') */ )
+ {
+ if ( IsAtRoot(cwd) ) // hope it gets / (for Linux), C: D: (for Windows)
{
// if we are already at / or c: --> hopeless
if (verbose)
return libname;
}
-// ===================================================================================
-
- static inline bool IsAtRoot(std::string cwd)
- {
- if ( cwd == "/" // hope it gets / (for Linux)
- || (cwd.size() <= 3 && cwd[1] == ':') ) // hope it gets C: D: (for Windows)
- return (true);
- else
- return(false);
- }
-
-// ===================================================================================
-
-static bool IsDirectory(std::string const &dirName)
-{
- struct stat fs;
-
- if ( stat(dirName.c_str(), &fs) == 0 )
- {
+ //========================================================================
+
+ static inline bool IsAtRoot(std::string cwd)
+ {
+ if ( cwd == "/" // hope it gets / (for Linux)
+ || (cwd.size() <= 3 && cwd[1] == ':') ) // hope it gets C: D: (for Windows)
+ return (true);
+ else
+ return(false);
+ }
+
+ // ======================================================================
+
+ static bool IsDirectory(std::string const &dirName)
+ {
+ struct stat fs;
+
+ if ( stat(dirName.c_str(), &fs) == 0 )
+ {
#if _WIN32
- return ((fs.st_mode & _S_IFDIR) != 0);
+ return ((fs.st_mode & _S_IFDIR) != 0);
#else
- return S_ISDIR(fs.st_mode);
+ return S_ISDIR(fs.st_mode);
#endif
- }
- else
- {
- return false;
- }
-}
-
-// ===================================================================================
-
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ // ===================================================================================
+
static inline void SplitAroundFirstDot( const std::string& in,
std::string& left,
std::string& right)
- {
+ {
std::string delimiter = ".";
std::string::size_type pos = in.find_first_of(delimiter);
if (std::string::npos != pos)
- {
- left = in.substr(0,pos);
- right = in.substr(pos+1,in.size());
-
- }
+ {
+ left = in.substr(0,pos);
+ right = in.substr(pos+1,in.size());
+
+ }
else
- {
- // bbtkError(in<<" : expected 'a.b' format but no dot found");
- left ="";
- right = "";
- }
+ {
+ // bbtkError(in<<" : expected 'a.b' format but no dot found");
+ left ="";
+ right = "";
+ }
}
- //=======================================================================
- static inline void SplitString ( const std::string& str,
- const std::string& delimiters,
- std::vector<std::string>& tokens)
- {
- // Skip delimiters at beginning.
- std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
- // Find first delimiter.
- std::string::size_type pos = str.find_first_of(delimiters, lastPos);
+ //=======================================================================
+ static inline void SplitString ( const std::string& str,
+ const std::string& delimiters,
+ std::vector<std::string>& tokens)
+ {
+ // Skip delimiters at beginning.
+ std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
+ // Find first delimiter.
+ std::string::size_type pos = str.find_first_of(delimiters, lastPos);
+
+ while (std::string::npos != pos || std::string::npos != lastPos)
+ {
+ // Found a token, add it to the vector.
+ tokens.push_back(str.substr(lastPos, pos - lastPos));
+ // Skip delimiters. Note the "not_of"
+ lastPos = str.find_first_not_of(delimiters, pos);
+ // Find next delimiter
+ pos = str.find_first_of(delimiters, lastPos);
+ }
+
+ }
+ //=======================================================================
- while (std::string::npos != pos || std::string::npos != lastPos)
- {
- // Found a token, add it to the vector.
- tokens.push_back(str.substr(lastPos, pos - lastPos));
- // Skip delimiters. Note the "not_of"
- lastPos = str.find_first_not_of(delimiters, pos);
- // Find next delimiter
- pos = str.find_first_of(delimiters, lastPos);
- }
- }
- //=======================================================================
-
-
-// ===================================================================================
-
+ // ===================================================================================
+
static inline std::string get_file_name(const std::string& s)
{
std::string::size_type slash_position = s.find_last_of("/\\");
if (slash_position != std::string::npos)
- {
- return s.substr(slash_position+1,std::string::npos);
- }
+ {
+ return s.substr(slash_position+1,std::string::npos);
+ }
else
- {
- return s;
- }
+ {
+ return s;
+ }
}
-// ===================================================================================
-/**
- * \brief Explore a directory with possibility of recursion
- * return number of files read
- * @param dirpath directory to explore
- * @param recursive whether we want recursion or not
- */
-static int Explore(std::string const &dirpath, bool recursive, std::vector<std::string> &Filenames)
-{
- int numberOfFiles = 0;
- std::string fileName;
-
- std::string dirName = dirpath;
-
+ // ===================================================================================
+ /**
+ * \brief Explore a directory with possibility of recursion
+ * return number of files read
+ * @param dirpath directory to explore
+ * @param recursive whether we want recursion or not
+ */
+ static int Explore(std::string const &dirpath, bool recursive, std::vector<std::string> &Filenames)
+ {
+ int numberOfFiles = 0;
+ std::string fileName;
+
+ std::string dirName = dirpath;
+
#ifdef _MSC_VER
- WIN32_FIND_DATA fileData;
+ WIN32_FIND_DATA fileData;
HANDLE hFile = FindFirstFile((dirName+"*").c_str(), &fileData);
for(BOOL b = (hFile != INVALID_HANDLE_VALUE); b;
}
+
+ //=======================================================================
+ // Replaces substrings "\\n" by a real carriage return "\n"
+ static inline void SubsBackslashN ( std::string& s )
+ {
+ std::string ss("\\n");
+ std::string::size_type pos = 0;
+ pos = s.find(ss,0);
+ char* cr = "\n";
+ while ( pos != std::string::npos )
+ {
+ s.replace(pos,2,cr,1);
+ pos = s.find(ss, pos-1);
+ }
+ }
+ //=======================================================================
+
+
//========================================================================
// Usefull functions for html generation
//========================================================================
Program: bbtk
Module: $RCSfile: bbtkVirtualExec.h,v $ $
Language: C++
- Date: $Date: 2008/03/07 08:40:14 $
- Version: $Revision: 1.8 $
+ Date: $Date: 2008/03/26 08:27:19 $
+ Version: $Revision: 1.9 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
/// Sets the mode of dialog of the executer for Root inputs
virtual void SetDialogMode(DialogModeType t) = 0;
+ //=================================================================
+ /// Loads a package
+ virtual void LoadPackage(const std::string &name ) = 0;
+
+ /// Unloads a package
+ virtual void UnLoadPackage(const std::string &name ) = 0;
+
/// Starts a package block
virtual void BeginPackage (const std::string &name ) = 0;
boxName) = 0;
/// Destroys a black box
- //virtual void Destroy (const std::string &boxName) = 0;
+ virtual void Destroy (const std::string &boxName) = 0;
/// Connects the output boxOutput to the input boxInput
virtual void Connect (const std::string &boxfrom,
const std::string &boxto,
const std::string &input) = 0;
- /// Updates the box
- /// would 'Execute' be more meaningfull ?
- virtual void Update (const std::string &box) = 0;
+ /// Executes the box
+ virtual void Execute (const std::string &box) = 0;
/// Defines an input of the current complex box
virtual void DefineInput (const std::string &name,
/// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
virtual std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true) = 0;
- /// Description of the actual pipeline
- virtual void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr) = 0;
-
- virtual void Reset() = 0;
+ /// Description of the actual pipeline
+ virtual void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr) = 0;
+
+ virtual void Reset() = 0;
+
+ /// Sets the level of message for kind
+ virtual void SetMessageLevel(const std::string &kind, int level) = 0,;
+
+ /// Prints help on the messages
+ virtual void HelpMessages() = 0;
+ /// Prints the string ... MORE : TO EXPLAIN
+ virtual void Print(const std::string & message) = 0;
+
// static const std::string& GetObjectDescription() = 0;
// { static std::string s("VirtualExec"); return s; }
protected: