X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkPackage.cxx;h=91cdb518372b220f124b1de33af8dc5c22c8912a;hb=12f2166f201f4e5a99c9c7876dadd09da81bfb51;hp=29bd891d79008fd75b062b1c9800d51f3f03d622;hpb=d7a6d341e2d11c175351212f0bf4812784dc57e5;p=bbtk.git diff --git a/kernel/src/bbtkPackage.cxx b/kernel/src/bbtkPackage.cxx index 29bd891..91cdb51 100644 --- a/kernel/src/bbtkPackage.cxx +++ b/kernel/src/bbtkPackage.cxx @@ -1,25 +1,47 @@ -/*========================================================================= - +/* + # --------------------------------------------------------------------- + # + # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image + # pour la SantÈ) + # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton + # Previous Authors : Laurent Guigues, Jean-Pierre Roux + # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil + # + # This software is governed by the CeCILL-B license under French law and + # abiding by the rules of distribution of free software. You can use, + # modify and/ or redistribute the software under the terms of the CeCILL-B + # license as circulated by CEA, CNRS and INRIA at the following URL + # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + # or in the file LICENSE.txt. + # + # As a counterpart to the access to the source code and rights to copy, + # modify and redistribute granted by the license, users are provided only + # with a limited warranty and the software's author, the holder of the + # economic rights, and the successive licensors have only limited + # liability. + # + # The fact that you are presently reading this means that you have had + # knowledge of the CeCILL-B license and that you accept its terms. + # ------------------------------------------------------------------------ */ + + + +/*========================================================================= Program: bbtk Module: $RCSfile: bbtkPackage.cxx,v $ Language: C++ - Date: $Date: 2008/04/22 06:59:31 $ - 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 - http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - + Date: $Date: 2012/11/16 08:49:01 $ + Version: $Revision: 1.37 $ =========================================================================*/ + + + /** *\file *\brief Class bbtk::Package : registers black boxes descriptors and is able to create instances of the black boxes registered. */ #include "bbtkPackage.h" +#include "bbtkComplexBlackBoxDescriptor.h" #include "bbtkMessageManager.h" #include "bbtkConfigurationFile.h" #include @@ -36,16 +58,14 @@ namespace bbtk Package::Pointer Package::New(const std::string& name, const std::string& author, const std::string& description, - const std::string& version, - const std::string& BBTKVersion) + const std::string& version) { bbtkDebugMessage("object",1,"##> Package::New('"< Package::Package('"< Package('"< Package::~Package(\""< ~Package(\""<GetName(); - - Package::BlackBoxMapType::iterator desc = - pack.lock()->GetBlackBoxMap().find(descname); - if (desc == pack.lock()->GetBlackBoxMap().end()) + + bbtkDebugMessage("package",5,"--- Releasing descriptor '" + <GetDescriptorMap().find(descname); + if (desc == pack.lock()->GetDescriptorMap().end()) { - bbtkDebugMessage("package",3, + bbtkDebugMessage("package",5, " Descriptor has already been released" - <second; @@ -131,25 +153,22 @@ namespace bbtk // if it is dead : remove it if (pdesc.expired()) { - bbtkDebugMessage("package",2," '"< '"<GetBlackBoxMap().find(descname); - if (desc != pack.lock()->GetBlackBoxMap().end()) - pack.lock()->GetBlackBoxMap().erase(desc); - } - else - { - bbtkDebugMessage("package",3," ... Descriptor still alive (" - <GetBlackBoxMap()[descname] = pdesc.lock(); - } + } // pack.expired + desc = pack.lock()->GetDescriptorMap().find(descname); + if (desc != pack.lock()->GetDescriptorMap().end()) pack.lock()->GetDescriptorMap().erase(desc); + } else { //pdesc.expired + bbtkDebugMessage("package",5," ... Descriptor still alive (" + <GetDescriptorMap()[descname] = pdesc.lock(); + } // pdesc.expired } //========================================================================== @@ -163,10 +182,10 @@ namespace bbtk packname<<"')"<mDynamicLibraryHandler ? 1:0; - long ndesc = pack.lock()->GetBlackBoxMap().size(); + long ndesc = pack.lock()->GetDescriptorMap().size(); long nrefs = pack.use_count(); - bbtkDebugMessage("package",2," "< No more external ref : checking descriptors" < descnamelist; - BlackBoxMapType::iterator i; - for (i=pack.lock()->mBlackBoxMap.begin(); - i!= pack.lock()->mBlackBoxMap.end(); + DescriptorMapType::iterator i; + for (i=pack.lock()->mDescriptorMap.begin(); + i!= pack.lock()->mDescriptorMap.end(); ++i) descnamelist.push_back(i->first); @@ -212,32 +231,40 @@ namespace bbtk // Is package still alive ? if (pack.expired()) { - bbtkDebugMessage("package",2,"--- Package::Release('"<< + bbtkDebugMessage("package",1,"--- Package::Release('"<< packname <<"') : package expired during release : bailing out"<mDescriptorMap[*descname]; + if ( (dyn==0) || (boost::dynamic_pointer_cast(desc)) ) + { + PackageReleaseBlackBoxDescriptorInternal(pack,*descname); + } +#else + PackageReleaseBlackBoxDescriptorInternal(pack,*descname); +#endif + } // UnLoadDynamicLibrary(pack); // Unload orphan dl packages Package::UnLoadReleasedDynamicallyLoadedPackages(); - - - } - bbtkDebugMessage("package",1,"<== Package::Release('"<< +#ifdef BBTK_COMPILE_DEBUG_MESSAGES + + bbtkDebugMessage("package",2,"<== Package::Release('"<< packname<<"')"<mDynamicLibraryHandler ? 1:0; - long ndesc = pack.lock()->GetBlackBoxMap().size(); + long ndesc = pack.lock()->GetDescriptorMap().size(); long nrefs = pack.use_count(); bbtkDebugMessage("package",1," ... Package still alive (" @@ -247,9 +274,10 @@ namespace bbtk } else { - bbtkDebugMessage("package",1," ... Package has been released" + bbtkDebugMessage("package",1," ... Package has been released" <mName; std::string dname = descr.lock()->GetTypeName(); bbtkDebugMessage("package",3,"==> Package::ReleaseBlackBoxDescriptor('"<< - packname<<"','"< Package::OpenDynamicLibrary(" <SetDocURL(doc); p->SetDocRelativeURL(reldoc); - bbtkDebugMessage("package",1,"<== Package::CreateFromDynamicLibrary(" + bbtkDebugMessage("package",2,"<== Package::CreateFromDynamicLibrary(" <mDynamicLibraryHandler)) return; - - + std::string packname = pack.lock()->GetName(); - bbtkDebugMessage("package",3,"==> Package::UnLoadDynamicLibrary('" + bbtkDebugMessage("package",5,"==> Package::UnLoadDynamicLibrary('" <GetBlackBoxMap().empty()) + + if (!pack.lock()->GetDescriptorMap().empty()) { - - bbtkDebugMessage("package",3," Package not empty ... abort" + + bbtkDebugMessage("package",5," Package not empty ... abort" < dynamic library for package '" + < package '"< Package::UnLoadReleasedDynamicallyLoadedPackages()"< Package::UnLoadReleasedDynamicallyLoadedPackages()"<::iterator i; - for (i=mReleasedDynamicallyLoadedPackages.begin(); - i!=mReleasedDynamicallyLoadedPackages.end(); - ++i) - { - if (!i->expired()) UnLoad(*i); - } - bbtkDebugMessage("package",2,"<== Package::UnLoadReleasedDynamicallyLoadedPackages()"<0){ + for (i=mReleasedDynamicallyLoadedPackages.begin(); + i!=mReleasedDynamicallyLoadedPackages.end(); + ++i) + { + if (!i->expired()) UnLoad(*i); + } + } +//JCP- 21-04-09 + bbtkDebugMessage("package",5,"<== Package::UnLoadReleasedDynamicallyLoadedPackages()"<GetName(); - bbtkDebugMessage("package",2,"==> Package::UnLoad("< Package::UnLoad("< dynamic library for package '" + < with name BlackBox::Pointer Package::NewBlackBox(const std::string& type, const std::string& name) const { - bbtkDebugMessageInc("Kernel",8,"Package<"<::NewBlackBox(\""<::NewBlackBox(\""<second->NewBlackBox(name); - bbtkDebugDecTab("Kernel",8); + bbtkDebugDecTab("kernel",8); return bb; } @@ -661,7 +721,7 @@ namespace bbtk const DataInfo& typeout, const std::string& name) const { - bbtkDebugMessageInc("Kernel",8,"Package<"<::NewAdaptor(" <second.lock()->NewBlackBox(name); - bbtkDebugDecTab("Kernel",8); + bbtkDebugDecTab("kernel",8); return bb; } @@ -689,7 +749,7 @@ namespace bbtk const DataInfo& typeout, const std::string& name) const { - bbtkDebugMessageInc("Kernel",8,"Package<"<::NewWidgetAdaptor(" <second.lock()->NewBlackBox(name); - bbtkDebugDecTab("Kernel",8); + bbtkDebugDecTab("kernel",8); return bb; } @@ -721,7 +781,7 @@ namespace bbtk const DataInfo& typeout, std::string& adaptor) const { - bbtkDebugMessageInc("Kernel",8,"Package<"<::FindWidgetAdaptor(" <second.lock()->GetTypeName(); - bbtkDebugDecTab("Kernel",8); + bbtkDebugDecTab("kernel",8); return true; } @@ -755,7 +815,7 @@ namespace bbtk const DataInfo& typeout, std::string& adaptor) const { - bbtkDebugMessageInc("Kernel",8,"Package<"<::FindAdaptor(" <second.lock()->GetTypeName(); - bbtkDebugDecTab("Kernel",8); + bbtkDebugDecTab("kernel",8); return true; } @@ -778,26 +838,26 @@ namespace bbtk //========================================================================== /// Registers a black box descriptor in the package - bool Package::RegisterBlackBox(BlackBoxDescriptor::Pointer d) + bool Package::Register(BlackBoxDescriptor::Pointer d) { - bbtkDebugMessageInc("Kernel",8,"Package<"<::RegisterBlackBox(\""<GetTypeName()<<"\")"<::Register(\""<GetTypeName()<<"\")"<GetTypeName()); - if (i!=mBlackBoxMap.end()) + DescriptorMapType::iterator i = mDescriptorMap.find(d->GetTypeName()); + if (i!=mDescriptorMap.end()) { bbtkWarning("Package<"< : Trying to register box type <" <GetTypeName()<<"> which is already in the package"); return false; } - mBlackBoxMap[d->GetTypeName()] = d; + mDescriptorMap[d->GetTypeName()] = d; // d->Reference(); d->SetPackage(GetThisPointer()); // If it is a default adaptor, also register it in the adaptors map if ( d->GetKind() == BlackBoxDescriptor::DEFAULT_ADAPTOR ) { - bbtkDebugMessage("Kernel",8,"Package<"<::RegisterBlackBox(\""<GetTypeName()<<"\") : The box is an adaptor, inserting it in adaptors map ..."<::Register(\""<GetTypeName()<<"\") : The box is an adaptor, inserting it in adaptors map ..."<GetInputDescriptor("In")->GetTypeInfo(); TypeInfo typeout = d->GetOutputDescriptor("Out")->GetTypeInfo(); @@ -827,7 +887,7 @@ namespace bbtk // If it is a default adaptor, also register it in the adaptors map else if ( d->GetKind() == BlackBoxDescriptor::DEFAULT_GUI) { - bbtkDebugMessage("Kernel",8,"Package<"<::RegisterBlackBox(\""<GetTypeName()<<"\") : The box is a widget adaptor, inserting it in adaptors map ..."<::Register(\""<GetTypeName()<<"\") : The box is a widget adaptor, inserting it in adaptors map ..."<GetOutputDescriptor("Out")->GetTypeInfo(); DataInfo infoin(typeid(void),""); @@ -855,25 +915,25 @@ namespace bbtk } - bbtkDebugDecTab("Kernel",8); + bbtkDebugDecTab("kernel",8); return true; } //========================================================================== //=================================================================== - void Package::CheckBoxes() const + void Package::Check() const { - bbtkMessage("Debug",1,"****** Checking Package "<<(void*)this + bbtkMessage("debug",1,"****** Checking Package "<<(void*)this <<" ["<second->Check(true); } - bbtkMessage("Debug",1,"****** Checking Package "<<(void*)this + bbtkMessage("debug",1,"****** Checking Package "<<(void*)this <<" ["<::ChangeBlackBoxName(\""<::ChangeDescriptorName(\""< does not contains the black box <"<"); + bbtkDebugDecTab("kernel",8); + bbtkError("ChangeDescriptorName : The package <"< does not contains the black box <"<"); } i->second->SetTypeName(newname); - mBlackBoxMap[newname] = i->second; - mBlackBoxMap.erase(i); + mDescriptorMap[newname] = i->second; + mDescriptorMap.erase(i); - bbtkDebugDecTab("Kernel",8); + bbtkDebugDecTab("kernel",8); } //========================================================================== //========================================================================== - /// Displays the list of black boxes of the package - void Package::PrintBlackBoxes(bool description, bool adaptors) const + void Package::PrintHelpListDescriptors(bool description, bool adaptors) const { unsigned int lmax = 0; std::vector names; std::vector kinds; std::vector descrs; - BlackBoxMapType::const_iterator i; - for (i=mBlackBoxMap.begin(); - i!=mBlackBoxMap.end(); + DescriptorMapType::const_iterator i; + for (i=mDescriptorMap.begin(); + i!=mDescriptorMap.end(); ++i) { if ( adaptors || @@ -957,15 +1018,15 @@ namespace bbtk { std::string space; space.append(lmax - ni->size() - ci->size(),' '); - bbtkMessage("Help",1,*ni << space << *ci ); + bbtkMessage("help",1,*ni << space << *ci ); std::string d(*di); unsigned int dmax = 75 - lmax; // while (d.size() > dmax ) // { if (d.size()>dmax) - bbtkMessage("Help",1,d.substr(0,dmax) << "..." << std::endl); + bbtkMessage("help",1,d.substr(0,dmax) << "..." << std::endl); else - bbtkMessage("Help",1,d << std::endl); + bbtkMessage("help",1,d << std::endl); // d = d.substr(dmax,d.size()); // } } @@ -975,30 +1036,30 @@ namespace bbtk //========================================================================== /// Displays the list of adaptors of the package - void Package::PrintAdaptors(bool description) const + void Package::PrintHelpListAdaptors(bool description) const { - BlackBoxMapType::const_iterator i; - for (i=mBlackBoxMap.begin(); - i!=mBlackBoxMap.end(); + DescriptorMapType::const_iterator i; + for (i=mDescriptorMap.begin(); + i!=mDescriptorMap.end(); ++i) { if ( i->second->GetKind() != BlackBoxDescriptor::STANDARD ) { - bbtkMessage("Help",1, + bbtkMessage("help",1, " "<second->GetTypeName()); if ( i->second->GetKind() == BlackBoxDescriptor::DEFAULT_ADAPTOR ) { - bbtkMessage("Help",1, + bbtkMessage("help",1, " [default]"); } if (description) { - bbtkMessage("Help",1, + bbtkMessage("help",1, " : "<second->GetDescription()); } - bbtkMessage("Help",1,std::endl); + bbtkMessage("help",1,std::endl); } } /* @@ -1007,36 +1068,37 @@ namespace bbtk i!=mAdaptorMap.end(); ++i) { - bbtkMessage("Help",1, + bbtkMessage("help",1, " "<second->GetTypeName()); if (detail_level>0) { - bbtkMessage("Help",1, + bbtkMessage("help",1, " : "<second->GetDescription()); } - bbtkMessage("Help",1,std::endl); + bbtkMessage("help",1,std::endl); } */ } //========================================================================== //========================================================================== - /// Prints help on a black box - void Package::HelpBlackBox(const std::string& name, bool full) const + /// Prints help on a black box descriptor + void Package::PrintHelpDescriptor(const std::string& name, bool full) const { - bbtkDebugMessageInc("Kernel",8,"Package<"<::HelpBlackBox(\"" + bbtkDebugMessageInc("kernel",8,"Package<"<::PrintHelpDescriptor(\"" < does not contains the black box <"<"); } - // bbtkMessage("Help",1,"["<second->GetHelp(full); - bbtkDebugDecTab("Kernel",8); + bbtkDebugDecTab("kernel",8); } //========================================================================== @@ -1044,18 +1106,19 @@ namespace bbtk //========================================================================== /// Returns true iff the package contains the box of name boxname - bool Package::ContainsBlackBox(const std::string& name) const + bool Package::ContainsDescriptor(const std::string& name) const { - bbtkDebugMessageInc("Kernel",8,"Package<"<::HelpBlackBox(\"" + bbtkDebugMessageInc("kernel",8,"Package<"<::ContainsDescriptor(\"" <::CreateHtmlPage(\"" + bbtkDebugMessageInc("kernel",9,"Package<"<::CreateHtmlPage(\"" <\n"; s << "\n"; } - +//std::cout<<"JCP bbtkPackage.cxx void Package::CreateHtmlPage() ln 1225"<\n"; - BlackBoxMapType::const_iterator i; - for (i=mBlackBoxMap.begin(); i!=mBlackBoxMap.end(); ++i) - { - if ( i->second->GetKind() != BlackBoxDescriptor::STANDARD) - continue; + DescriptorMapType::const_iterator i; +//std::cout<<"JCP bbtkPackage.cxx void Package::CreateHtmlPage() ln 1236"<second->GetKind() != BlackBoxDescriptor::STANDARD) + continue; - std::string name = i->second->GetTypeName(); - Utilities::html_format(name); - std::string descr = i->second->GetDescription(); - Utilities::html_format(descr); - - s << ""; - s << " "; - s << " "; - s << "\n"; - } - s << "
"; - s << "   " - <"; - s << "" << descr << "
\n"; + std::string name = i->second->GetTypeName(); + Utilities::html_format(name); + std::string descr = i->second->GetDescription(); + //Utilities::html_format(descr); +//std::cout<<"JCP bbtkPackage.cxx void Package::CreateHtmlPage() ln 1246"<"; + s << ""; + s << "   " + <"; + s << " "; + s << " " << descr << " "; + s << "\n"; + } + s << "\n"; + + + s << "\n"; + s << "\n"; + //------------------- + // Adaptors list + if (mAdaptorMap.size()>0) + { + // s << "
\n"; + s << "

