X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=kernel%2Fsrc%2FbbtkConnection.cxx;h=1e84edfa3d0395e3afa7da5b930913703c8d0ecf;hb=4ad5b5ee44357ad873bc8c43230defb6d0a79879;hp=8d60b38699afa0f73b65fa34d6243c95155a5d09;hpb=372f03317f05d4a436b0f9c39b98558ec4810b78;p=bbtk.git diff --git a/kernel/src/bbtkConnection.cxx b/kernel/src/bbtkConnection.cxx index 8d60b38..1e84edf 100644 --- a/kernel/src/bbtkConnection.cxx +++ b/kernel/src/bbtkConnection.cxx @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkConnection.cxx,v $ Language: C++ - Date: $Date: 2008/03/18 12:51:26 $ - Version: $Revision: 1.4 $ + Date: $Date: 2008/04/18 12:59:15 $ + 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 @@ -27,27 +27,41 @@ namespace bbtk { - + Connection::Pointer Connection::New(BlackBox::Pointer from, + const std::string& output, + BlackBox::Pointer to, + const std::string& input , + const Factory::Pointer f ) + { + bbtkDebugMessage("object",1,"##> Connection::Connection(\"" + <bbGetName()<<"\",\""<bbGetName()<<"\",\""<bbGetName()<<"\",\""<bbGetName()<<"\",\""<bbGetName()<<"\",\""<bbGetName()<<"\",\""< Connection::Connection(\"" + <bbGetName()<<"\",\""<bbGetName()<<"\",\""<bbHasOutput(output) ) @@ -99,9 +113,10 @@ namespace bbtk std::string name; name = from->bbGetName() + "." + output + "-" + to->bbGetName() + "." + input; - mAdaptor = mFactory->NewAdaptor(from->bbGetOutputType(output), - to->bbGetInputType(input), - name); + mAdaptor = mFactory.lock() + ->NewAdaptor(from->bbGetOutputType(output), + to->bbGetInputType(input), + name); if (!mAdaptor) { bbtkError("did not find any <" @@ -113,29 +128,60 @@ namespace bbtk } } - // - from->bbConnectOutput(output,this); - to->bbConnectInput(input,this); + // Lock this pointer !!! + Pointer p = MakePointer(this,true); + from->bbConnectOutput(output,p); + to->bbConnectInput(input,p); + mFrom = from; + mOriginalFrom = from; + mTo = to; + mOriginalTo = to; + mInput = mOriginalInput = input; + mOutput = mOriginalOutput = output; + - bbtkDebugDecTab("Kernel",7); + bbtkDebugMessage("object",2,"==> Connection::Connection(\"" + <bbGetName()<<"\",\""<bbGetName()<<"\",\""< Connection::~Connection() [" + <bbDisconnectOutput(mOutput,this); - mTo->bbDisconnectInput(mInput,this); - if (mAdaptor) mAdaptor->bbDelete(); + if (mAdaptor) mAdaptor.reset(); + mOriginalFrom.reset(); + mOriginalTo.reset(); + if (mFrom!=0) + { + mFrom->bbDisconnectOutput(mOutput, + GetThisPointer()); + } + else + { + bbtkInternalError("Connection::~Connection() : invalid initial box pointer"); + } + if (mTo!=0) + { + mTo->bbDisconnectInput(mInput, + GetThisPointer()); + } + else + { + bbtkInternalError("Connection::~Connection() : invalid final box pointer"); + } + mFrom.reset(); + mTo.reset(); - bbtkDebugDecTab("Kernel",7); + bbtkDebugMessage("object",2, + "<== Connection::~Connection() [" + <bbBackwardUpdate(this); + s = mFrom->bbBackwardUpdate(GetThisPointer()); TransferData(); @@ -228,12 +274,13 @@ namespace bbtk else { // 2) Look for an adaptor - bbtk::BlackBox* adaptor = 0; + bbtk::BlackBox::Pointer adaptor; try { - adaptor = mFactory->NewAdaptor(mFrom->bbGetOutput(mOutput).type(), - mTo->bbGetInputType(mInput), - ""); + adaptor = mFactory.lock() + ->NewAdaptor(mFrom->bbGetOutput(mOutput).type(), + mTo->bbGetInputType(mInput), + ""); } catch (...) { @@ -246,7 +293,7 @@ namespace bbtk adaptor->bbExecute(); // LG : Connection Update does not set mTo as modified mTo->bbSetInput(mInput, adaptor->bbGetOutput("Out"),false); - adaptor->bbDelete(); + // adaptor->bbDelete(); } // 3) If no adaptor found but the any content is a pointer // and target type is also a pointer : we try run-time cast @@ -314,14 +361,171 @@ namespace bbtk //================================================================== std::string Connection::GetFullName() const { - if (mFrom && mTo) - return mFrom->bbGetName()+"."+mOutput+"--" - +mTo->bbGetName()+"."+mInput; + if (mFrom && mTo) + { + std::string res = mFrom->bbGetName()+"."+mOutput+"--" + +mTo->bbGetName()+"."+mInput; + if ((!mOriginalFrom.expired()) && (!mOriginalTo.expired()) && + ((mFrom!=mOriginalFrom.lock())||(mTo!=mOriginalTo.lock()))) + { + res += "("+mOriginalFrom.lock()->bbGetName() + +"."+mOriginalOutput+"--" + + mOriginalTo.lock()->bbGetName()+"."+mOriginalInput+")"; + } + return res; + } return "***Invalid Connection***"; } //================================================================== + //================================================================== + void Connection::Check() const + { + bbtkMessage("Debug",1,"** Checking Connection "<<(void*)this<<" ["<bbGetFullName()<bbHasOutput(mOutput)) + { + bbtkError("** Checking Connection "<<(void*)this + <<" ["<bbGetFullName()<<" does not have output '" + <bbGetOutputConnectorMap().find(mOutput); + if (i== mFrom->bbGetOutputConnectorMap().end()) + { + bbtkError("** Checking Connection "<<(void*)this + <<" ["<bbGetFullName()<<" output '" + <::const_iterator j; + for (j = i->second->GetConnectionVector().begin(); + j != i->second->GetConnectionVector().end(); + ++j) + { + if ((*j).lock()==GetThisPointer()) break; + } + /* + j = find(i->second->GetConnectionVector().begin(), + i->second->GetConnectionVector().end(), + GetThisPointer()); + */ + if (j==i->second->GetConnectionVector().end()) + { + bbtkError("** Checking Connection "<<(void*)this + <<" ["<bbGetFullName() + <<" does not point to this connection"); + + } + bbtkMessage("Debug",2," - From : This connection is in OutputConnector connection vector"<bbGetName()<bbGetDescriptor() << std::endl; + // std::cout << mTo->bbGetDescriptor()->GetTypeName() << std::endl; + // mTo->bbGetFullName(); + bbtkMessage("Debug",2," - To : "<bbGetFullName()<bbHasInput(mInput)) + { + bbtkError("** Checking Connection "<<(void*)this + <<" ["<bbGetFullName()<<" does not have input '" + <bbGetInputConnectorMap().find(mInput); + if (i== mTo->bbGetInputConnectorMap().end()) + { + bbtkError("** Checking Connection "<<(void*)this + <<" ["<bbGetFullName()<<" input '" + <second->GetConnection()==0) + { + bbtkError("** Checking Connection "<<(void*)this + <<" ["<bbGetFullName() + <<" does not point to this connection"); + + } + bbtkMessage("Debug",2," - To : This connection is in InputConnector connection vector"<