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
161 bbtkDebugMessageInc("kernel",7,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
162 bbtkMessage("debug",1,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
164 std::vector<std::string> package_paths;
165 std::string libname; // full path library name
166 std::string pkgname; // e.g. libbb<pkgname>.so
170 pkgname = Utilities::ExtractPackageName(name,upath);
172 bbtkMessage("debug",1,"Package name ["<<pkgname<<"]"<<std::endl);
173 bbtkMessage("debug",1,"Package path ["<<upath<<"]"<<std::endl);
175 // no loading package if already loaded
176 PackageMapType::iterator iUnload;
177 iUnload = mPackageMap.find(pkgname);
179 //EED Debuging message
180 // std::cout << "EED Factory::LoadPackage " << std::endl;
181 // PackageMapType::iterator it;
182 // for ( it=mPackageMap.begin() ; it != mPackageMap.end(); it++ )
183 // std::cout << (*it).first << " ";
184 // std::cout << std::endl;
187 if (iUnload != mPackageMap.end())
189 bbtkMessage("output",2,"["<< pkgname <<"] already loaded" << std::endl);
193 // =================================================
194 // The following structure was checked to work
195 // with any type of relative/absolute path.
196 // Please don't modify it without checking
197 // *all* the cases. JP
198 //==================================================
201 bool foundFile = false;
203 // If path provided by user will be the first scanned :
204 // push it into vector of paths
205 if (upath.length()>0) // ------------------------------------- check user supplied location
207 if (name[0] != '.' && name[0] != '/' && name[1]!= ':')
209 bbtkError("Use absolute or relative path name! ["<<name<<"] is an illegal name");
213 // std::string path = Utilities::ExpandLibName(upath, false);
215 std::string path = Utilities::ExpandLibName(name,false); // keep last item, here.
219 Utilities::ExtractPackageName(path,p2);
220 //libname = Utilities::MakeLibnameFromPath(path, pkgname);
221 libname = Utilities::MakeLibnameFromPath(p2, pkgname); // remove last item
222 // Check if library exists
223 if ( !Utilities::FileExists(libname) )
225 // The following is *NOT* a debug time message :
226 // It's a user intended message.
227 // Please don't remove it.
228 bbtkMessage("output",3," [" << libname <<"] : doesn't exist" <<std::endl);
230 ok = DoLoadPackage( libname, pkgname, path);
233 bbtkError("Path ["<<upath<<"] doesn't exist");
236 } else // ----------------------------------------------------- iterate on the paths
239 std::string path = ".";
240 package_paths = ConfigurationFile::GetInstance().Get_package_paths();
241 std::vector<std::string>::iterator i;
242 for (i=package_paths.begin();i!=package_paths.end();++i)
246 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = path "<<path<<std::endl;
247 // we *really* want '.' to be the current working directory
250 char buf[2048]; // for getcwd
251 char * currentDir = getcwd(buf, 2048);
252 std::string cwd(currentDir);
253 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = currentDir "<<currentDir<<std::endl;
256 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = path "<<path<<" pkgnam="<<pkgname<<std::endl;
257 libname = Utilities::MakeLibnameFromPath(path, pkgname);
259 bbtkMessage("debug",2,"-> Trying to load [" << libname << "]" <<std::endl);
261 // Check if library exists
262 if ( !Utilities::FileExists(libname) )
264 // The following is *NOT* a debug time message :
265 // It's a user intended message.
266 // Please don't remove it.
267 bbtkMessage("output",3,
268 " [" <<libname <<"] : doesn't exist" <<std::endl);
269 continue; // try next path
273 // Try to Load the library
274 ok = DoLoadPackage( libname, pkgname, path);
277 bbtkMessage("debug",2," OK"<<std::endl);
279 break; // we stop iterating even if error : have to signal it to user
280 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
284 if( !ok ) // nothing was loaded
288 bbtkError("Could not find package ["<<pkgname<< "]");
292 #if defined(__GNUC__)
293 bbtkError("Could not load package ["<< pkgname
295 << " Opening "<<libname<<" failed"
296 << " Reason: "<< dlerror());
297 #elif defined(_WIN32)
298 bbtkError("Could not load package ["<<pkgname
299 <<"] :"<< std::endl << " Error loading " <<libname);
301 // look how to get the error message on win
303 // it is the bordel !! (the bloody fucking bordel, you mean?)
304 // look : http://msdn2.microsoft.com/en-us/library/ms680582.aspx
308 bbtkMessage("output",2,"[" << libname << "] loaded" << std::endl);
312 //===================================================================
313 /// \brief UnLoads a package.
315 /// The package must have been previously loaded by LoadPackage.
316 /// If the entry is found in the map, calls ClosePackage
317 void Factory::UnLoadPackage( const std::string& name )
319 bbtkDebugMessageInc("kernel",7,"Factory::UnLoadPackage(\""
320 <<name<<"\")"<<std::endl);
322 PackageMapType::iterator i;
323 i = mPackageMap.find(name);
324 if (i == mPackageMap.end())
326 bbtkError("cannot unload package \""<<name
327 <<"\" : package not loaded !");
330 bbtkDebugDecTab("kernel",7);
332 //===================================================================
335 //===================================================================
336 void Factory::CloseAllPackages()
338 bbtkDebugMessageInc("kernel",7,"Factory::CloseAllPackages()"<<std::endl);
340 std::vector< Package::WeakPointer > mAlive;
343 while (mPackageMap.begin() != mPackageMap.end())
345 PackageMapType::iterator i = mPackageMap.begin();
346 Package::WeakPointer p = i->second;
348 if (p.lock()) mAlive.push_back(p);
350 std::vector< Package::WeakPointer >::iterator i;
351 for (i=mAlive.begin();i!=mAlive.end();++i)
353 // If not dead : reinsert
356 bbtkDebugMessage("kernel",7,"Package "<<i->lock()->GetName()
357 <<" still alive"<<std::endl);
358 // InsertPackage(i->lock());
362 while (mPackageMap.size()>0);
364 bbtkDebugDecTab("kernel",7);
366 //===================================================================
368 //===================================================================
369 /// \brief Close the package referenced by the iterator
371 /// First removes the factory from the set of factories which use the package
372 /// If the set is empty then :
373 /// If it is a dynamically loaded package :
374 /// - Loads and calls the function "<name>DeletePackage" of the dynamic library (responsible for package desallocation)
375 /// - Closes the dynamic library
377 /// - deletes the package normally
379 /// Finally erases the package entry in the packages map
380 void Factory::ClosePackage(PackageMapType::iterator& i)
382 bbtkDebugMessageInc("kernel",7,"Factory::ClosePackage(\""
383 <<i->second->GetName()
387 // Removes this from the set of factories which use the package
388 i->second->RemoveFactory(GetThisPointer<Factory>());
389 Package::WeakPointer p = i->second;
390 // remove the entry in the map
391 mPackageMap.erase(i);
392 // Release the package if not already destroyed
397 bbtkDebugDecTab("kernel",7);
399 //===================================================================
403 //===================================================================
404 void Factory::PrintHelpListPackages(bool details, bool adaptors) const
406 bbtkDebugMessageInc("kernel",9,"Factory::PrintPackages"<<std::endl);
408 PackageMapType::const_iterator i;
409 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
411 bbtkMessage("help",1, i->first << std::endl);
413 i->second->PrintHelpListDescriptors(false,adaptors);
417 bbtkDebugDecTab("kernel",9);
419 //===================================================================
421 //===================================================================
422 /// Displays help on a package
423 void Factory::PrintHelpPackage(const std::string& name, bool adaptors) const
425 bbtkDebugMessageInc("kernel",9,"Factory::PrintHelpPackage(\""
429 PackageMapType::const_iterator i = mPackageMap.find(name);
430 if ( i != mPackageMap.end() )
432 bbtkMessage("help",1, "Package "<<i->first<<" ");
434 if (i->second->GetVersion().length()>0)
435 bbtkMessageCont("help",1,"v" <<i->second->GetVersion());
437 if (i->second->GetAuthor().length()>0)
438 bbtkMessageCont("help",1,"- "<<i->second->GetAuthor());
440 if (i->second->GetCategory().length()>0)
441 bbtkMessageCont("help",1,"- "<<i->second->GetCategory());
443 bbtkMessageCont("help",1,std::endl);
444 bbtkIncTab("help",1);
445 bbtkMessage("help",1,i->second->GetDescription()<<std::endl);
446 if (i->second->GetNumberOfDescriptors()>0)
448 bbtkMessage("help",1, "Black boxes : "<<std::endl);
449 i->second->PrintHelpListDescriptors(true,adaptors);
453 bbtkMessage("help",1, "No black boxes"<<std::endl);
455 bbtkDecTab("help",1);
459 bbtkDebugDecTab("kernel",9);
460 bbtkError("package \""<<name<<"\" unknown");
463 bbtkDebugDecTab("kernel",9);
465 //===================================================================
467 //===================================================================
468 /// Prints help on the black box of type <name>
469 /// Returns the package to which it belongs
470 void Factory::PrintHelpDescriptor(const std::string& name,
471 std::string& package,
474 bbtkDebugMessageInc("kernel",9,"Factory::PrintHelpDescriptor(\""
479 PackageMapType::const_iterator i;
480 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
482 if (i->second->ContainsDescriptor(name))
484 i->second->PrintHelpDescriptor(name,full);
485 package = i->second->GetName();
490 bbtkDebugDecTab("kernel",9);
493 bbtkError("No package of the factory contains any black box <"
497 //===================================================================
500 //===================================================================
501 /// Inserts a package in the factory
502 void Factory::InsertPackage( Package::Pointer p )
504 bbtkDebugMessageInc("kernel",9,"Factory::InsertPackage(\""<<
505 p->GetName()<<"\")"<<std::endl);
507 p->AddFactory(GetThisPointer<Factory>());
508 mPackageMap[p->GetName()] = p;
509 bbtkDebugDecTab("kernel",9);
511 //===================================================================
513 //===================================================================
514 /// Removes a package from the factory (and deletes it)
515 void Factory::RemovePackage( Package::Pointer p )
517 bbtkDebugMessageInc("kernel",9,"Factory::RemovePackage(\""<<
518 p->GetName()<<"\")"<<std::endl);
520 PackageMapType::iterator i;
521 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
523 if (i->second == p) break;
526 if (i!=mPackageMap.end())
532 bbtkError("Factory::RemovePackage(\""<<
533 p->GetName()<<"\") : package absent from factory");
536 bbtkDebugDecTab("kernel",9);
540 //===================================================================
541 std::string Factory::GetPackageNameOfaBlackBox(std::string boxType)
543 std::string packageName="<void bbtk package name>";
544 PackageMapType::const_iterator i;
546 std::size_t found = boxType.find(":");
547 if (found!=std::string::npos)
549 packageName = boxType.substr(0,found);
551 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
553 if ( i->second->ifBoxExist( boxType ) == true)
555 packageName = i->first;
563 //===================================================================
564 std::string Factory::GetTypeNameOfaBlackBox(std::string boxType)
566 std::string typeName="<void bbtk type name>";
568 std::size_t found = boxType.find(":");
569 if (found!=std::string::npos)
571 typeName = boxType.substr(found+1);
581 //===================================================================
582 /// Creates an instance of a black box of type <type> with name <name>
583 BlackBox::Pointer Factory::NewBlackBox(const std::string& type,
584 const std::string& name) const
586 bbtkDebugMessageInc("kernel",7,"Factory::NewBlackBox(\""
587 <<type<<"\",\""<<name<<"\")"<<std::endl);
590 PackageMapType::const_iterator i;
592 std::string tmp = type;
593 std::string packageName = ((bbtk::Factory*)this)->GetPackageNameOfaBlackBox(tmp);
594 std::string type2 = ((bbtk::Factory*)this)->GetTypeNameOfaBlackBox(tmp);
595 i = mPackageMap.find(packageName);
596 if (i != mPackageMap.end())
598 b = i->second->NewBlackBox(type2,name);
600 b =BlackBox::Pointer();
604 std::size_t found = type.find(":");
605 if (found!=std::string::npos)
607 std::string packageName = type.substr(0,found);
608 std::string type2 = type.substr(found+1);
609 i = mPackageMap.find(packageName);
610 if (i != mPackageMap.end())
612 b = i->second->NewBlackBox(type2,name);
614 b =BlackBox::Pointer();
617 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
619 b = i->second->NewBlackBox(type,name);
629 bbtkError("black box type \""<<type<<"\" unknown");
633 bbtkDebugDecTab("kernel",7);
636 //===================================================================
638 //===================================================================
639 /// Creates an instance of a black box of type <type> with name <name>
640 BlackBox::Pointer Factory::NewAdaptor(const DataInfo& typein,
641 const DataInfo& typeout,
642 const std::string& name) const
644 bbtkDebugMessageInc("kernel",8,"Factory::NewAdaptor("
647 <<name<<"\")"<<bbtkendl);
651 PackageMapType::const_iterator i;
652 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
654 b = i->second->NewAdaptor(typein,typeout,name);
659 bbtkError("no "<<typein<<" to "<<typeout
660 <<" adaptor available");
663 bbtkDebugDecTab("kernel",7);
666 //===================================================================
669 //===================================================================
670 /// Creates an instance of a black box of type <type> with name <name>
671 BlackBox::Pointer Factory::NewWidgetAdaptor(const DataInfo& typein,
672 const DataInfo& typeout,
673 const std::string& name) const
675 bbtkDebugMessageInc("kernel",8,"Factory::NewWidgetAdaptor(<"
678 <<name<<"\")"<<bbtkendl);
682 PackageMapType::const_iterator i;
683 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
685 b = i->second->NewWidgetAdaptor(typein,
692 bbtkError("no "<<typein<<" to "<<typeout
693 <<"> widget adaptor available");
696 bbtkDebugDecTab("kernel",7);
699 //===================================================================
701 //===================================================================
702 /// Creates an instance of a black box of type <type> with name <name>
703 bool Factory::FindAdaptor(const DataInfo& typein,
704 const DataInfo& typeout,
705 std::string& adaptor) const
707 bbtkDebugMessageInc("kernel",8,"Factory::FindAdaptor(<"
709 <<typeout<<">)"<<bbtkendl);
712 PackageMapType::const_iterator i;
713 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
715 b = i->second->FindAdaptor(typein,
723 bbtkError("no "<<typein<<" to "<<typeout
724 <<"> widget adaptor available");
728 bbtkDebugDecTab("kernel",7);
731 //===================================================================
733 //===================================================================
734 /// Creates an instance of a black box of type <type> with name <name>
735 bool Factory::FindWidgetAdaptor(const DataInfo& typein,
736 const DataInfo& typeout,
737 std::string& adaptor) const
739 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
741 <<typeout<<">)"<<bbtkendl);
744 PackageMapType::const_iterator i;
745 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
747 b = i->second->FindWidgetAdaptor(typein,
752 bbtkDebugDecTab("kernel",7);
755 //===================================================================
757 //===================================================================
758 /// Creates an instance of a black box of type <type> with name <name>
759 bool Factory::FindWidgetAdaptor2(const DataInfo& typein,
760 const DataInfo& typeout,
762 std::string& adaptor) const
764 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
766 <<typeout<<">)"<<bbtkendl);
769 adaptor = widget = "";
770 PackageMapType::const_iterator i;
771 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
773 b = i->second->FindWidgetAdaptor(typein,
780 // Look for a widget adaptor with good nature out
781 bbtkMessage("kernel",5,
782 "*** Looking for a two pieces widget adaptor for : "
783 << typein << "->"<<typeout<<std::endl);
784 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
786 Package::AdaptorMapType::const_iterator j;
787 for (j=i->second->GetAdaptorMap().begin();
788 j!=i->second->GetAdaptorMap().end();
791 if ( ( j->first.mKind ==
792 BlackBoxDescriptor::DEFAULT_GUI) &&
793 //(j->first.mTypeIn == typein) &&
794 (j->first.mTypeOut.GetNature() == typeout.GetNature() )
797 widget = j->second.lock()->GetTypeName();
798 bbtkMessage("kernel",5,
799 "===> Found first part : "<<widget
800 << " "<<j->first.mTypeIn<<"->"
801 <<j->first.mTypeOut<<std::endl);
802 DataInfo ti( j->first.mTypeOut.GetType(), "");
803 DataInfo to( typeout.GetType(), "");
804 b = FindAdaptor( ti, to, adaptor );
807 bbtkMessage("kernel",5,
808 "===> Found second part : "<<adaptor
814 bbtkMessage("kernel",5,
815 "===> No second part found"<<std::endl);
822 bbtkDebugDecTab("kernel",7);
825 //===================================================================
827 //===================================================================
828 /// Creates an instance of a connection
829 Connection::Pointer Factory::NewConnection(BlackBox::Pointer from,
830 const std::string& output,
831 BlackBox::Pointer to,
832 const std::string& input) const
834 bbtkDebugMessage("kernel",7,"Factory::NewConnection(\""
835 <<from->bbGetName()<<"\",\""<<output<<"\",\""
836 <<to->bbGetName()<<"\",\""<<input
839 return Connection::New(from,output,to,input,
840 GetThisPointer<Factory>());
842 //===================================================================
846 //===================================================================
847 Package::Pointer Factory::GetPackage(const std::string& name) const
849 bbtkDebugMessageInc("kernel",9,"Factory::GetPackage(\""<<name<<"\")"
852 PackageMapType::const_iterator i = mPackageMap.find(name);
853 if ( i != mPackageMap.end() )
855 bbtkDebugDecTab("kernel",9);
860 bbtkDebugDecTab("kernel",9);
861 bbtkError("package \""<<name<<"\" unknown");
864 bbtkDebugDecTab("kernel",9);
866 //===================================================================
869 //===================================================================
870 void Factory::Check() const
872 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
874 PackageMapType::const_iterator i;
875 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
879 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
880 <<" ... OK"<<std::endl);
882 //===================================================================
884 //===================================================================
885 void Factory::WriteDotFilePackagesList(FILE *ff)
888 bbtkDebugMessageInc("kernel",9,"Factory::WriteDotFilePackagesList()"
892 fprintf( ff , "subgraph cluster_FACTORY {\n");
893 fprintf( ff , " label = \"PACKAGES\"%s\n", ";");
894 fprintf( ff , " style=filled%s\n",";");
895 fprintf( ff , " color=lightgrey%s\n",";");
896 fprintf( ff , " rankdir=TB%s\n",";");
899 PackageMapType::const_iterator i;
900 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
902 url=GetPackage(i->first)->GetDocURL();
903 fprintf(ff," %s [shape=ellipse, URL=\"%s\"]%s\n",i->first.c_str(),url.c_str(),";" );
905 fprintf( ff , "}\n\n");
906 bbtkDebugDecTab("kernel",9);
908 //===================================================================
911 void Factory::ShowGraphTypes(const std::string& name) const
914 PackageMapType::const_iterator i;
915 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
917 if (i->second->ContainsDescriptor(name))
919 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
921 // Don't pollute the file store with "temp_dir" directories ...
922 std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
923 std::string directory = "\"" + default_doc_dir + separator + "temp_dir" +separator + "\"";
924 std::string filename2 = default_doc_dir + separator + "temp_dir" + separator + "tmp.html";
927 std::string command("start \"Titre\" /D ");
929 std::string command("gnome-open ");
931 command=command + directory +" tmp.html";
933 ff=fopen(filename2.c_str(),"w");
935 fprintf(ff,"<html><head><title>TMP</title> <script type=\"text/javascript\"> <!--\n");
936 fprintf(ff," window.location=\"%s#%s\";\n" , i->second->GetDocURL().c_str(),name.c_str() );
937 fprintf(ff,"//--></script></head><body></body></html>\n");
940 //fprintf(ff, "<a href=\"%s#%s\">Link</a>\n", i->second->GetDocURL().c_str(),name.c_str() );
942 system( command.c_str() );
947 bbtkDebugDecTab("kernel",9);
950 bbtkError("No package of the factory contains any black box <"
958 void Factory::CreateHtmlIndex(IndexEntryType type,
959 const std::string& filename)
961 bbtkDebugMessageInc("kernel",9,"Factory::CreateHtmlIndex(\""
962 <<filename<<"\")"<<bbtkendl);
966 typedef std::map<std::string,
967 std::vector<BlackBoxDescriptor::Pointer> > IndexType;
969 // Builds the index map
970 PackageMapType::const_iterator i;
971 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
973 Package::Pointer pack = i->second;
974 if (pack->GetName()=="user") continue;
975 Package::DescriptorMapType::const_iterator j;
976 for (j = pack->GetDescriptorMap().begin();
977 j!= pack->GetDescriptorMap().end();
982 if ( type==Adaptors )
984 if (j->second->GetKind() == BlackBoxDescriptor::STANDARD )
988 if (j->second->GetKind() != BlackBoxDescriptor::STANDARD )
991 std::vector<std::string> keys;
995 k += pack->GetName();
997 title = "Boxes by package";
999 else if ((type==Initials) || (type==Adaptors))
1001 std::string init(" ");
1002 init[0] = std::toupper(j->second->GetTypeName()[0]);
1003 keys.push_back(init);
1004 title = "Alphabetical list";
1006 else if (type==Categories)
1008 // Split the category string
1009 std::string delimiters = ";,";
1010 Utilities::SplitString(j->second->GetCategory(),
1013 keys.push_back(" NONE");
1014 title = "Boxes by category";
1017 std::vector<std::string>::const_iterator k;
1018 for (k=keys.begin(); k!=keys.end(); ++k )
1020 IndexType::iterator p;
1022 if (p != index.end())
1024 p->second.push_back(j->second);
1028 std::vector<BlackBoxDescriptor::Pointer> v;
1029 v.push_back(j->second);
1036 //---------------------
1039 s.open(filename.c_str());
1042 bbtkError("Factory::CreateHtmlIndex : could not open file '"
1046 //----------------------
1048 s << "<html lang=\"en\">\n";
1050 s << "<title>"<<title<<"</title>\n";
1051 s << "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n";
1052 s << "<meta name=\"description\" content=\""<<title<<"\">\n";
1053 s << "<meta name=\"generator\" content=\"\">\n";
1054 s << "<link title=\"Top\" rel=\"top\" href=\"#Top\">\n";
1055 //<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
1056 s << "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><style type=\"text/css\"><!--\n";
1057 s << "pre.display { font-family:inherit }\n";
1058 s << "pre.format { font-family:inherit }\n";
1059 s << "pre.smalldisplay { font-family:inherit; font-size:smaller }\n";
1060 s << "pre.smallformat { font-family:inherit; font-size:smaller }\n";
1061 s << "pre.smallexample { font-size:smaller }\n";
1062 s << "pre.smalllisp { font-size:smaller }\n";
1063 s << "span.sc { font-variant:small-caps }\n";
1064 s << "span.roman { font-family:serif; font-weight:normal; } \n";
1065 s << "span.sansserif { font-family:sans-serif; font-weight:normal; }\n";
1066 s << "--></style>\n";
1068 //----------------------
1070 //----------------------
1073 s << "<a name=\"Top\"></a>\n";
1074 s << "<h1 class=\"settitle\">"<<title<<"</h1>\n";
1076 IndexType::iterator ii;
1077 for (ii=index.begin();ii!=index.end();++ii)
1079 s << "<a href=\"#"<<ii->first<<"\">"<<ii->first<<"</a> ";
1082 for (ii=index.begin();ii!=index.end();++ii)
1085 s << "<p><a href=\"#Top\">Top</a>";
1088 s << "<a name=\""<<ii->first<<"\"></a>\n";
1089 s << "<p><a href=\""<<ii->first<<"/index.html\">"
1090 << ii->first<<"</a>\n";
1092 s << " - \n";
1094 s << "<a name=\"doxygen\"></a>\n";
1098 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1099 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1101 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1102 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1106 s << "<a name=\""<<ii->first<<"\"></a>\n";
1107 s << "<p><b>"<<ii->first<<"</b>\n";
1111 s << "<p><TABLE cellspacing=0 cellpadding=3>\n";
1113 std::vector<BlackBoxDescriptor::Pointer>::iterator di;
1114 for (di=ii->second.begin();di!=ii->second.end();++di)
1116 std::string pack = (*di)->GetPackage()->GetName();
1117 std::string name = (*di)->GetTypeName();
1118 Utilities::html_format(name);
1119 std::string descr = (*di)->GetDescription();
1120 Utilities::html_format(descr);
1122 s << "<TD style='vertical-align: top;'>";
1123 s << " <a href=\""<<pack
1124 <<"/index.html#"<<name<<"\">"
1125 <<pack<<"::"<<name<<"</a>";
1127 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1134 //----------------------
1139 ptm = gmtime ( &rawtime );
1142 s << "Automatically generated by <b>bbtk</b> on "
1143 << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900
1144 << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n";
1145 s << "</body></html>\n";
1147 //----------------------
1150 bbtkDebugDecTab("kernel",9);
1153 //==========================================================================
1154 std::string Factory::GetObjectName() const
1156 return std::string("Factory");
1158 //==========================================================================
1160 //==========================================================================
1161 std::string Factory::GetObjectInfo() const
1163 std::stringstream i;
1166 //==========================================================================
1168 //==========================================================================
1169 size_t Factory::GetObjectSize() const
1171 size_t s = Superclass::GetObjectSize();
1172 s += Factory::GetObjectInternalSize();
1175 //==========================================================================
1176 //==========================================================================
1177 size_t Factory::GetObjectInternalSize() const
1179 size_t s = sizeof(Factory);
1182 //==========================================================================
1183 //==========================================================================
1184 size_t Factory::GetObjectRecursiveSize() const
1186 size_t s = Superclass::GetObjectRecursiveSize();
1187 s += Factory::GetObjectInternalSize();
1189 PackageMapType::const_iterator i;
1190 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
1192 s += i->second->GetObjectRecursiveSize();
1196 //==========================================================================