Adaptors : \n"; + s << "

    \n"; +//std::cout<<"JCP bbtkPackage.cxx void Package::CreateHtmlPage() ln 1268"<\n"; + for (i=mDescriptorMap.begin(); i!=mDescriptorMap.end();++i) + { + if ( i->second->GetKind() == BlackBoxDescriptor::STANDARD) + continue; - s << "\n"; - s << "\n"; - - //------------------- - // Adaptors list - if (mAdaptorMap.size()>0) - { - // s << "
    \n"; - s << "

    Adaptors : \n"; - s << "

      \n"; - - // BlackBoxMapType::const_iterator i; - s << "

    \n"; - for (i=mBlackBoxMap.begin(); i!=mBlackBoxMap.end();++i) - { - if ( i->second->GetKind() == BlackBoxDescriptor::STANDARD) - continue; - - std::string name = i->second->GetTypeName(); - Utilities::html_format(name); - std::string descr = i->second->GetDescription(); - - s << ""; - s << " "; - s << " "; - s << "\n"; - } - s << "
    "; - s << "   " - <"; - s << "" << descr << "
    \n"; - - s << "
\n"; - s << "
\n"; - } + std::string name = i->second->GetTypeName(); + Utilities::html_format(name); + std::string descr = i->second->GetDescription(); + + s << ""; + s << ""; + s << "   
" + <"; + s << " "; + s << " " << descr << " "; + s << "\n"; + } + s << "\n"; + + s << "\n"; + s << "\n"; + } // s << "
\n"; @@ -1252,23 +1317,23 @@ namespace bbtk //------------------- // Computes output directory from filename to pass it to // BlackBoxDescriptor::InsertHtmlHelp - std::string dir; + std::string dir; - std::string::size_type slash_position = filename.find_last_of("/\\"); + std::string::size_type slash_position = filename.find_last_of("/\\"); - if (slash_position != std::string::npos) { - if (slash_position == 0) - slash_position = 1; - dir = filename.substr(0,slash_position); - } + if (slash_position != std::string::npos) { + if (slash_position == 0) + slash_position = 1; + dir = filename.substr(0,slash_position); + } - for (i=mBlackBoxMap.begin(); - i!=mBlackBoxMap.end(); - ++i) - { - i->second->InsertHtmlHelp(s,detail,level,dir,relative_link); - } + for (i=mDescriptorMap.begin(); + i!=mDescriptorMap.end(); + ++i) + { + i->second->InsertHtmlHelp(s,detail,level,dir,relative_link); + } //---------------------- // Footer @@ -1288,7 +1353,7 @@ namespace bbtk //---------------------- // End - bbtkDebugDecTab("Kernel",9); + bbtkDebugDecTab("kernel",9); } //========================================================================== @@ -1303,7 +1368,7 @@ namespace bbtk std::string Package::GetObjectInfo() const { std::stringstream i; - i << " - "<second->GetObjectRecursiveSize(); } return s; } //========================================================================== - + void Package::GetBoxesInside(NodeTreeC& tree, int cont) + { + DescriptorMapType::const_iterator i; + std::cout<<"*********a********"<second->GetBoxesInside(tree, cont); + std::cout<<"*****************"< Package::mReleasedDynamicallyLoadedPackages; //========================================================================== + }