Program: bbtk
Module: $RCSfile: bbtkBlackBox.cxx,v $
Language: C++
-Date: $Date: 2008/04/09 11:16:57 $
-Version: $Revision: 1.9 $
+Date: $Date: 2008/04/18 12:59:15 $
+Version: $Revision: 1.10 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See doc/license.txt or
namespace bbtk
{
-//EED
+
static bool bbmgSomeBoxExecuting = false;
static bool bbmgFreezeExecution = false;
- static std::set<BlackBox*> bbmgExecutionList;
+ static std::set<BlackBox::Pointer> bbmgExecutionList;
+ //=========================================================================
+ BlackBox::Deleter::Deleter()
+ {
+ }
+ //=========================================================================
+
+ //=========================================================================
+ void BlackBox::Deleter::Delete(Object* p)
+ {
+ BlackBox* b = dynamic_cast<BlackBox*>(p);
+ if (!b)
+ {
+ bbtkInternalError("BlackBox::Deleter::Delete("<<p->GetObjectName()
+ <<"["<<p<<"]) : "
+ <<"dynamic cast to BlackBox* failed !");
+ }
+ std::string name = p->GetObjectName();//b->bbGetNameWithParent();
+ bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\")"<<std::endl);
+
+
+ BlackBoxDescriptor::WeakPointer desc = b->bbGetDescriptor();
+ bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : deleting black box"<<std::endl);
+
+ b->bbDelete();
+
+ bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : releasing descriptor ["<<desc.lock()<<"]"<<std::endl);
+
+ if (!desc.expired())
+ {
+ Package::WeakPointer pack = desc.lock()->GetPackage();
+ if (!pack.expired())
+ {
+ Package::ReleaseBlackBoxDescriptor(pack,desc);
+ }
+ else
+ {
+ bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : descriptor package expired (was not held by a package and the box was the last instance)"<<std::endl);
+ }
+ }
+ else
+ {
+ bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : descriptor expired : nothing to do (was not held by a package or the box is a complex black box prototype)"<<std::endl);
+ }
+ bbtkDebugMessage("object",2,"<## BlackBox::Deleter(\""<<name<<"\")"<<std::endl);
+ }
+ //=========================================================================
//=========================================================================
BlackBox::BlackBox(const std::string &name)
: bbmName(name),
bbmStatus(MODIFIED),
bbmBoxProcessMode("Pipeline"),
- bbmParent(NULL),
+ bbmParent(),
bbmExecuting(false)
{
- bbtkDebugMessage("Kernel",7,"BlackBox::BlackBox(\""
+ bbtkDebugMessage("object",4,"==> BlackBox::BlackBox(\""
+ <<name<<"\")"<<std::endl);
+ bbtkDebugMessage("object",4,"<== BlackBox::BlackBox(\""
<<name<<"\")"<<std::endl);
}
//=========================================================================
: bbmName(name),
bbmStatus(from.bbmStatus),
bbmBoxProcessMode(from.bbmBoxProcessMode),
- bbmParent(NULL),
+ bbmParent(),
bbmExecuting(false)
{
- bbtkDebugMessage("Kernel",7,"BlackBox::BlackBox("
+ bbtkDebugMessage("object",4,"==> BlackBox::BlackBox("
+ <<from.bbGetFullName()<<",\""
+ <<name<<"\")"<<std::endl);
+ bbtkDebugMessage("object",4,"<== BlackBox::BlackBox("
<<from.bbGetFullName()<<",\""
<<name<<"\")"<<std::endl);
}
//=========================================================================
BlackBox::~BlackBox()
{
- // std::cout << "EED BlackBox::~BlackBox 01 [" << bbGetName()<<"]\n";
- bbtkDebugMessageInc("Kernel",7,"BlackBox::~BlackBox()"<<std::endl);
+ bbtkDebugMessage("object",4,"==> BlackBox::~BlackBox() ["<<bbmName
+ <<"]"<<std::endl);
this->bbDesallocateConnectors();
- //printf("EED BlackBox::~BlackBox 02 \n");
- bbtkDebugDecTab("Kernel",7);
- }
- //=========================================================================
-
- //=========================================================================
- /// Destruction method of a black box
- void BlackBox::bbDelete()
- {
- bbtkDebugMessage("Kernel",1,"BlackBox::bbDelete() ["
- <<bbGetFullName()<<"]"<<std::endl);
- bbGetDescriptor()->UnReference();
- this->bbUserDelete();
+ bbtkDebugMessage("object",4,"<== BlackBox::~BlackBox() ["<<bbmName
+ <<"]"<<std::endl);
}
//=========================================================================
if (force) bbSetModifiedStatus();
// Calls the main recursive update method
- bbBackwardUpdate(0);
+ bbBackwardUpdate(Connection::Pointer());
Wx::EndBusyCursor();
//=========================================================================
std::string BlackBox::bbGetFullName() const
{
- return bbGetNameWithParent()+"<"+this->bbGetDescriptor()->GetTypeName()+">";
+ return this->bbGetNameWithParent()+"<"+this->bbGetDescriptor()->GetTypeName()+">";
}
//=========================================================================
/// Returns the name with the name of the parent prepended if any
std::string BlackBox::bbGetNameWithParent() const
{
- if (bbmParent)
+ if (bbmParent.lock())
{
- return bbmParent->bbGetNameWithParent() + ":" + bbmName;
+ return bbmParent.lock()->bbGetNameWithParent() + ":" + bbmName;
}
else
{
{
bbtkDebugMessage("Kernel",8,"* Allocate \""<<i->first<<"\""<<std::endl);
bbGetInputConnectorMap()[i->second->GetName()]
- = new BlackBoxInputConnector(this);
+ = new BlackBoxInputConnector(GetThisPointer<BlackBox>());
}
const BlackBoxDescriptor::OutputDescriptorMapType& omap
= bbGetDescriptor()->GetOutputDescriptorMap();
bbtkDebugMessage("Process",9,
"-> Execution triggered by Reactive mode or BoxExecute input change"<<std::endl);
this->bbSetStatus(MODIFIED);
- bbGlobalAddToExecutionList( this );
+ bbGlobalAddToExecutionList( GetThisPointer<BlackBox>() );
}
else if ( bbGetStatus() == MODIFIED ) //! this->bbIsUptodate())
{
//=========================================================================
/// Connects the input <name> to the connection c
- void BlackBox::bbConnectInput( const std::string& name, Connection* c)
+ void BlackBox::bbConnectInput( const std::string& name, Connection::Pointer c)
{
bbtkDebugMessageInc("Kernel",7,
"BlackBox::bbConnectInput(\""<<name<<"\","<<c<<") ["
//=========================================================================
/// Connects the output <name> to the connection c
- void BlackBox::bbConnectOutput( const std::string& name, Connection* c)
+ void BlackBox::bbConnectOutput( const std::string& name, Connection::Pointer c)
{
bbtkDebugMessageInc("Kernel",7,
"BlackBox::bbConnectOutput(\""<<name<<"\","<<c<<") ["
//=========================================================================
/// Disconnects the input <name> from the connection c
- void BlackBox::bbDisconnectInput( const std::string& name, Connection* c)
+ void BlackBox::bbDisconnectInput( const std::string& name, Connection::Pointer c)
{
+ if (!c) return;
bbtkDebugMessageInc("Kernel",7,
"BlackBox::bbDisconnectInput(\""<<name
<<"\","<<c<<") ["
//=========================================================================
/// Disconnects the output <name> from the connection c
- void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c)
+ void BlackBox::bbDisconnectOutput( const std::string& name, Connection::Pointer c)
{
+ if (!c) return;
bbtkDebugMessageInc("Kernel",7,
"BlackBox::bbDisconnectOutput(\""<<name
<<"\","<<c<<") ["
if (bbGetOutputType(output).name() != typeid(std::string).name() )
{
// Look for factory
- Package* p = bbGetDescriptor()->GetPackage();
+ Package::Pointer p = bbGetDescriptor()->GetPackage();
if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
{
- Factory* f = *p->GetFactorySet().begin();
- BlackBox* a = 0;
+ Factory::Pointer f = p->GetFactorySet().begin()->lock();
+ BlackBox::Pointer a;
try
{
a = f->NewAdaptor(
} catch (bbtk::Exception e)
{
}
- if (a!=NULL){
+ if (a){
// bbUpdate();
a->bbSetInput("In",bbGetOutput(output));
a->bbExecute();
if (bbGetInputType(input) != typeid(std::string))
{
// Look for factory
- Package* p = bbGetDescriptor()->GetPackage();
+ Package::Pointer p = bbGetDescriptor()->GetPackage();
if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
{
- Factory* f = *p->GetFactorySet().begin();
- BlackBox* a = 0;
+ Factory::Pointer f = p->GetFactorySet().begin()->lock();
+ BlackBox::Pointer a;
try
{
a = f->NewAdaptor(
}catch (bbtk::Exception e)
{
}
- if (a!=NULL)
+ if (a)
{
// bbUpdate();
a->bbSetInput("In",bbGetInput(input));
//=========================================================================
/// Write Graphviz-dot description in file
void BlackBox::bbWriteDotFileBlackBox(FILE *ff,
- BlackBox *parentblackbox,
+ BlackBox::Pointer parentblackbox,
int detail, int level,
bool instanceOrtype,
bool relative_link )
// std::cout << labelStr << std::endl;
// Relation Input
- if (this!=parentblackbox){
+ if (GetThisPointer<BlackBox>()!=parentblackbox){
for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
{
if (i->second)
{
- Connection* con = i->second->GetConnection();
+ Connection::Pointer con = i->second->GetConnection();
if (con!=NULL){
- BlackBox *a=con->GetBlackBoxFrom();
- BlackBox *b=con->GetBlackBoxTo();
+ BlackBox::Pointer a=con->GetBlackBoxFrom();
+ BlackBox::Pointer b=con->GetBlackBoxTo();
fprintf(ff," ");
a->bbWriteDotInputOutputName(ff,false,detail,level);
if (detail==1)
//=========================================================================
- void BlackBox::bbShowRelations(BlackBox *parentblackbox,
+ void BlackBox::bbShowRelations(BlackBox::Pointer parentblackbox,
int detail, int level
/*,Factory *factory*/ )
{
ivalue.push_back(bbGetInputAsString(i->first));
if (ivalue.back().size()>valuelmax) valuelmax = ivalue.back().size();
std::string s("");
- Connection* con = i->second->GetConnection();
+ Connection::Pointer con = i->second->GetConnection();
if (con!=0){
s = con->GetBlackBoxFrom()->bbGetName();
s += ".";
ovalue.push_back(bbGetOutputAsString(o->first));
if (ovalue.back().size()>valuelmax) valuelmax = ovalue.back().size();
std::vector<std::string> ss;
- const std::vector<Connection*>& con = o->second->GetConnectionVector();
- std::vector<Connection*>::const_iterator c;
+ const std::vector<Connection::WeakPointer>& con
+ = o->second->GetConnectionVector();
+ std::vector<Connection::WeakPointer>::const_iterator c;
for (c=con.begin();c!=con.end();++c)
{
std::string s;
- s = (*c)->GetBlackBoxTo()->bbGetName();
+ s = (*c).lock()->GetBlackBoxTo()->bbGetName();
s += ".";
- s += (*c)->GetBlackBoxToInput();
+ s += (*c).lock()->GetBlackBoxToInput();
ss.push_back(s);
} // if con
oconn.push_back(ss);
"=> BlackBox::bbGlobalProcessExecutionList()"
<<std::endl);
- std::set<BlackBox*>::iterator i;
+ std::set<BlackBox::Pointer>::iterator i;
for (i=bbmgExecutionList.begin();
i!=bbmgExecutionList.end();
++i)
return bbmgFreezeExecution;
}
- void BlackBox::bbGlobalAddToExecutionList( BlackBox* b )
+ void BlackBox::bbGlobalAddToExecutionList( BlackBox::Pointer b )
{
bbmgExecutionList.insert(b);
}
}
//=========================================================================
+
+
} // EO namespace bbtk
// EOF