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,
109 Package::Pointer p = Package::CreateFromDynamicLibrary(libname,
114 //===================================================================
115 bbtkMessage("output",2,p->GetName()<<" "
118 <<p->GetAuthor() << " Category(s) :"
121 bbtkMessage("output",2,p->GetDescription()<<std::endl);
122 //===================================================================
123 p->AddFactory(GetThisPointer<Factory>());
124 mPackageMap[pkgname] = p;
130 //===================================================================
131 /// \brief Loads a package.
133 /// The name is the system-independant name of the package (the name of the instance of bbtk::Package).
134 /// Tries to open the dynamic library :
135 /// - "libbb<name>.so" for linux systems,
136 /// - "bb<name>.dll" for windows systems.
137 /// If it succeeds, then tries to load the symbols "<name>GetPackage" and "<name>DeletePackage".
138 /// "<name>GetPackage" is called to get the pointer on the bbtk::Package of the library
139 /// ("<name>DeletePackage" is not used, its presence is just checked before loading the package).
141 /// now, filename is only the last name (no longer the full name!)
142 /// it will be searched within *all* the paths given in bbtk_config.xml
146 void Factory::LoadPackage( const std::string& name )
149 // Note : in the following :
150 // name : the user supplied name
151 // - abreviated name e.g. pkg pkg.so libbpkg libbbpkg.so
152 // - relative full name e.g. ./libbbpkg.so ../../libbbpkg.so
153 // - absolute full name e.g. /home/usrname/proj/lib/libbbpkg.so
154 // same for Windows, with c:, d: ...
156 // lastname : string before the last / (if any), or user supplied name
159 bbtkDebugMessageInc("kernel",7,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
160 bbtkMessage("debug",1,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
162 std::vector<std::string> package_paths;
163 std::string libname; // full path library name
164 std::string pkgname; // e.g. libbb<pkgname>.so
168 pkgname = Utilities::ExtractPackageName(name,upath);
170 bbtkMessage("debug",1,"Package name ["<<pkgname<<"]"<<std::endl);
171 bbtkMessage("debug",1,"Package path ["<<upath<<"]"<<std::endl);
173 // no loading package if already loaded
174 PackageMapType::iterator iUnload;
175 iUnload = mPackageMap.find(pkgname);
177 //EED Debuging message
178 // std::cout << "EED Factory::LoadPackage " << std::endl;
179 // PackageMapType::iterator it;
180 // for ( it=mPackageMap.begin() ; it != mPackageMap.end(); it++ )
181 // std::cout << (*it).first << " ";
182 // std::cout << std::endl;
184 if (iUnload != mPackageMap.end())
186 bbtkMessage("output",2,"["<< pkgname <<"] already loaded" << std::endl);
190 // =================================================
191 // The following structure was checked to work
192 // with any type of relative/absolute path.
193 // Please don't modify it without checking
194 // *all* the cases. JP
195 //==================================================
198 bool foundFile = false;
200 // If path provided by user will be the first scanned :
201 // push it into vector of paths
202 if (upath.length()>0) // ------------------------------------- check user supplied location
204 if (name[0] != '.' && name[0] != '/' && name[1]!= ':')
206 bbtkError("Use absolute or relative path name! ["<<name<<"] is an illegal name");
210 // std::string path = Utilities::ExpandLibName(upath, false);
212 std::string path = Utilities::ExpandLibName(name,false); // keep last item, here.
216 Utilities::ExtractPackageName(path,p2);
217 //libname = Utilities::MakeLibnameFromPath(path, pkgname);
218 libname = Utilities::MakeLibnameFromPath(p2, pkgname); // remove last item
219 // Check if library exists
220 if ( !Utilities::FileExists(libname) )
222 // The following is *NOT* a debug time message :
223 // It's a user intended message.
224 // Please don't remove it.
225 bbtkMessage("output",3," [" << libname <<"] : doesn't exist" <<std::endl);
227 ok = DoLoadPackage( libname, pkgname, path);
230 bbtkError("Path ["<<upath<<"] doesn't exist");
233 } else // ----------------------------------------------------- iterate on the paths
236 std::string path = ".";
237 package_paths = ConfigurationFile::GetInstance().Get_package_paths();
238 std::vector<std::string>::iterator i;
239 for (i=package_paths.begin();i!=package_paths.end();++i)
243 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = path "<<path<<std::endl;
244 // we *really* want '.' to be the current working directory
247 char buf[2048]; // for getcwd
248 char * currentDir = getcwd(buf, 2048);
249 std::string cwd(currentDir);
250 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = currentDir "<<currentDir<<std::endl;
253 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = path "<<path<<" pkgnam="<<pkgname<<std::endl;
254 libname = Utilities::MakeLibnameFromPath(path, pkgname);
256 bbtkMessage("debug",2,"-> Trying to load [" << libname << "]" <<std::endl);
258 // Check if library exists
259 if ( !Utilities::FileExists(libname) )
261 // The following is *NOT* a debug time message :
262 // It's a user intended message.
263 // Please don't remove it.
264 bbtkMessage("output",3,
265 " [" <<libname <<"] : doesn't exist" <<std::endl);
266 continue; // try next path
270 // Try to Load the library
271 ok = DoLoadPackage( libname, pkgname, path);
274 bbtkMessage("debug",2," OK"<<std::endl);
276 break; // we stop iterating even if error : have to signal it to user
277 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
280 if( !ok ) // nothing was loaded
284 bbtkError("Could not find package ["<<pkgname<< "]");
288 #if defined(__GNUC__)
289 bbtkError("Could not load package ["<< pkgname
291 << " Opening "<<libname<<" failed"
292 << " Reason: "<< dlerror());
293 #elif defined(_WIN32)
294 bbtkError("Could not load package ["<<pkgname
295 <<"] :"<< std::endl << " Error loading " <<libname);
297 // look how to get the error message on win
299 // it is the bordel !! (the bloody fucking bordel, you mean?)
300 // look : http://msdn2.microsoft.com/en-us/library/ms680582.aspx
304 bbtkMessage("output",2,"[" << libname << "] loaded" << std::endl);
308 //===================================================================
309 /// \brief UnLoads a package.
311 /// The package must have been previously loaded by LoadPackage.
312 /// If the entry is found in the map, calls ClosePackage
313 void Factory::UnLoadPackage( const std::string& name )
315 bbtkDebugMessageInc("kernel",7,"Factory::UnLoadPackage(\""
316 <<name<<"\")"<<std::endl);
318 PackageMapType::iterator i;
319 i = mPackageMap.find(name);
320 if (i == mPackageMap.end())
322 bbtkError("cannot unload package \""<<name
323 <<"\" : package not loaded !");
326 bbtkDebugDecTab("kernel",7);
328 //===================================================================
331 //===================================================================
332 void Factory::CloseAllPackages()
334 bbtkDebugMessageInc("kernel",7,"Factory::CloseAllPackages()"<<std::endl);
336 std::vector< Package::WeakPointer > mAlive;
339 while (mPackageMap.begin() != mPackageMap.end())
341 PackageMapType::iterator i = mPackageMap.begin();
342 Package::WeakPointer p = i->second;
344 if (p.lock()) mAlive.push_back(p);
346 std::vector< Package::WeakPointer >::iterator i;
347 for (i=mAlive.begin();i!=mAlive.end();++i)
349 // If not dead : reinsert
352 bbtkDebugMessage("kernel",7,"Package "<<i->lock()->GetName()
353 <<" still alive"<<std::endl);
354 // InsertPackage(i->lock());
358 while (mPackageMap.size()>0);
360 bbtkDebugDecTab("kernel",7);
362 //===================================================================
364 //===================================================================
365 /// \brief Close the package referenced by the iterator
367 /// First removes the factory from the set of factories which use the package
368 /// If the set is empty then :
369 /// If it is a dynamically loaded package :
370 /// - Loads and calls the function "<name>DeletePackage" of the dynamic library (responsible for package desallocation)
371 /// - Closes the dynamic library
373 /// - deletes the package normally
375 /// Finally erases the package entry in the packages map
376 void Factory::ClosePackage(PackageMapType::iterator& i)
378 bbtkDebugMessageInc("kernel",7,"Factory::ClosePackage(\""
379 <<i->second->GetName()
383 // Removes this from the set of factories which use the package
384 i->second->RemoveFactory(GetThisPointer<Factory>());
385 Package::WeakPointer p = i->second;
386 // remove the entry in the map
387 mPackageMap.erase(i);
388 // Release the package if not already destroyed
393 bbtkDebugDecTab("kernel",7);
395 //===================================================================
399 //===================================================================
400 void Factory::PrintHelpListPackages(bool details, bool adaptors) const
402 bbtkDebugMessageInc("kernel",9,"Factory::PrintPackages"<<std::endl);
404 PackageMapType::const_iterator i;
405 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
407 bbtkMessage("help",1, i->first << std::endl);
409 i->second->PrintHelpListDescriptors(false,adaptors);
413 bbtkDebugDecTab("kernel",9);
415 //===================================================================
417 //===================================================================
418 /// Displays help on a package
419 void Factory::PrintHelpPackage(const std::string& name, bool adaptors) const
421 bbtkDebugMessageInc("kernel",9,"Factory::PrintHelpPackage(\""
425 PackageMapType::const_iterator i = mPackageMap.find(name);
426 if ( i != mPackageMap.end() )
428 bbtkMessage("help",1, "Package "<<i->first<<" ");
430 if (i->second->GetVersion().length()>0)
431 bbtkMessageCont("help",1,"v" <<i->second->GetVersion());
433 if (i->second->GetAuthor().length()>0)
434 bbtkMessageCont("help",1,"- "<<i->second->GetAuthor());
436 if (i->second->GetCategory().length()>0)
437 bbtkMessageCont("help",1,"- "<<i->second->GetCategory());
439 bbtkMessageCont("help",1,std::endl);
440 bbtkIncTab("help",1);
441 bbtkMessage("help",1,i->second->GetDescription()<<std::endl);
442 if (i->second->GetNumberOfDescriptors()>0)
444 bbtkMessage("help",1, "Black boxes : "<<std::endl);
445 i->second->PrintHelpListDescriptors(true,adaptors);
449 bbtkMessage("help",1, "No black boxes"<<std::endl);
451 bbtkDecTab("help",1);
455 bbtkDebugDecTab("kernel",9);
456 bbtkError("package \""<<name<<"\" unknown");
459 bbtkDebugDecTab("kernel",9);
461 //===================================================================
463 //===================================================================
464 /// Prints help on the black box of type <name>
465 /// Returns the package to which it belongs
466 void Factory::PrintHelpDescriptor(const std::string& name,
467 std::string& package,
470 bbtkDebugMessageInc("kernel",9,"Factory::PrintHelpDescriptor(\""
475 PackageMapType::const_iterator i;
476 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
478 if (i->second->ContainsDescriptor(name))
480 i->second->PrintHelpDescriptor(name,full);
481 package = i->second->GetName();
486 bbtkDebugDecTab("kernel",9);
489 bbtkError("No package of the factory contains any black box <"
493 //===================================================================
496 //===================================================================
497 /// Inserts a package in the factory
498 void Factory::InsertPackage( Package::Pointer p )
500 bbtkDebugMessageInc("kernel",9,"Factory::InsertPackage(\""<<
501 p->GetName()<<"\")"<<std::endl);
503 p->AddFactory(GetThisPointer<Factory>());
504 mPackageMap[p->GetName()] = p;
505 bbtkDebugDecTab("kernel",9);
507 //===================================================================
509 //===================================================================
510 /// Removes a package from the factory (and deletes it)
511 void Factory::RemovePackage( Package::Pointer p )
513 bbtkDebugMessageInc("kernel",9,"Factory::RemovePackage(\""<<
514 p->GetName()<<"\")"<<std::endl);
516 PackageMapType::iterator i;
517 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
519 if (i->second == p) break;
522 if (i!=mPackageMap.end())
528 bbtkError("Factory::RemovePackage(\""<<
529 p->GetName()<<"\") : package absent from factory");
532 bbtkDebugDecTab("kernel",9);
536 //===================================================================
537 std::string Factory::GetPackageNameOfaBlackBox(std::string boxType)
539 std::string packageName="<void bbtk package name>";
540 PackageMapType::const_iterator i;
542 std::size_t found = boxType.find(":");
543 if (found!=std::string::npos)
545 packageName = boxType.substr(0,found);
547 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
549 if ( i->second->ifBoxExist( boxType ) == true)
551 packageName = i->first;
559 //===================================================================
560 std::string Factory::GetTypeNameOfaBlackBox(std::string boxType)
562 std::string typeName="<void bbtk type name>";
564 std::size_t found = boxType.find(":");
565 if (found!=std::string::npos)
567 typeName = boxType.substr(found+1);
577 //===================================================================
578 /// Creates an instance of a black box of type <type> with name <name>
579 BlackBox::Pointer Factory::NewBlackBox(const std::string& type,
580 const std::string& name) const
582 bbtkDebugMessageInc("kernel",7,"Factory::NewBlackBox(\""
583 <<type<<"\",\""<<name<<"\")"<<std::endl);
586 PackageMapType::const_iterator i;
588 std::string tmp = type;
589 std::string packageName = ((bbtk::Factory*)this)->GetPackageNameOfaBlackBox(tmp);
590 std::string type2 = ((bbtk::Factory*)this)->GetTypeNameOfaBlackBox(tmp);
591 i = mPackageMap.find(packageName);
592 if (i != mPackageMap.end())
594 b = i->second->NewBlackBox(type2,name);
596 b =BlackBox::Pointer();
600 std::size_t found = type.find(":");
601 if (found!=std::string::npos)
603 std::string packageName = type.substr(0,found);
604 std::string type2 = type.substr(found+1);
605 i = mPackageMap.find(packageName);
606 if (i != mPackageMap.end())
608 b = i->second->NewBlackBox(type2,name);
610 b =BlackBox::Pointer();
613 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
615 b = i->second->NewBlackBox(type,name);
625 bbtkError("black box type \""<<type<<"\" unknown");
629 bbtkDebugDecTab("kernel",7);
632 //===================================================================
634 //===================================================================
635 /// Creates an instance of a black box of type <type> with name <name>
636 BlackBox::Pointer Factory::NewAdaptor(const DataInfo& typein,
637 const DataInfo& typeout,
638 const std::string& name) const
640 bbtkDebugMessageInc("kernel",8,"Factory::NewAdaptor("
643 <<name<<"\")"<<bbtkendl);
647 PackageMapType::const_iterator i;
648 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
650 b = i->second->NewAdaptor(typein,typeout,name);
655 bbtkError("no "<<typein<<" to "<<typeout
656 <<" adaptor available");
659 bbtkDebugDecTab("kernel",7);
662 //===================================================================
665 //===================================================================
666 /// Creates an instance of a black box of type <type> with name <name>
667 BlackBox::Pointer Factory::NewWidgetAdaptor(const DataInfo& typein,
668 const DataInfo& typeout,
669 const std::string& name) const
671 bbtkDebugMessageInc("kernel",8,"Factory::NewWidgetAdaptor(<"
674 <<name<<"\")"<<bbtkendl);
678 PackageMapType::const_iterator i;
679 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
681 b = i->second->NewWidgetAdaptor(typein,
688 bbtkError("no "<<typein<<" to "<<typeout
689 <<"> widget adaptor available");
692 bbtkDebugDecTab("kernel",7);
695 //===================================================================
697 //===================================================================
698 /// Creates an instance of a black box of type <type> with name <name>
699 bool Factory::FindAdaptor(const DataInfo& typein,
700 const DataInfo& typeout,
701 std::string& adaptor) const
703 bbtkDebugMessageInc("kernel",8,"Factory::FindAdaptor(<"
705 <<typeout<<">)"<<bbtkendl);
708 PackageMapType::const_iterator i;
709 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
711 b = i->second->FindAdaptor(typein,
719 bbtkError("no "<<typein<<" to "<<typeout
720 <<"> widget adaptor available");
724 bbtkDebugDecTab("kernel",7);
727 //===================================================================
729 //===================================================================
730 /// Creates an instance of a black box of type <type> with name <name>
731 bool Factory::FindWidgetAdaptor(const DataInfo& typein,
732 const DataInfo& typeout,
733 std::string& adaptor) const
735 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
737 <<typeout<<">)"<<bbtkendl);
740 PackageMapType::const_iterator i;
741 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
743 b = i->second->FindWidgetAdaptor(typein,
748 bbtkDebugDecTab("kernel",7);
751 //===================================================================
753 //===================================================================
754 /// Creates an instance of a black box of type <type> with name <name>
755 bool Factory::FindWidgetAdaptor2(const DataInfo& typein,
756 const DataInfo& typeout,
758 std::string& adaptor) const
760 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
762 <<typeout<<">)"<<bbtkendl);
765 adaptor = widget = "";
766 PackageMapType::const_iterator i;
767 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
769 b = i->second->FindWidgetAdaptor(typein,
776 // Look for a widget adaptor with good nature out
777 bbtkMessage("kernel",5,
778 "*** Looking for a two pieces widget adaptor for : "
779 << typein << "->"<<typeout<<std::endl);
780 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
782 Package::AdaptorMapType::const_iterator j;
783 for (j=i->second->GetAdaptorMap().begin();
784 j!=i->second->GetAdaptorMap().end();
787 if ( ( j->first.mKind ==
788 BlackBoxDescriptor::DEFAULT_GUI) &&
789 //(j->first.mTypeIn == typein) &&
790 (j->first.mTypeOut.GetNature() == typeout.GetNature() )
793 widget = j->second.lock()->GetTypeName();
794 bbtkMessage("kernel",5,
795 "===> Found first part : "<<widget
796 << " "<<j->first.mTypeIn<<"->"
797 <<j->first.mTypeOut<<std::endl);
798 DataInfo ti( j->first.mTypeOut.GetType(), "");
799 DataInfo to( typeout.GetType(), "");
800 b = FindAdaptor( ti, to, adaptor );
803 bbtkMessage("kernel",5,
804 "===> Found second part : "<<adaptor
810 bbtkMessage("kernel",5,
811 "===> No second part found"<<std::endl);
818 bbtkDebugDecTab("kernel",7);
821 //===================================================================
823 //===================================================================
824 /// Creates an instance of a connection
825 Connection::Pointer Factory::NewConnection(BlackBox::Pointer from,
826 const std::string& output,
827 BlackBox::Pointer to,
828 const std::string& input) const
830 bbtkDebugMessage("kernel",7,"Factory::NewConnection(\""
831 <<from->bbGetName()<<"\",\""<<output<<"\",\""
832 <<to->bbGetName()<<"\",\""<<input
835 return Connection::New(from,output,to,input,
836 GetThisPointer<Factory>());
838 //===================================================================
842 //===================================================================
843 Package::Pointer Factory::GetPackage(const std::string& name) const
845 bbtkDebugMessageInc("kernel",9,"Factory::GetPackage(\""<<name<<"\")"
848 PackageMapType::const_iterator i = mPackageMap.find(name);
849 if ( i != mPackageMap.end() )
851 bbtkDebugDecTab("kernel",9);
856 bbtkDebugDecTab("kernel",9);
857 bbtkError("package \""<<name<<"\" unknown");
860 bbtkDebugDecTab("kernel",9);
862 //===================================================================
865 //===================================================================
866 void Factory::Check() const
868 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
870 PackageMapType::const_iterator i;
871 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
875 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
876 <<" ... OK"<<std::endl);
878 //===================================================================
880 //===================================================================
881 void Factory::WriteDotFilePackagesList(FILE *ff)
884 bbtkDebugMessageInc("kernel",9,"Factory::WriteDotFilePackagesList()"
888 fprintf( ff , "subgraph cluster_FACTORY {\n");
889 fprintf( ff , " label = \"PACKAGES\"%s\n", ";");
890 fprintf( ff , " style=filled%s\n",";");
891 fprintf( ff , " color=lightgrey%s\n",";");
892 fprintf( ff , " rankdir=TB%s\n",";");
895 PackageMapType::const_iterator i;
896 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
898 url=GetPackage(i->first)->GetDocURL();
899 fprintf(ff," %s [shape=ellipse, URL=\"%s\"]%s\n",i->first.c_str(),url.c_str(),";" );
901 fprintf( ff , "}\n\n");
902 bbtkDebugDecTab("kernel",9);
904 //===================================================================
907 void Factory::ShowGraphTypes(const std::string& name) const
910 PackageMapType::const_iterator i;
911 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
913 if (i->second->ContainsDescriptor(name))
915 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
917 // Don't pollute the file store with "temp_dir" directories ...
918 std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
919 std::string directory = "\"" + default_doc_dir + separator + "temp_dir" +separator + "\"";
920 std::string filename2 = default_doc_dir + separator + "temp_dir" + separator + "tmp.html";
923 std::string command("start \"Titre\" /D ");
925 std::string command("gnome-open ");
927 command=command + directory +" tmp.html";
929 ff=fopen(filename2.c_str(),"w");
931 fprintf(ff,"<html><head><title>TMP</title> <script type=\"text/javascript\"> <!--\n");
932 fprintf(ff," window.location=\"%s#%s\";\n" , i->second->GetDocURL().c_str(),name.c_str() );
933 fprintf(ff,"//--></script></head><body></body></html>\n");
936 //fprintf(ff, "<a href=\"%s#%s\">Link</a>\n", i->second->GetDocURL().c_str(),name.c_str() );
938 system( command.c_str() );
943 bbtkDebugDecTab("kernel",9);
946 bbtkError("No package of the factory contains any black box <"
954 void Factory::CreateHtmlIndex(IndexEntryType type,
955 const std::string& filename)
957 bbtkDebugMessageInc("kernel",9,"Factory::CreateHtmlIndex(\""
958 <<filename<<"\")"<<bbtkendl);
962 typedef std::map<std::string,
963 std::vector<BlackBoxDescriptor::Pointer> > IndexType;
965 // Builds the index map
966 PackageMapType::const_iterator i;
967 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
969 Package::Pointer pack = i->second;
970 if (pack->GetName()=="user") continue;
971 Package::DescriptorMapType::const_iterator j;
972 for (j = pack->GetDescriptorMap().begin();
973 j!= pack->GetDescriptorMap().end();
978 if ( type==Adaptors )
980 if (j->second->GetKind() == BlackBoxDescriptor::STANDARD )
984 if (j->second->GetKind() != BlackBoxDescriptor::STANDARD )
987 std::vector<std::string> keys;
991 k += pack->GetName();
993 title = "Boxes by package";
995 else if ((type==Initials) || (type==Adaptors))
997 std::string init(" ");
998 init[0] = std::toupper(j->second->GetTypeName()[0]);
999 keys.push_back(init);
1000 title = "Alphabetical list";
1002 else if (type==Categories)
1004 // Split the category string
1005 std::string delimiters = ";,";
1006 Utilities::SplitString(j->second->GetCategory(),
1009 keys.push_back(" NONE");
1010 title = "Boxes by category";
1013 std::vector<std::string>::const_iterator k;
1014 for (k=keys.begin(); k!=keys.end(); ++k )
1016 IndexType::iterator p;
1018 if (p != index.end())
1020 p->second.push_back(j->second);
1024 std::vector<BlackBoxDescriptor::Pointer> v;
1025 v.push_back(j->second);
1032 //---------------------
1035 s.open(filename.c_str());
1038 bbtkError("Factory::CreateHtmlIndex : could not open file '"
1042 //----------------------
1044 s << "<html lang=\"en\">\n";
1046 s << "<title>"<<title<<"</title>\n";
1047 s << "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n";
1048 s << "<meta name=\"description\" content=\""<<title<<"\">\n";
1049 s << "<meta name=\"generator\" content=\"\">\n";
1050 s << "<link title=\"Top\" rel=\"top\" href=\"#Top\">\n";
1051 //<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
1052 s << "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><style type=\"text/css\"><!--\n";
1053 s << "pre.display { font-family:inherit }\n";
1054 s << "pre.format { font-family:inherit }\n";
1055 s << "pre.smalldisplay { font-family:inherit; font-size:smaller }\n";
1056 s << "pre.smallformat { font-family:inherit; font-size:smaller }\n";
1057 s << "pre.smallexample { font-size:smaller }\n";
1058 s << "pre.smalllisp { font-size:smaller }\n";
1059 s << "span.sc { font-variant:small-caps }\n";
1060 s << "span.roman { font-family:serif; font-weight:normal; } \n";
1061 s << "span.sansserif { font-family:sans-serif; font-weight:normal; }\n";
1062 s << "--></style>\n";
1064 //----------------------
1066 //----------------------
1069 s << "<a name=\"Top\"></a>\n";
1070 s << "<h1 class=\"settitle\">"<<title<<"</h1>\n";
1072 IndexType::iterator ii;
1073 for (ii=index.begin();ii!=index.end();++ii)
1075 s << "<a href=\"#"<<ii->first<<"\">"<<ii->first<<"</a> ";
1078 for (ii=index.begin();ii!=index.end();++ii)
1081 s << "<p><a href=\"#Top\">Top</a>";
1084 s << "<a name=\""<<ii->first<<"\"></a>\n";
1085 s << "<p><a href=\""<<ii->first<<"/index.html\">"
1086 << ii->first<<"</a>\n";
1088 s << " - \n";
1090 s << "<a name=\"doxygen\"></a>\n";
1094 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1095 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1097 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1098 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1102 s << "<a name=\""<<ii->first<<"\"></a>\n";
1103 s << "<p><b>"<<ii->first<<"</b>\n";
1107 s << "<p><TABLE cellspacing=0 cellpadding=3>\n";
1109 std::vector<BlackBoxDescriptor::Pointer>::iterator di;
1110 for (di=ii->second.begin();di!=ii->second.end();++di)
1112 std::string pack = (*di)->GetPackage()->GetName();
1113 std::string name = (*di)->GetTypeName();
1114 Utilities::html_format(name);
1115 std::string descr = (*di)->GetDescription();
1116 Utilities::html_format(descr);
1118 s << "<TD style='vertical-align: top;'>";
1119 s << " <a href=\""<<pack
1120 <<"/index.html#"<<name<<"\">"
1121 <<pack<<"::"<<name<<"</a>";
1123 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1130 //----------------------
1135 ptm = gmtime ( &rawtime );
1138 s << "Automatically generated by <b>bbtk</b> on "
1139 << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900
1140 << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n";
1141 s << "</body></html>\n";
1143 //----------------------
1146 bbtkDebugDecTab("kernel",9);
1149 //==========================================================================
1150 std::string Factory::GetObjectName() const
1152 return std::string("Factory");
1154 //==========================================================================
1156 //==========================================================================
1157 std::string Factory::GetObjectInfo() const
1159 std::stringstream i;
1162 //==========================================================================
1164 //==========================================================================
1165 size_t Factory::GetObjectSize() const
1167 size_t s = Superclass::GetObjectSize();
1168 s += Factory::GetObjectInternalSize();
1171 //==========================================================================
1172 //==========================================================================
1173 size_t Factory::GetObjectInternalSize() const
1175 size_t s = sizeof(Factory);
1178 //==========================================================================
1179 //==========================================================================
1180 size_t Factory::GetObjectRecursiveSize() const
1182 size_t s = Superclass::GetObjectRecursiveSize();
1183 s += Factory::GetObjectInternalSize();
1185 PackageMapType::const_iterator i;
1186 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
1188 s += i->second->GetObjectRecursiveSize();
1192 //==========================================================================