2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkFactory.cxx,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.55 $
34 =========================================================================*/
40 *\brief Class bbtk::Factory : can load and unload dynamic libraries containing
41 * black boxes packages and create instances of the black boxes registered
42 * in the packages loaded.
44 #include "bbtkFactory.h"
45 #include "bbtkMessageManager.h"
46 #include "bbtkConnection.h"
47 #include "bbtkConfigurationFile.h"
48 #include "bbtkUtilities.h"
49 #include "bbtkConfigurationFile.h"
51 #include <sys/stat.h> // for struct stat stFileInfo
54 #include <direct.h> // for getcwd
57 #include <cctype> // std::toupper
64 //===================================================================
66 Factory::Pointer Factory::New()
68 bbtkDebugMessage("kernel",9,"Factory::New()"<<std::endl);
69 return MakePointer(new Factory());
71 //===================================================================
73 //===================================================================
78 bbtkDebugMessage("kernel",7,"Factory()"<<std::endl);
80 //===================================================================
82 //===================================================================
86 bbtkDebugMessage("kernel",7,"==> ~Factory()"<<std::endl);
88 bbtkDebugMessage("kernel",7,"<== ~Factory()"<<std::endl);
90 //===================================================================
94 //===================================================================
97 bbtkDebugMessage("kernel",7,"==> Factory::Reset()"<<std::endl);
99 bbtkDebugMessage("kernel",7,"<== Factory::Reset()"<<std::endl);
101 //===================================================================
104 // ===================================================================
105 bool Factory::DoLoadPackage(std::string libname,
110 Package::Pointer p = Package::CreateFromDynamicLibrary(libname,
115 //===================================================================
116 bbtkMessage("output",2,p->GetName()<<" "
119 <<p->GetAuthor() << " Category(s) :"
122 bbtkMessage("output",2,p->GetDescription()<<std::endl);
123 //===================================================================
124 p->AddFactory(GetThisPointer<Factory>());
125 mPackageMap[pkgname] = p;
132 //===================================================================
133 /// \brief Loads a package.
135 /// The name is the system-independant name of the package (the name of the instance of bbtk::Package).
136 /// Tries to open the dynamic library :
137 /// - "libbb<name>.so" for linux systems,
138 /// - "bb<name>.dll" for windows systems.
139 /// If it succeeds, then tries to load the symbols "<name>GetPackage" and "<name>DeletePackage".
140 /// "<name>GetPackage" is called to get the pointer on the bbtk::Package of the library
141 /// ("<name>DeletePackage" is not used, its presence is just checked before loading the package).
143 /// now, filename is only the last name (no longer the full name!)
144 /// it will be searched within *all* the paths given in bbtk_config.xml
148 void Factory::LoadPackage( const std::string& name )
152 // Note : in the following :
153 // name : the user supplied name
154 // - abreviated name e.g. pkg pkg.so libbpkg libbbpkg.so
155 // - relative full name e.g. ./libbbpkg.so ../../libbbpkg.so
156 // - absolute full name e.g. /home/usrname/proj/lib/libbbpkg.so
157 // same for Windows, with c:, d: ...
159 // lastname : string before the last / (if any), or user supplied name
164 bbtkDebugMessageInc("kernel",7,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
165 bbtkMessage("debug",1,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
167 std::vector<std::string> package_paths;
168 std::string libname; // full path library name
169 std::string pkgname; // e.g. libbb<pkgname>.so
173 pkgname = Utilities::ExtractPackageName(name,upath);
175 bbtkMessage("debug",1,"Package name ["<<pkgname<<"]"<<std::endl);
176 bbtkMessage("debug",1,"Package path ["<<upath<<"]"<<std::endl);
178 // no loading package if already loaded
179 PackageMapType::iterator iUnload;
180 iUnload = mPackageMap.find(pkgname);
182 //EED Debuging message
183 // std::cout << "EED Factory::LoadPackage " << std::endl;
184 // PackageMapType::iterator it;
185 // for ( it=mPackageMap.begin() ; it != mPackageMap.end(); it++ )
186 // std::cout << (*it).first << " ";
187 // std::cout << std::endl;
190 if (iUnload != mPackageMap.end())
192 bbtkMessage("output",2,"["<< pkgname <<"] already loaded" << std::endl);
196 // =================================================
197 // The following structure was checked to work
198 // with any type of relative/absolute path.
199 // Please don't modify it without checking
200 // *all* the cases. JP
201 //==================================================
204 bool foundFile = false;
206 // If path provided by user will be the first scanned :
207 // push it into vector of paths
208 if (upath.length()>0) // ------------------------------------- check user supplied location
210 if (name[0] != '.' && name[0] != '/' && name[1]!= ':')
212 bbtkError("Use absolute or relative path name! ["<<name<<"] is an illegal name");
216 // std::string path = Utilities::ExpandLibName(upath, false);
218 std::string path = Utilities::ExpandLibName(name,false); // keep last item, here.
222 Utilities::ExtractPackageName(path,p2);
223 //libname = Utilities::MakeLibnameFromPath(path, pkgname);
224 libname = Utilities::MakeLibnameFromPath(p2, pkgname); // remove last item
225 // Check if library exists
226 if ( !Utilities::FileExists(libname) )
228 // The following is *NOT* a debug time message :
229 // It's a user intended message.
230 // Please don't remove it.
231 bbtkMessage("output",3," [" <<libname
232 <<"] : doesn't exist" <<std::endl);
236 ok = DoLoadPackage( libname, pkgname, path);
241 bbtkError("Path ["<<upath<<"] doesn't exist");
245 else // ----------------------------------------------------- iterate on the paths
248 std::string path = ".";
249 package_paths = ConfigurationFile::GetInstance().Get_package_paths();
250 std::vector<std::string>::iterator i;
251 for (i=package_paths.begin();i!=package_paths.end();++i)
255 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = path "<<path<<std::endl;
256 // we *really* want '.' to be the current working directory
259 char buf[2048]; // for getcwd
260 char * currentDir = getcwd(buf, 2048);
261 std::string cwd(currentDir);
262 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = currentDir "<<currentDir<<std::endl;
265 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = path "<<path<<" pkgnam="<<pkgname<<std::endl;
266 libname = Utilities::MakeLibnameFromPath(path, pkgname);
268 bbtkMessage("debug",2,"-> Trying to load [" << libname << "]" <<std::endl);
270 // Check if library exists
271 if ( !Utilities::FileExists(libname) )
273 // The following is *NOT* a debug time message :
274 // It's a user intended message.
275 // Please don't remove it.
276 bbtkMessage("output",3,
277 " [" <<libname <<"] : doesn't exist" <<std::endl);
278 continue; // try next path
282 // Try to Load the library
284 ok = DoLoadPackage( libname, pkgname, path);
287 bbtkMessage("debug",2," OK"<<std::endl);
289 break; // we stop iterating even if error : have to signal it to user
290 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
294 if( !ok ) // nothing was loaded
298 bbtkError("Could not find package ["<<pkgname<< "]");
302 #if defined(__GNUC__)
303 bbtkError("Could not load package ["<< pkgname
305 << " Opening "<<libname<<" failed"
306 << " Reason: "<< dlerror());
307 #elif defined(_WIN32)
308 bbtkError("Could not load package ["<<pkgname
309 <<"] :"<< std::endl << " Error loading " <<libname);
311 // look how to get the error message on win
313 // it is the bordel !! (the bloody fucking bordel, you mean?)
314 // look : http://msdn2.microsoft.com/en-us/library/ms680582.aspx
318 bbtkMessage("output",2,"[" << libname << "] loaded" << std::endl);
325 //===================================================================
326 /// \brief UnLoads a package.
328 /// The package must have been previously loaded by LoadPackage.
329 /// If the entry is found in the map, calls ClosePackage
330 void Factory::UnLoadPackage( const std::string& name )
332 bbtkDebugMessageInc("kernel",7,"Factory::UnLoadPackage(\""
333 <<name<<"\")"<<std::endl);
335 PackageMapType::iterator i;
336 i = mPackageMap.find(name);
337 if (i == mPackageMap.end())
339 bbtkError("cannot unload package \""<<name
340 <<"\" : package not loaded !");
343 bbtkDebugDecTab("kernel",7);
345 //===================================================================
348 //===================================================================
349 void Factory::CloseAllPackages()
351 bbtkDebugMessageInc("kernel",7,"Factory::CloseAllPackages()"<<std::endl);
353 std::vector< Package::WeakPointer > mAlive;
356 while (mPackageMap.begin() != mPackageMap.end())
358 PackageMapType::iterator i = mPackageMap.begin();
359 Package::WeakPointer p = i->second;
361 if (p.lock()) mAlive.push_back(p);
363 std::vector< Package::WeakPointer >::iterator i;
364 for (i=mAlive.begin();i!=mAlive.end();++i)
366 // If not dead : reinsert
369 bbtkDebugMessage("kernel",7,"Package "<<i->lock()->GetName()
370 <<" still alive"<<std::endl);
371 // InsertPackage(i->lock());
375 while (mPackageMap.size()>0);
377 bbtkDebugDecTab("kernel",7);
379 //===================================================================
381 //===================================================================
382 /// \brief Close the package referenced by the iterator
384 /// First removes the factory from the set of factories which use the package
385 /// If the set is empty then :
386 /// If it is a dynamically loaded package :
387 /// - Loads and calls the function "<name>DeletePackage" of the dynamic library (responsible for package desallocation)
388 /// - Closes the dynamic library
390 /// - deletes the package normally
392 /// Finally erases the package entry in the packages map
393 void Factory::ClosePackage(PackageMapType::iterator& i)
395 bbtkDebugMessageInc("kernel",7,"Factory::ClosePackage(\""
396 <<i->second->GetName()
400 // Removes this from the set of factories which use the package
401 i->second->RemoveFactory(GetThisPointer<Factory>());
402 Package::WeakPointer p = i->second;
403 // remove the entry in the map
404 mPackageMap.erase(i);
405 // Release the package if not already destroyed
410 bbtkDebugDecTab("kernel",7);
412 //===================================================================
416 //===================================================================
417 void Factory::PrintHelpListPackages(bool details, bool adaptors) const
419 bbtkDebugMessageInc("kernel",9,"Factory::PrintPackages"<<std::endl);
421 PackageMapType::const_iterator i;
422 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
424 bbtkMessage("help",1, i->first << std::endl);
426 i->second->PrintHelpListDescriptors(false,adaptors);
430 bbtkDebugDecTab("kernel",9);
432 //===================================================================
434 //===================================================================
435 /// Displays help on a package
436 void Factory::PrintHelpPackage(const std::string& name, bool adaptors) const
438 bbtkDebugMessageInc("kernel",9,"Factory::PrintHelpPackage(\""
442 PackageMapType::const_iterator i = mPackageMap.find(name);
443 if ( i != mPackageMap.end() )
445 bbtkMessage("help",1, "Package "<<i->first<<" ");
447 if (i->second->GetVersion().length()>0)
448 bbtkMessageCont("help",1,"v" <<i->second->GetVersion());
450 if (i->second->GetAuthor().length()>0)
451 bbtkMessageCont("help",1,"- "<<i->second->GetAuthor());
453 if (i->second->GetCategory().length()>0)
454 bbtkMessageCont("help",1,"- "<<i->second->GetCategory());
456 bbtkMessageCont("help",1,std::endl);
457 bbtkIncTab("help",1);
458 bbtkMessage("help",1,i->second->GetDescription()<<std::endl);
459 if (i->second->GetNumberOfDescriptors()>0)
461 bbtkMessage("help",1, "Black boxes : "<<std::endl);
462 i->second->PrintHelpListDescriptors(true,adaptors);
466 bbtkMessage("help",1, "No black boxes"<<std::endl);
468 bbtkDecTab("help",1);
472 bbtkDebugDecTab("kernel",9);
473 bbtkError("package \""<<name<<"\" unknown");
476 bbtkDebugDecTab("kernel",9);
478 //===================================================================
480 //===================================================================
481 /// Prints help on the black box of type <name>
482 /// Returns the package to which it belongs
483 void Factory::PrintHelpDescriptor(const std::string& name,
484 std::string& package,
487 bbtkDebugMessageInc("kernel",9,"Factory::PrintHelpDescriptor(\""
492 PackageMapType::const_iterator i;
493 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
495 if (i->second->ContainsDescriptor(name))
497 i->second->PrintHelpDescriptor(name,full);
498 package = i->second->GetName();
503 bbtkDebugDecTab("kernel",9);
506 bbtkError("No package of the factory contains any black box <"
510 //===================================================================
513 //===================================================================
514 /// Inserts a package in the factory
515 void Factory::InsertPackage( Package::Pointer p )
517 bbtkDebugMessageInc("kernel",9,"Factory::InsertPackage(\""<<
518 p->GetName()<<"\")"<<std::endl);
520 p->AddFactory(GetThisPointer<Factory>());
521 mPackageMap[p->GetName()] = p;
522 bbtkDebugDecTab("kernel",9);
524 //===================================================================
526 //===================================================================
527 /// Removes a package from the factory (and deletes it)
528 void Factory::RemovePackage( Package::Pointer p )
530 bbtkDebugMessageInc("kernel",9,"Factory::RemovePackage(\""<<
531 p->GetName()<<"\")"<<std::endl);
533 PackageMapType::iterator i;
534 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
536 if (i->second == p) break;
539 if (i!=mPackageMap.end())
545 bbtkError("Factory::RemovePackage(\""<<
546 p->GetName()<<"\") : package absent from factory");
549 bbtkDebugDecTab("kernel",9);
553 //===================================================================
554 std::string Factory::GetPackageNameOfaBlackBox(std::string boxType)
556 std::string packageName="<void bbtk package name>";
557 PackageMapType::const_iterator i;
559 std::size_t found = boxType.find(":");
560 if (found!=std::string::npos)
562 packageName = boxType.substr(0,found);
564 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
566 if ( i->second->ifBoxExist( boxType ) == true)
568 packageName = i->first;
576 //===================================================================
577 std::string Factory::GetTypeNameOfaBlackBox(std::string boxType)
579 std::string typeName="<void bbtk type name>";
581 std::size_t found = boxType.find(":");
582 if (found!=std::string::npos)
584 typeName = boxType.substr(found+1);
594 //===================================================================
595 /// Creates an instance of a black box of type <type> with name <name>
596 BlackBox::Pointer Factory::NewBlackBox(const std::string& type,
597 const std::string& name) const
599 bbtkDebugMessageInc("kernel",7,"Factory::NewBlackBox(\""
600 <<type<<"\",\""<<name<<"\")"<<std::endl);
603 PackageMapType::const_iterator i;
605 std::string tmp = type;
606 std::string packageName = ((bbtk::Factory*)this)->GetPackageNameOfaBlackBox(tmp);
607 std::string type2 = ((bbtk::Factory*)this)->GetTypeNameOfaBlackBox(tmp);
608 i = mPackageMap.find(packageName);
609 if (i != mPackageMap.end())
611 b = i->second->NewBlackBox(type2,name);
613 b =BlackBox::Pointer();
617 std::size_t found = type.find(":");
618 if (found!=std::string::npos)
620 std::string packageName = type.substr(0,found);
621 std::string type2 = type.substr(found+1);
622 i = mPackageMap.find(packageName);
623 if (i != mPackageMap.end())
625 b = i->second->NewBlackBox(type2,name);
627 b =BlackBox::Pointer();
630 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
632 b = i->second->NewBlackBox(type,name);
642 bbtkError("black box type \""<<type<<"\" unknown");
646 bbtkDebugDecTab("kernel",7);
649 //===================================================================
651 //===================================================================
652 /// Creates an instance of a black box of type <type> with name <name>
653 BlackBox::Pointer Factory::NewAdaptor(const DataInfo& typein,
654 const DataInfo& typeout,
655 const std::string& name) const
657 bbtkDebugMessageInc("kernel",8,"Factory::NewAdaptor("
660 <<name<<"\")"<<bbtkendl);
664 PackageMapType::const_iterator i;
665 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
667 b = i->second->NewAdaptor(typein,typeout,name);
672 bbtkError("no "<<typein<<" to "<<typeout
673 <<" adaptor available");
676 bbtkDebugDecTab("kernel",7);
679 //===================================================================
682 //===================================================================
683 /// Creates an instance of a black box of type <type> with name <name>
684 BlackBox::Pointer Factory::NewWidgetAdaptor(const DataInfo& typein,
685 const DataInfo& typeout,
686 const std::string& name) const
688 bbtkDebugMessageInc("kernel",8,"Factory::NewWidgetAdaptor(<"
691 <<name<<"\")"<<bbtkendl);
695 PackageMapType::const_iterator i;
696 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
698 b = i->second->NewWidgetAdaptor(typein,
705 bbtkError("no "<<typein<<" to "<<typeout
706 <<"> widget adaptor available");
709 bbtkDebugDecTab("kernel",7);
712 //===================================================================
714 //===================================================================
715 /// Creates an instance of a black box of type <type> with name <name>
716 bool Factory::FindAdaptor(const DataInfo& typein,
717 const DataInfo& typeout,
718 std::string& adaptor) const
720 bbtkDebugMessageInc("kernel",8,"Factory::FindAdaptor(<"
722 <<typeout<<">)"<<bbtkendl);
725 PackageMapType::const_iterator i;
726 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
728 b = i->second->FindAdaptor(typein,
736 bbtkError("no "<<typein<<" to "<<typeout
737 <<"> widget adaptor available");
741 bbtkDebugDecTab("kernel",7);
744 //===================================================================
746 //===================================================================
747 /// Creates an instance of a black box of type <type> with name <name>
748 bool Factory::FindWidgetAdaptor(const DataInfo& typein,
749 const DataInfo& typeout,
750 std::string& adaptor) const
752 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
754 <<typeout<<">)"<<bbtkendl);
757 PackageMapType::const_iterator i;
758 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
760 b = i->second->FindWidgetAdaptor(typein,
765 bbtkDebugDecTab("kernel",7);
768 //===================================================================
770 //===================================================================
771 /// Creates an instance of a black box of type <type> with name <name>
772 bool Factory::FindWidgetAdaptor2(const DataInfo& typein,
773 const DataInfo& typeout,
775 std::string& adaptor) const
777 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
779 <<typeout<<">)"<<bbtkendl);
782 adaptor = widget = "";
783 PackageMapType::const_iterator i;
784 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
786 b = i->second->FindWidgetAdaptor(typein,
793 // Look for a widget adaptor with good nature out
794 bbtkMessage("kernel",5,
795 "*** Looking for a two pieces widget adaptor for : "
796 << typein << "->"<<typeout<<std::endl);
797 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
799 Package::AdaptorMapType::const_iterator j;
800 for (j=i->second->GetAdaptorMap().begin();
801 j!=i->second->GetAdaptorMap().end();
804 if ( ( j->first.mKind ==
805 BlackBoxDescriptor::DEFAULT_GUI) &&
806 //(j->first.mTypeIn == typein) &&
807 (j->first.mTypeOut.GetNature() == typeout.GetNature() )
810 widget = j->second.lock()->GetTypeName();
811 bbtkMessage("kernel",5,
812 "===> Found first part : "<<widget
813 << " "<<j->first.mTypeIn<<"->"
814 <<j->first.mTypeOut<<std::endl);
815 DataInfo ti( j->first.mTypeOut.GetType(), "");
816 DataInfo to( typeout.GetType(), "");
817 b = FindAdaptor( ti, to, adaptor );
820 bbtkMessage("kernel",5,
821 "===> Found second part : "<<adaptor
827 bbtkMessage("kernel",5,
828 "===> No second part found"<<std::endl);
835 bbtkDebugDecTab("kernel",7);
838 //===================================================================
840 //===================================================================
841 /// Creates an instance of a connection
842 Connection::Pointer Factory::NewConnection(BlackBox::Pointer from,
843 const std::string& output,
844 BlackBox::Pointer to,
845 const std::string& input) const
847 bbtkDebugMessage("kernel",7,"Factory::NewConnection(\""
848 <<from->bbGetName()<<"\",\""<<output<<"\",\""
849 <<to->bbGetName()<<"\",\""<<input
852 return Connection::New(from,output,to,input,
853 GetThisPointer<Factory>());
855 //===================================================================
859 //===================================================================
860 Package::Pointer Factory::GetPackage(const std::string& name) const
862 bbtkDebugMessageInc("kernel",9,"Factory::GetPackage(\""<<name<<"\")"
865 PackageMapType::const_iterator i = mPackageMap.find(name);
866 if ( i != mPackageMap.end() )
868 bbtkDebugDecTab("kernel",9);
873 bbtkDebugDecTab("kernel",9);
874 bbtkError("package \""<<name<<"\" unknown");
877 bbtkDebugDecTab("kernel",9);
879 //===================================================================
882 //===================================================================
883 void Factory::Check() const
885 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
887 PackageMapType::const_iterator i;
888 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
892 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
893 <<" ... OK"<<std::endl);
895 //===================================================================
897 //===================================================================
898 void Factory::WriteDotFilePackagesList(FILE *ff)
901 bbtkDebugMessageInc("kernel",9,"Factory::WriteDotFilePackagesList()"
905 fprintf( ff , "subgraph cluster_FACTORY {\n");
906 fprintf( ff , " label = \"PACKAGES\"%s\n", ";");
907 fprintf( ff , " style=filled%s\n",";");
908 fprintf( ff , " color=lightgrey%s\n",";");
909 fprintf( ff , " rankdir=TB%s\n",";");
912 PackageMapType::const_iterator i;
913 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
915 url=GetPackage(i->first)->GetDocURL();
916 fprintf(ff," %s [shape=ellipse, URL=\"%s\"]%s\n",i->first.c_str(),url.c_str(),";" );
918 fprintf( ff , "}\n\n");
919 bbtkDebugDecTab("kernel",9);
921 //===================================================================
924 void Factory::ShowGraphTypes(const std::string& name) const
927 PackageMapType::const_iterator i;
928 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
930 if (i->second->ContainsDescriptor(name))
932 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
934 // Don't pollute the file store with "temp_dir" directories ...
935 std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
936 std::string directory = "\"" + default_doc_dir + separator + "temp_dir" +separator + "\"";
937 std::string filename2 = default_doc_dir + separator + "temp_dir" + separator + "tmp.html";
940 std::string command("start \"Titre\" /D ");
942 std::string command("gnome-open ");
944 command=command + directory +" tmp.html";
946 ff=fopen(filename2.c_str(),"w");
948 fprintf(ff,"<html><head><title>TMP</title> <script type=\"text/javascript\"> <!--\n");
949 fprintf(ff," window.location=\"%s#%s\";\n" , i->second->GetDocURL().c_str(),name.c_str() );
950 fprintf(ff,"//--></script></head><body></body></html>\n");
953 //fprintf(ff, "<a href=\"%s#%s\">Link</a>\n", i->second->GetDocURL().c_str(),name.c_str() );
955 system( command.c_str() );
960 bbtkDebugDecTab("kernel",9);
963 bbtkError("No package of the factory contains any black box <"
971 void Factory::CreateHtmlIndex(IndexEntryType type,
972 const std::string& filename)
974 bbtkDebugMessageInc("kernel",9,"Factory::CreateHtmlIndex(\""
975 <<filename<<"\")"<<bbtkendl);
979 typedef std::map<std::string,
980 std::vector<BlackBoxDescriptor::Pointer> > IndexType;
982 // Builds the index map
983 PackageMapType::const_iterator i;
984 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
986 Package::Pointer pack = i->second;
987 if (pack->GetName()=="user") continue;
988 Package::DescriptorMapType::const_iterator j;
989 for (j = pack->GetDescriptorMap().begin();
990 j!= pack->GetDescriptorMap().end();
995 if ( type==Adaptors )
997 if (j->second->GetKind() == BlackBoxDescriptor::STANDARD )
1001 if (j->second->GetKind() != BlackBoxDescriptor::STANDARD )
1004 std::vector<std::string> keys;
1008 k += pack->GetName();
1010 title = "Boxes by package";
1012 else if ((type==Initials) || (type==Adaptors))
1014 std::string init(" ");
1015 init[0] = std::toupper(j->second->GetTypeName()[0]);
1016 keys.push_back(init);
1017 title = "Alphabetical list";
1019 else if (type==Categories)
1021 // Split the category string
1022 std::string delimiters = ";,";
1023 Utilities::SplitString(j->second->GetCategory(),
1026 keys.push_back(" NONE");
1027 title = "Boxes by category";
1030 std::vector<std::string>::const_iterator k;
1031 for (k=keys.begin(); k!=keys.end(); ++k )
1033 IndexType::iterator p;
1035 if (p != index.end())
1037 p->second.push_back(j->second);
1041 std::vector<BlackBoxDescriptor::Pointer> v;
1042 v.push_back(j->second);
1049 //---------------------
1052 s.open(filename.c_str());
1055 bbtkError("Factory::CreateHtmlIndex : could not open file '"
1059 //----------------------
1061 s << "<html lang=\"en\">\n";
1063 s << "<title>"<<title<<"</title>\n";
1064 s << "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n";
1065 s << "<meta name=\"description\" content=\""<<title<<"\">\n";
1066 s << "<meta name=\"generator\" content=\"\">\n";
1067 s << "<link title=\"Top\" rel=\"top\" href=\"#Top\">\n";
1068 //<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
1069 s << "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><style type=\"text/css\"><!--\n";
1070 s << "pre.display { font-family:inherit }\n";
1071 s << "pre.format { font-family:inherit }\n";
1072 s << "pre.smalldisplay { font-family:inherit; font-size:smaller }\n";
1073 s << "pre.smallformat { font-family:inherit; font-size:smaller }\n";
1074 s << "pre.smallexample { font-size:smaller }\n";
1075 s << "pre.smalllisp { font-size:smaller }\n";
1076 s << "span.sc { font-variant:small-caps }\n";
1077 s << "span.roman { font-family:serif; font-weight:normal; } \n";
1078 s << "span.sansserif { font-family:sans-serif; font-weight:normal; }\n";
1079 s << "--></style>\n";
1081 //----------------------
1083 //----------------------
1086 s << "<a name=\"Top\"></a>\n";
1087 s << "<h1 class=\"settitle\">"<<title<<"</h1>\n";
1089 IndexType::iterator ii;
1090 for (ii=index.begin();ii!=index.end();++ii)
1092 s << "<a href=\"#"<<ii->first<<"\">"<<ii->first<<"</a> ";
1095 for (ii=index.begin();ii!=index.end();++ii)
1098 s << "<p><a href=\"#Top\">Top</a>";
1101 s << "<a name=\""<<ii->first<<"\"></a>\n";
1102 s << "<p><a href=\""<<ii->first<<"/index.html\">"
1103 << ii->first<<"</a>\n";
1105 s << " - \n";
1107 s << "<a name=\"doxygen\"></a>\n";
1111 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1112 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1114 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1115 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1119 s << "<a name=\""<<ii->first<<"\"></a>\n";
1120 s << "<p><b>"<<ii->first<<"</b>\n";
1124 s << "<p><TABLE cellspacing=0 cellpadding=3>\n";
1126 std::vector<BlackBoxDescriptor::Pointer>::iterator di;
1127 for (di=ii->second.begin();di!=ii->second.end();++di)
1129 std::string pack = (*di)->GetPackage()->GetName();
1130 std::string name = (*di)->GetTypeName();
1131 Utilities::html_format(name);
1132 std::string descr = (*di)->GetDescription();
1133 Utilities::html_format(descr);
1135 s << "<TD style='vertical-align: top;'>";
1136 s << " <a href=\""<<pack
1137 <<"/index.html#"<<name<<"\">"
1138 <<pack<<"::"<<name<<"</a>";
1140 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1147 //----------------------
1152 ptm = gmtime ( &rawtime );
1155 s << "Automatically generated by <b>bbtk</b> on "
1156 << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900
1157 << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n";
1158 s << "</body></html>\n";
1160 //----------------------
1163 bbtkDebugDecTab("kernel",9);
1166 //==========================================================================
1167 std::string Factory::GetObjectName() const
1169 return std::string("Factory");
1171 //==========================================================================
1173 //==========================================================================
1174 std::string Factory::GetObjectInfo() const
1176 std::stringstream i;
1179 //==========================================================================
1181 //==========================================================================
1182 size_t Factory::GetObjectSize() const
1184 size_t s = Superclass::GetObjectSize();
1185 s += Factory::GetObjectInternalSize();
1188 //==========================================================================
1189 //==========================================================================
1190 size_t Factory::GetObjectInternalSize() const
1192 size_t s = sizeof(Factory);
1195 //==========================================================================
1196 //==========================================================================
1197 size_t Factory::GetObjectRecursiveSize() const
1199 size_t s = Superclass::GetObjectRecursiveSize();
1200 s += Factory::GetObjectInternalSize();
1202 PackageMapType::const_iterator i;
1203 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
1205 s += i->second->GetObjectRecursiveSize();
1209 //==========================================================================