1 /*=========================================================================
4 Module: $RCSfile: bbtkFactory.cxx,v $
7 Date: $Date: 2008/03/11 12:27:21 $
8 Version: $Revision: 1.30 $
11 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
12 l'Image). All rights reserved. See doc/license.txt or
13 http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
15 This software is distributed WITHOUT ANY WARRANTY; without even
16 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17 PURPOSE. See the above copyright notices for more information.
19 =========================================================================*/
22 *\brief Class bbtk::Factory : can load and unload dynamic libraries containing
23 * black boxes packages and create instances of the black boxes registered
24 * in the packages loaded.
26 #include "bbtkFactory.h"
27 #include "bbtkMessageManager.h"
28 #include "bbtkConnection.h"
29 #include "bbtkConfigurationFile.h"
30 #include "bbtkUtilities.h"
32 #include <sys/stat.h> // for struct stat stFileInfo
35 #include <direct.h> // for getcwd
38 #include <cctype> // std::toupper
43 typedef Package* (*PackageAccessor)();
44 typedef void (*PackageDeleteFunction)();
47 //===================================================================
52 bbtkDebugMessage("Kernel",7,"Factory::Factory()"<<std::endl);
54 //===================================================================
56 //===================================================================
60 bbtkDebugMessageInc("Kernel",7,"Factory::~Factory()"<<std::endl);
62 bbtkDebugDecTab("Kernel",7);
64 //===================================================================
67 //===================================================================
68 void Factory::CloseAllPackages()
70 bbtkDebugMessageInc("Kernel",7,"Factory::CloseAllPackages()"<<std::endl);
71 while (mPackageMap.begin() != mPackageMap.end())
73 PackageMapType::iterator i = mPackageMap.begin();
76 bbtkDebugDecTab("Kernel",7);
78 //===================================================================
80 //===================================================================
84 printf("EED kkkkkkkkkkkkkkkkkkkkkkkk Factory::Reset() \n");
85 printf("EED kkkkkkkkkkkkkkkkkkkkkkkk Factory::Reset() \n");
86 printf("EED kkkkkkkkkkkkkkkkkkkkkkkk Factory::Reset() \n");
87 printf("EED kkkkkkkkkkkkkkkkkkkkkkkk Factory::Reset() \n");
88 printf("EED kkkkkkkkkkkkkkkkkkkkkkkk Factory::Reset() \n");
89 printf("EED kkkkkkkkkkkkkkkkkkkkkkkk Factory::Reset() \n");
91 bbtkDebugMessageInc("Kernel",7,"Factory::Reset()"<<std::endl);
93 bbtkDebugDecTab("Kernel",7);
95 //===================================================================
98 // ===================================================================
99 bool Factory::DoLoadPackage(std::string libname,
104 #if defined(__GNUC__)
107 handler = dlopen(libname.c_str(),
108 BBTK_RTLD_TIME | BBTK_RTLD_SCOPE );
111 // The following is *NOT* a debug time message :
112 // It's a user intended message.
113 // Please don't remove it.
114 bbtkError("Could not open shared library [" <<libname<<"] : "
115 <<dlerror() << std::endl);
117 return false; // try next path
120 // The following is *NOT* a debug time message :
121 // It's a user intended message.
122 // Please don't remove it.
123 bbtkMessage("Output",2," -->[" <<libname<<"] found" << std::endl);
125 // Loads the Package accessor
127 std::string getpackname(pkgname);
128 getpackname += "GetPackage";
129 void *getpack = dlsym(handler, getpackname.c_str());
133 bbtkError("Shared library ["<<libname<<"] is not a valid bbtk package."
134 <<" Symbol ["<<getpackname<<"] :"<<dlerror());
137 // Verifies that the Package delete function is present
138 std::string delfname(pkgname);
139 delfname += "DeletePackage";
140 void *delf = dlsym(handler, delfname.c_str());
144 bbtkError("Shared library ["<<libname<<"] is not a valid bbtk package."
145 <<" Symbol ["<<delfname<<"] :"<<dlerror());
148 #elif defined(_WIN32)
153 handler = LoadLibrary(libname.c_str());
156 // The following is *NOT* a debug time message :
157 // It's a user intended message.
158 // Please don't remove it.
159 bbtkError("Error loading library [" <<libname<<"]" << std::endl);
160 return false;// Problem with the found library
163 bbtkMessage("Output",2," --->[" <<libname<<"] found" << std::endl);
165 // Loads the Package accessor
167 std::string getpackname(pkgname);
168 getpackname += "GetPackage";
169 void *getpack = GetProcAddress(handler, getpackname.c_str());
172 FreeLibrary(handler);
173 bbtkError("[1] Could not load package \""<<pkgname
174 <<"\" : "<<getpackname<<" symbol not found (is it a bbtk package lib ?)");
175 // look how to get the error message on win
178 // Verifies that the Package delete function is present
179 std::string delfname(pkgname);
180 delfname += "DeletePackage";
181 void *delf = GetProcAddress(handler, delfname.c_str());
184 FreeLibrary(handler);
185 bbtkError("[2] Could not load package \""<<pkgname
186 <<"\" : "<<delfname<<" symbol not found (is it a bbtk package lib ?)");
187 // look how to get the error message on win
191 bbtkError("neither __GNUC__ nor _WIN32 ?!? How did you compile ?");
194 // Stores the package
195 PackageInfoType pack;
196 pack.mDynamicLibraryHandler = handler;
197 // Invokes the accessor to the PackageUnit pointer
198 pack.mPackage = ((PackageAccessor)getpack)();
200 // Test bbtk build version ok
201 if ( pack.mPackage->GetBBTKVersion() != bbtk::GetVersion() )
203 std::string v(pack.mPackage->GetBBTKVersion());
204 UnLoadPackage(pkgname);
205 bbtkError("Cannot load package ["<<libname<<"]. "
206 <<"Package build with bbtk version "
208 << " whereas application build with version "
209 << bbtk::GetVersion());
212 pack.mPackage->AddFactory(this);
213 mPackageMap[pkgname] = pack;
215 std::string separator =
216 ConfigurationFile::GetInstance().Get_file_separator ();
217 //BBTK_STRINGIFY_SYMBOL(BBTK_DOC_REL_PATH)
218 std::string docreldoc =
219 separator + "bbdoc" + separator + pkgname + separator + "index.html";
221 ".." + separator + ".." + docreldoc;
222 std::string doc = path + separator + ".." + separator
223 + BBTK_STRINGIFY_SYMBOL(BBTK_DOC_REL_PATH)
226 pack.mPackage->SetDocURL(doc);
227 pack.mPackage->SetDocRelativeURL(reldoc);
229 //===================================================================
230 bbtkMessage("Output",2,pack.mPackage->GetName()<<" "
231 <<pack.mPackage->GetVersion()
233 <<pack.mPackage->GetBBTKVersion()<<") "
234 <<pack.mPackage->GetAuthor() << " Category(s) :"
235 <<pack.mPackage->GetCategory()
237 bbtkMessage("Output",2,pack.mPackage->GetDescription()<<std::endl);
238 //===================================================================
240 bbtkDebugDecTab("Kernel",7);
244 //===================================================================
245 /// \brief Loads a package.
247 /// The name is the system-independant name of the package (the name of the instance of bbtk::Package).
248 /// Tries to open the dynamic library :
249 /// - "libbb<name>.so" for linux systems,
250 /// - "bb<name>.dll" for windows systems.
251 /// If it succeeds, then tries to load the symbols "<name>GetPackage" and "<name>DeletePackage".
252 /// "<name>GetPackage" is called to get the pointer on the bbtk::Package of the library
253 /// ("<name>DeletePackage" is not used, its presence is just checked before loading the package).
255 /// now, filename is only the last name (no longer the full name!)
256 /// it will be searched within *all* the paths given in bbtk_config.xml
260 void Factory::LoadPackage( const std::string& name )
262 // Note : in the following :
263 // name : the user supplied name
264 // - abreviated name e.g. pkg pkg.so libbpkg libbbpkg.so
265 // - relative full name e.g. ./libbbpkg.so ../../libbbpkg.so
266 // - absolute full name e.g. /home/usrname/proj/lib/libbbpkg.so
267 // same for Windows, with c:, d: ...
269 // lastname : string before the last / (if any), or user supplied name
271 bbtkDebugMessageInc("Kernel",7,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
272 bbtkMessage("Debug",1,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
274 std::vector<std::string> package_paths;
275 std::string libname; // full path library name
276 std::string pkgname; // e.g. libbb<pkgname>.so
279 pkgname = Utilities::ExtractPackageName(name,upath);
281 bbtkMessage("Debug",1,"Package name ["<<pkgname<<"]"<<std::endl);
282 bbtkMessage("Debug",1,"Package path ["<<upath<<"]"<<std::endl);
284 // no loading package if already loaded
285 PackageMapType::iterator iUnload;
286 iUnload = mPackageMap.find(pkgname);
287 if (iUnload != mPackageMap.end())
289 bbtkMessage("Output",2,"["<< pkgname <<"] already loaded" << std::endl);
293 // =================================================
294 // The following structure was checked to work
295 // with any type of relative/absolute path.
296 // Please don't modify it without checking
297 // *all* the cases. JP
298 //==================================================
300 //std::cout << "upath [" << upath << "]" << std::endl;
303 bool foundFile = false;
305 // If path provided by user will be the first scanned :
306 // push it into vector of paths
307 if (upath.length()>0) // ------------------------------------- check user supplied location
309 if (name[0] != '.' && name[0] != '/' && name[1]!= ':')
311 bbtkError("Use absolute or relative path name! ["<<name<<"] is an illegal name");
315 // std::string path = Utilities::ExpandLibName(upath, false);
316 std::string path = Utilities::ExpandLibName(name,false); // keep last item, here.
321 Utilities::ExtractPackageName(path,p2);
322 //libname = Utilities::MakeLibnameFromPath(path, pkgname);
323 libname = Utilities::MakeLibnameFromPath(p2, pkgname); // remove last item
324 // Check if library exists
325 if ( !Utilities::FileExists(libname) )
327 // The following is *NOT* a debug time message :
328 // It's a user intended message.
329 // Please don't remove it.
330 bbtkMessage("Output",3," [" <<libname
331 <<"] : doesn't exist" <<std::endl);
335 ok = DoLoadPackage( libname, pkgname, path);
340 bbtkError("Path ["<<upath<<"] doesn't exist");
344 else // ----------------------------------------------------- iterate on the paths
348 package_paths = ConfigurationFile::GetInstance().Get_package_paths();
349 std::vector<std::string>::iterator i;
350 for (i=package_paths.begin();i!=package_paths.end();++i)
355 // we *really* want '.' to be the current working directory
358 char buf[2048]; // for getcwd
359 char * currentDir = getcwd(buf, 2048);
360 std::string cwd(currentDir);
364 libname = Utilities::MakeLibnameFromPath(path, pkgname);
366 bbtkMessage("Debug",2,"-> Trying to load [" << libname << "]" <<std::endl);
368 // Check if library exists
369 if ( !Utilities::FileExists(libname) )
371 // The following is *NOT* a debug time message :
372 // It's a user intended message.
373 // Please don't remove it.
374 bbtkMessage("Output",3,
375 " [" <<libname <<"] : doesn't exist" <<std::endl);
376 continue; // try next path
380 // Try to Load the library
382 ok = DoLoadPackage( libname, pkgname, path);
385 bbtkMessage("Debug",2," OK"<<std::endl);
386 break; // a package was found; we stop iterating
388 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
392 if( !ok ) // nothing was loaded
396 bbtkError("Could not find package ["<<pkgname<< "]");
400 #if defined(__GNUC__)
401 bbtkError("Could not load package ["<< pkgname
402 <<"] :" << std::endl << " " << dlerror());
403 #elif defined(_WIN32)
404 bbtkError("Could not load package ["<<pkgname
405 <<"] : " << std::endl << " " <<libname<<" not found");
407 // look how to get the error message on win
409 // it is the bordel !! (the bloody fucking bordel, you mean?)
410 // look : http://msdn2.microsoft.com/en-us/library/ms680582.aspx
414 bbtkMessage("Output",2,"[" << libname << "] loaded" << std::endl);
418 //===================================================================
419 /// \brief UnLoads a package.
421 /// The package must have been previously loaded by LoadPackage.
422 /// If the entry is found in the map, calls ClosePackage
423 void Factory::UnLoadPackage( const std::string& name )
425 bbtkDebugMessageInc("Kernel",7,"Factory::UnLoadPackage(\""
426 <<name<<"\")"<<std::endl);
428 PackageMapType::iterator i;
429 i = mPackageMap.find(name);
430 if (i == mPackageMap.end())
432 bbtkError("cannot unload package \""<<name
433 <<"\" : package not loaded !");
436 bbtkDebugDecTab("Kernel",7);
438 //===================================================================
441 //===================================================================
442 /// \brief Close the package referenced by the iterator
444 /// First removes the factory from the set of factories which use the package
445 /// If the set is empty then :
446 /// If it is a dynamically loaded package :
447 /// - Loads and calls the function "<name>DeletePackage" of the dynamic library (responsible for package desallocation)
448 /// - Closes the dynamic library
450 /// - deletes the package normally
452 /// Finally erases the package entry in the packages map
453 void Factory::ClosePackage(PackageMapType::iterator& i)
455 bbtkDebugMessageInc("Kernel",7,"Factory::ClosePackage(\""
456 <<i->second.mPackage->GetName()
460 // Removes this from the set of factories which use the package
461 i->second.mPackage->RemoveFactory(this);
463 // If no more factory which use it
464 if (i->second.mPackage->GetFactorySet().empty())
466 // If it is a dynamically loaded package
467 if (i->second.mDynamicLibraryHandler)
471 // Loads the Package delete function
473 std::string delfname(i->second.mPackage->GetName());
474 delfname += "DeletePackage";
475 #if defined(__GNUC__)
476 void *delf = dlsym(i->second.mDynamicLibraryHandler, delfname.c_str());
479 bbtkError("could not close package \""
480 <<i->second.mPackage->GetName()
481 <<"\" :"<<dlerror());
483 #elif defined(_WIN32)
484 void *delf = GetProcAddress(i->second.mDynamicLibraryHandler,
488 bbtkError("could not close package \""
489 <<i->second.mPackage->GetName()
491 <<" symbol not found (how did you open it ???");
492 //<<"\" :"<<dlerror());
496 // deletes the package
497 ((PackageDeleteFunction)delf)();
499 // closes the dl handler
500 #if defined(__GNUC__)
501 dlclose(i->second.mDynamicLibraryHandler);
502 #elif defined(_WIN32)
504 FreeLibrary(i->second.mDynamicLibraryHandler);
510 // If it is a manually inserted package : delete it normally
511 delete i->second.mPackage;
515 // in any cases remove the entry in the map
516 mPackageMap.erase(i);
518 bbtkDebugDecTab("Kernel",7);
520 //===================================================================
524 //===================================================================
525 /// Displays the list of packages loaded
526 void Factory::PrintPackages(bool details, bool adaptors) const
528 bbtkDebugMessageInc("Kernel",9,"Factory::PrintPackages"<<std::endl);
530 PackageMapType::const_iterator i;
531 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
533 bbtkMessage("Help",1, i->first << std::endl);
535 i->second.mPackage->PrintBlackBoxes(false,adaptors);
539 bbtkDebugDecTab("Kernel",9);
541 //===================================================================
543 //===================================================================
544 /// Displays help on a package
545 void Factory::HelpPackage(const std::string& name, bool adaptors) const
547 bbtkDebugMessageInc("Kernel",9,"Factory::HelpPackage(\""<<name<<"\")"
550 PackageMapType::const_iterator i = mPackageMap.find(name);
551 if ( i != mPackageMap.end() )
553 bbtkMessage("Help",1, "Package "<<i->first<<" ");
555 if (i->second.mPackage->GetVersion().length()>0)
556 bbtkMessageCont("Help",1,"v" <<i->second.mPackage->GetVersion());
558 if (i->second.mPackage->GetAuthor().length()>0)
559 bbtkMessageCont("Help",1,"- "<<i->second.mPackage->GetAuthor());
561 if (i->second.mPackage->GetCategory().length()>0)
562 bbtkMessageCont("Help",1,"- "<<i->second.mPackage->GetCategory());
564 bbtkMessageCont("Help",1,std::endl);
565 bbtkIncTab("Help",1);
566 bbtkMessage("Help",1,i->second.mPackage->GetDescription()<<std::endl);
567 if (i->second.mPackage->GetNumberOfBlackBoxes()>0)
569 bbtkMessage("Help",1, "Black boxes : "<<std::endl);
570 i->second.mPackage->PrintBlackBoxes(true,adaptors);
574 bbtkMessage("Help",1, "No black boxes"<<std::endl);
576 bbtkDecTab("Help",1);
580 bbtkDebugDecTab("Kernel",9);
581 bbtkError("package \""<<name<<"\" unknown");
584 bbtkDebugDecTab("Kernel",9);
586 //===================================================================
588 //===================================================================
589 /// Prints help on the black box of type <name>
590 /// Returns the package to which it belongs
591 void Factory::HelpBlackBox(const std::string& name,
592 std::string& package,
595 bbtkDebugMessageInc("Kernel",9,"Factory::HelpBlackBox(\""<<name<<"\")"
599 PackageMapType::const_iterator i;
600 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
602 if (i->second.mPackage->ContainsBlackBox(name))
604 i->second.mPackage->HelpBlackBox(name,full);
605 package = i->second.mPackage->GetName();
610 bbtkDebugDecTab("Kernel",9);
613 bbtkError("No package of the factory contains any black box <"
617 //===================================================================
620 //===================================================================
621 /// Inserts a package in the factory
622 void Factory::InsertPackage( Package* p )
624 bbtkDebugMessageInc("Kernel",9,"Factory::InsertPackage(\""<<
625 p->GetName()<<"\")"<<std::endl);
628 PackageInfoType pack;
629 pack.mDynamicLibraryHandler = 0;
631 mPackageMap[p->GetName()] = pack;
633 bbtkDebugDecTab("Kernel",9);
635 //===================================================================
637 //===================================================================
638 /// Removes a package from the factory (and deletes it)
639 void Factory::RemovePackage( Package* p )
641 bbtkDebugMessageInc("Kernel",9,"Factory::RemovePackage(\""<<
642 p->GetName()<<"\")"<<std::endl);
644 PackageMapType::iterator i;
645 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
647 if (i->second.mPackage == p) break;
650 if (i!=mPackageMap.end())
656 bbtkError("Factory::RemovePackage(\""<<
657 p->GetName()<<"\") : package absent from factory");
660 bbtkDebugDecTab("Kernel",9);
662 //===================================================================
665 //===================================================================
666 /// Creates an instance of a black box of type <type> with name <name>
667 BlackBox* Factory::NewBlackBox(const std::string& type,
668 const std::string& name) const
670 bbtkDebugMessageInc("Kernel",7,"Factory::NewBlackBox(\""
671 <<type<<"\",\""<<name<<"\")"<<std::endl);
674 PackageMapType::const_iterator i;
675 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
677 b = i->second.mPackage->NewBlackBox(type,name);
682 bbtkError("black box type \""<<type<<"\" unknown");
685 bbtkDebugDecTab("Kernel",7);
688 //===================================================================
690 //===================================================================
691 /// Creates an instance of a black box of type <type> with name <name>
692 BlackBox* Factory::NewAdaptor(TypeInfo typein,
694 const std::string& name) const
696 bbtkDebugMessageInc("Kernel",8,"Factory::NewAdaptor(<"
697 <<TypeName(typein)<<">,<"
698 <<TypeName(typeout)<<">,\""
699 <<name<<"\")"<<bbtkendl);
703 PackageMapType::const_iterator i;
704 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
706 b = i->second.mPackage->NewAdaptor(typein,typeout,name);
712 <<TypeName(typein)<<"> to <"
714 <<"> adaptor available");
717 bbtkDebugDecTab("Kernel",7);
720 //===================================================================
722 //===================================================================
723 /// Creates an instance of a connection
724 Connection* Factory::NewConnection(BlackBox* from,
725 const std::string& output,
727 const std::string& input) const
729 bbtkDebugMessage("Kernel",7,"Factory::NewConnection(\""
730 <<from->bbGetName()<<"\",\""<<output<<"\",\""
731 <<to->bbGetName()<<"\",\""<<input
734 return new Connection(from,output,to,input,this);
736 //===================================================================
740 //===================================================================
741 const Package* Factory::GetPackage(const std::string& name) const
743 bbtkDebugMessageInc("Kernel",9,"Factory::GetPackage(\""<<name<<"\")"
746 PackageMapType::const_iterator i = mPackageMap.find(name);
747 if ( i != mPackageMap.end() )
749 bbtkDebugDecTab("Kernel",9);
750 return i->second.mPackage;
754 bbtkDebugDecTab("Kernel",9);
755 bbtkError("package \""<<name<<"\" unknown");
758 bbtkDebugDecTab("Kernel",9);
760 //===================================================================
762 //===================================================================
763 Package* Factory::GetPackage(const std::string& name)
765 bbtkDebugMessageInc("Kernel",9,"Factory::GetPackage(\""<<name<<"\")"
768 PackageMapType::const_iterator i = mPackageMap.find(name);
769 if ( i != mPackageMap.end() )
771 bbtkDebugDecTab("Kernel",9);
772 return i->second.mPackage;
776 bbtkDebugDecTab("Kernel",9);
777 bbtkError("package \""<<name<<"\" unknown");
780 bbtkDebugDecTab("Kernel",9);
782 //===================================================================
784 //===================================================================
785 void Factory::WriteDotFilePackagesList(FILE *ff)
788 bbtkDebugMessageInc("Kernel",9,"Factory::WriteDotFilePackagesList()"
792 fprintf( ff , "subgraph cluster_FACTORY {\n");
793 fprintf( ff , " label = \"PACKAGES\"%s\n", ";");
794 fprintf( ff , " style=filled%s\n",";");
795 fprintf( ff , " color=lightgrey%s\n",";");
796 fprintf( ff , " rankdir=TB%s\n",";");
799 PackageMapType::const_iterator i;
800 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
802 url=GetPackage(i->first)->GetDocURL();
803 fprintf(ff," %s [shape=ellipse, URL=\"%s\"]%s\n",i->first.c_str(),url.c_str(),";" );
805 fprintf( ff , "}\n\n");
806 bbtkDebugDecTab("Kernel",9);
808 //===================================================================
811 void Factory::ShowGraphTypes(const std::string& name) const
815 PackageMapType::const_iterator i;
816 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
818 if (i->second.mPackage->ContainsBlackBox(name))
820 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
822 // Don't pollute the file store with "temp_dir" directories ...
823 std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
824 std::string directory = "\"" + default_doc_dir + separator + "temp_dir" +separator + "\"";
825 std::string filename2 = default_doc_dir + separator + "temp_dir" + separator + "tmp.html";
828 std::string command("start \"Titre\" /D ");
830 std::string command("gnome-open ");
832 command=command + directory +" tmp.html";
834 ff=fopen(filename2.c_str(),"w");
836 fprintf(ff,"<html><head><title>TMP</title> <script type=\"text/javascript\"> <!--\n");
837 fprintf(ff," window.location=\"%s#%s\";\n" , i->second.mPackage->GetDocURL().c_str(),name.c_str() );
838 fprintf(ff,"//--></script></head><body></body></html>\n");
841 //fprintf(ff, "<a href=\"%s#%s\">Link</a>\n", i->second.mPackage->GetDocURL().c_str(),name.c_str() );
843 system( command.c_str() );
848 bbtkDebugDecTab("Kernel",9);
851 bbtkError("No package of the factory contains any black box <"
859 void Factory::CreateHtmlIndex(IndexEntryType type,
860 const std::string& filename)
862 bbtkDebugMessageInc("Kernel",9,"Factory::CreateHtmlIndex(\""
863 <<filename<<"\")"<<bbtkendl);
867 typedef std::map<std::string, std::vector<BlackBoxDescriptor*> > IndexType;
869 // Builds the index map
870 PackageMapType::const_iterator i;
871 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
873 Package* pack = i->second.mPackage;
874 if (pack->GetName()=="user") continue;
875 Package::BlackBoxMapType::const_iterator j;
876 for (j = pack->GetBlackBoxMap().begin();
877 j!= pack->GetBlackBoxMap().end();
882 if ( type==Adaptors )
884 if (j->second->GetKind() == BlackBoxDescriptor::STANDARD )
888 if (j->second->GetKind() != BlackBoxDescriptor::STANDARD )
891 std::vector<std::string> keys;
895 k += pack->GetName();
897 title = "Boxes by package";
899 else if ((type==Initials) || (type==Adaptors))
901 std::string init(" ");
902 init[0] = std::toupper(j->second->GetTypeName()[0]);
903 keys.push_back(init);
904 title = "Alphabetical list";
906 else if (type==Categories)
908 // Split the category string
909 std::string delimiters = ";,";
910 Utilities::SplitString(j->second->GetCategory(),
913 keys.push_back(" NONE");
914 title = "Boxes by category";
918 std::vector<std::string>::const_iterator k;
919 for (k=keys.begin(); k!=keys.end(); ++k )
921 IndexType::iterator p;
923 if (p != index.end())
925 p->second.push_back(j->second);
929 std::vector<BlackBoxDescriptor*> v;
930 v.push_back(j->second);
938 //---------------------
941 s.open(filename.c_str());
944 bbtkError("Factory::CreateHtmlIndex : could not open file '"
948 //----------------------
950 s << "<html lang=\"en\">\n";
952 s << "<title>"<<title<<"</title>\n";
953 s << "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n";
954 s << "<meta name=\"description\" content=\""<<title<<"\">\n";
955 s << "<meta name=\"generator\" content=\"\">\n";
956 s << "<link title=\"Top\" rel=\"top\" href=\"#Top\">\n";
957 //<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
958 s << "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><style type=\"text/css\"><!--\n";
959 s << "pre.display { font-family:inherit }\n";
960 s << "pre.format { font-family:inherit }\n";
961 s << "pre.smalldisplay { font-family:inherit; font-size:smaller }\n";
962 s << "pre.smallformat { font-family:inherit; font-size:smaller }\n";
963 s << "pre.smallexample { font-size:smaller }\n";
964 s << "pre.smalllisp { font-size:smaller }\n";
965 s << "span.sc { font-variant:small-caps }\n";
966 s << "span.roman { font-family:serif; font-weight:normal; } \n";
967 s << "span.sansserif { font-family:sans-serif; font-weight:normal; }\n";
968 s << "--></style>\n";
970 //----------------------
972 //----------------------
975 s << "<a name=\"Top\"></a>\n";
976 s << "<h1 class=\"settitle\">"<<title<<"</h1>\n";
978 IndexType::iterator ii;
979 for (ii=index.begin();ii!=index.end();++ii)
981 s << "<a href=\"#"<<ii->first<<"\">"<<ii->first<<"</a> ";
984 for (ii=index.begin();ii!=index.end();++ii)
987 s << "<p><a href=\"#Top\">Top</a>";
990 s << "<a name=\""<<ii->first<<"\"></a>\n";
991 s << "<p><a href=\""<<ii->first<<"/index.html\">"
992 << ii->first<<"</a>\n";
994 s << " - \n";
996 s << "<a name=\"doxygen\"></a>\n";
997 s << "<a href=..\\doxygen\\" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1001 s << "<a name=\""<<ii->first<<"\"></a>\n";
1002 s << "<p><b>"<<ii->first<<"</b>\n";
1006 s << "<p><TABLE cellspacing=0 cellpadding=3>\n";
1008 std::vector<BlackBoxDescriptor*>::iterator di;
1009 for (di=ii->second.begin();di!=ii->second.end();++di)
1011 std::string pack = (*di)->GetPackage()->GetName();
1012 std::string name = (*di)->GetTypeName();
1013 Utilities::html_format(name);
1014 std::string descr = (*di)->GetDescription();
1015 Utilities::html_format(descr);
1017 s << "<TD style='vertical-align: top;'>";
1018 s << " <a href=\""<<pack
1019 <<"/index.html#"<<name<<"\">"
1020 <<pack<<"::"<<name<<"</a>";
1022 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1029 //----------------------
1034 ptm = gmtime ( &rawtime );
1037 s << "Automatically generated by <b>bbi</b> on "
1038 << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900
1039 << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n";
1040 s << "</body></html>\n";
1042 //----------------------
1045 bbtkDebugDecTab("Kernel",9);