1 /*=========================================================================
4 Module: $RCSfile: bbtkFactory.cxx,v $
7 Date: $Date: 2008/03/07 08:40:14 $
8 Version: $Revision: 1.27 $
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 //===================================================================
83 bbtkDebugMessageInc("Kernel",7,"Factory::Reset()"<<std::endl);
85 bbtkDebugDecTab("Kernel",7);
87 //===================================================================
90 // ===================================================================
91 bool Factory::DoLoadPackage(std::string libname,
99 handler = dlopen(libname.c_str(),
100 BBTK_RTLD_TIME | BBTK_RTLD_SCOPE );
103 // The following is *NOT* a debug time message :
104 // It's a user intended message.
105 // Please don't remove it.
106 bbtkError("Could not open shared library [" <<libname<<"] : "
107 <<dlerror() << std::endl);
109 return false; // try next path
112 // The following is *NOT* a debug time message :
113 // It's a user intended message.
114 // Please don't remove it.
115 bbtkMessage("Output",2," -->[" <<libname<<"] found" << std::endl);
117 // Loads the Package accessor
119 std::string getpackname(pkgname);
120 getpackname += "GetPackage";
121 void *getpack = dlsym(handler, getpackname.c_str());
125 bbtkError("Shared library ["<<libname<<"] is not a valid bbtk package."
126 <<" Symbol ["<<getpackname<<"] :"<<dlerror());
129 // Verifies that the Package delete function is present
130 std::string delfname(pkgname);
131 delfname += "DeletePackage";
132 void *delf = dlsym(handler, delfname.c_str());
136 bbtkError("Shared library ["<<libname<<"] is not a valid bbtk package."
137 <<" Symbol ["<<delfname<<"] :"<<dlerror());
140 #elif defined(_WIN32)
145 handler = LoadLibrary(libname.c_str());
148 // The following is *NOT* a debug time message :
149 // It's a user intended message.
150 // Please don't remove it.
151 bbtkError("Error loading library [" <<libname<<"]" << std::endl);
152 return false;// Problem with the found library
155 bbtkMessage("Output",2," --->[" <<libname<<"] found" << std::endl);
157 // Loads the Package accessor
159 std::string getpackname(pkgname);
160 getpackname += "GetPackage";
161 void *getpack = GetProcAddress(handler, getpackname.c_str());
164 FreeLibrary(handler);
165 bbtkError("[1] Could not load package \""<<pkgname
166 <<"\" : "<<getpackname<<" symbol not found (is it a bbtk package lib ?)");
167 // look how to get the error message on win
170 // Verifies that the Package delete function is present
171 std::string delfname(pkgname);
172 delfname += "DeletePackage";
173 void *delf = GetProcAddress(handler, delfname.c_str());
176 FreeLibrary(handler);
177 bbtkError("[2] Could not load package \""<<pkgname
178 <<"\" : "<<delfname<<" symbol not found (is it a bbtk package lib ?)");
179 // look how to get the error message on win
183 bbtkError("neither __GNUC__ nor _WIN32 ?!? How did you compile ?");
186 // Stores the package
187 PackageInfoType pack;
188 pack.mDynamicLibraryHandler = handler;
189 // Invokes the accessor to the PackageUnit pointer
190 pack.mPackage = ((PackageAccessor)getpack)();
192 // Test bbtk build version ok
193 if ( pack.mPackage->GetBBTKVersion() != bbtk::GetVersion() )
195 std::string v(pack.mPackage->GetBBTKVersion());
196 UnLoadPackage(pkgname);
197 bbtkError("Cannot load package ["<<libname<<"]. "
198 <<"Package build with bbtk version "
200 << " whereas application build with version "
201 << bbtk::GetVersion());
204 pack.mPackage->AddFactory(this);
205 mPackageMap[pkgname] = pack;
207 std::string separator =
208 ConfigurationFile::GetInstance().Get_file_separator ();
209 //BBTK_STRINGIFY_SYMBOL(BBTK_DOC_REL_PATH)
210 std::string docreldoc =
211 separator + "bbdoc" + separator + pkgname + separator + "index.html";
213 ".." + separator + ".." + docreldoc;
214 std::string doc = path + separator + ".." + separator
215 + BBTK_STRINGIFY_SYMBOL(BBTK_DOC_REL_PATH)
218 pack.mPackage->SetDocURL(doc);
219 pack.mPackage->SetDocRelativeURL(reldoc);
221 //===================================================================
222 bbtkMessage("Output",2,pack.mPackage->GetName()<<" "
223 <<pack.mPackage->GetVersion()
225 <<pack.mPackage->GetBBTKVersion()<<") "
226 <<pack.mPackage->GetAuthor() << " Category(s) :"
227 <<pack.mPackage->GetCategory()
229 bbtkMessage("Output",2,pack.mPackage->GetDescription()<<std::endl);
230 //===================================================================
232 bbtkDebugDecTab("Kernel",7);
236 //===================================================================
237 /// \brief Loads a package.
239 /// The name is the system-independant name of the package (the name of the instance of bbtk::Package).
240 /// Tries to open the dynamic library :
241 /// - "libbb<name>.so" for linux systems,
242 /// - "bb<name>.dll" for windows systems.
243 /// If it succeeds, then tries to load the symbols "<name>GetPackage" and "<name>DeletePackage".
244 /// "<name>GetPackage" is called to get the pointer on the bbtk::Package of the library
245 /// ("<name>DeletePackage" is not used, its presence is just checked before loading the package).
247 /// now, filename is only the last name (no longer the full name!)
248 /// it will be searched within *all* the paths given in bbtk_config.xml
252 void Factory::LoadPackage( const std::string& name )
254 // Note : in the following :
255 // name : the user supplied name
256 // - abreviated name e.g. pkg pkg.so libbpkg libbbpkg.so
257 // - relative full name e.g. ./libbbpkg.so ../../libbbpkg.so
258 // - absolute full name e.g. /home/usrname/proj/lib/libbbpkg.so
259 // same for Windows, with c:, d: ...
261 // lastname : string before the last / (if any), or user supplied name
263 bbtkDebugMessageInc("Kernel",7,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
264 bbtkMessage("Debug",1,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
266 std::vector<std::string> package_paths;
267 std::string libname; // full path library name
268 std::string pkgname; // e.g. libbb<pkgname>.so
271 pkgname = Utilities::ExtractPackageName(name,upath);
273 bbtkMessage("Debug",1,"Package name ["<<pkgname<<"]"<<std::endl);
274 bbtkMessage("Debug",1,"Package path ["<<upath<<"]"<<std::endl);
276 // no loading package if already loaded
277 PackageMapType::iterator iUnload;
278 iUnload = mPackageMap.find(pkgname);
279 if (iUnload != mPackageMap.end())
281 bbtkMessage("Output",2,"["<< pkgname <<"] already loaded" << std::endl);
285 // =================================================
286 // The following structure was checked to work
287 // with any type of relative/absolute path.
288 // Please don't modify it without checking
289 // *all* the cases. JP
290 //==================================================
292 //std::cout << "upath [" << upath << "]" << std::endl;
295 bool foundFile = false;
297 // If path provided by user will be the first scanned :
298 // push it into vector of paths
299 if (upath.length()>0) // ------------------------------------- check user supplied location
301 if (name[0] != '.' && name[0] != '/' && name[1]!= ':')
303 bbtkError("Use absolute or relative path name! ["<<name<<"] is an illegal name");
307 // std::string path = Utilities::ExpandLibName(upath, false);
308 std::string path = Utilities::ExpandLibName(name,false); // keep last item, here.
313 Utilities::ExtractPackageName(path,p2);
314 //libname = Utilities::MakeLibnameFromPath(path, pkgname);
315 libname = Utilities::MakeLibnameFromPath(p2, pkgname); // remove last item
316 // Check if library exists
317 if ( !Utilities::FileExists(libname) )
319 // The following is *NOT* a debug time message :
320 // It's a user intended message.
321 // Please don't remove it.
322 bbtkMessage("Output",3," [" <<libname
323 <<"] : doesn't exist" <<std::endl);
327 ok = DoLoadPackage( libname, pkgname, path);
332 bbtkError("Path ["<<upath<<"] doesn't exist");
336 else // ----------------------------------------------------- iterate on the paths
340 package_paths = ConfigurationFile::GetInstance().Get_package_paths();
341 std::vector<std::string>::iterator i;
342 for (i=package_paths.begin();i!=package_paths.end();++i)
347 // we *really* want '.' to be the current working directory
350 char buf[2048]; // for getcwd
351 char * currentDir = getcwd(buf, 2048);
352 std::string cwd(currentDir);
356 libname = Utilities::MakeLibnameFromPath(path, pkgname);
358 bbtkMessage("Debug",2,"-> Trying to load [" << libname << "]" <<std::endl);
360 // Check if library exists
361 if ( !Utilities::FileExists(libname) )
363 // The following is *NOT* a debug time message :
364 // It's a user intended message.
365 // Please don't remove it.
366 bbtkMessage("Output",3,
367 " [" <<libname <<"] : doesn't exist" <<std::endl);
368 continue; // try next path
372 // Try to Load the library
374 ok = DoLoadPackage( libname, pkgname, path);
377 bbtkMessage("Debug",2," OK"<<std::endl);
378 break; // a package was found; we stop iterating
380 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
384 if( !ok ) // nothing was loaded
388 bbtkError("Could not find package ["<<pkgname<< "]");
392 #if defined(__GNUC__)
393 bbtkError("Could not load package ["<< pkgname
394 <<"] :" << std::endl << " " << dlerror());
395 #elif defined(_WIN32)
396 bbtkError("Could not load package ["<<pkgname
397 <<"] : " << std::endl << " " <<libname<<" not found");
399 // look how to get the error message on win
401 // it is the bordel !! (the bloody fucking bordel, you mean?)
402 // look : http://msdn2.microsoft.com/en-us/library/ms680582.aspx
406 bbtkMessage("Output",2,"[" << libname << "] loaded" << std::endl);
410 //===================================================================
411 /// \brief UnLoads a package.
413 /// The package must have been previously loaded by LoadPackage.
414 /// If the entry is found in the map, calls ClosePackage
415 void Factory::UnLoadPackage( const std::string& name )
417 bbtkDebugMessageInc("Kernel",7,"Factory::UnLoadPackage(\""
418 <<name<<"\")"<<std::endl);
420 PackageMapType::iterator i;
421 i = mPackageMap.find(name);
422 if (i == mPackageMap.end())
424 bbtkError("cannot unload package \""<<name
425 <<"\" : package not loaded !");
428 bbtkDebugDecTab("Kernel",7);
430 //===================================================================
433 //===================================================================
434 /// \brief Close the package referenced by the iterator
436 /// First removes the factory from the set of factories which use the package
437 /// If the set is empty then :
438 /// If it is a dynamically loaded package :
439 /// - Loads and calls the function "<name>DeletePackage" of the dynamic library (responsible for package desallocation)
440 /// - Closes the dynamic library
442 /// - deletes the package normally
444 /// Finally erases the package entry in the packages map
445 void Factory::ClosePackage(PackageMapType::iterator& i)
447 bbtkDebugMessageInc("Kernel",7,"Factory::ClosePackage(\""
448 <<i->second.mPackage->GetName()
452 // Removes this from the set of factories which use the package
453 i->second.mPackage->RemoveFactory(this);
455 // If no more factory which use it
456 if (i->second.mPackage->GetFactorySet().empty())
458 // If it is a dynamically loaded package
459 if (i->second.mDynamicLibraryHandler)
463 // Loads the Package delete function
465 std::string delfname(i->second.mPackage->GetName());
466 delfname += "DeletePackage";
467 #if defined(__GNUC__)
468 void *delf = dlsym(i->second.mDynamicLibraryHandler, delfname.c_str());
471 bbtkError("could not close package \""
472 <<i->second.mPackage->GetName()
473 <<"\" :"<<dlerror());
475 #elif defined(_WIN32)
476 void *delf = GetProcAddress(i->second.mDynamicLibraryHandler,
480 bbtkError("could not close package \""
481 <<i->second.mPackage->GetName()
483 <<" symbol not found (how did you open it ???");
484 //<<"\" :"<<dlerror());
488 // deletes the package
489 ((PackageDeleteFunction)delf)();
491 // closes the dl handler
492 #if defined(__GNUC__)
493 dlclose(i->second.mDynamicLibraryHandler);
494 #elif defined(_WIN32)
496 FreeLibrary(i->second.mDynamicLibraryHandler);
502 // If it is a manually inserted package : delete it normally
503 delete i->second.mPackage;
507 // in any cases remove the entry in the map
508 mPackageMap.erase(i);
510 bbtkDebugDecTab("Kernel",7);
512 //===================================================================
516 //===================================================================
517 /// Displays the list of packages loaded
518 void Factory::PrintPackages(bool details, bool adaptors) const
520 bbtkDebugMessageInc("Kernel",9,"Factory::PrintPackages"<<std::endl);
522 PackageMapType::const_iterator i;
523 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
525 bbtkMessage("Help",1, i->first << std::endl);
527 i->second.mPackage->PrintBlackBoxes(false,adaptors);
531 bbtkDebugDecTab("Kernel",9);
533 //===================================================================
535 //===================================================================
536 /// Displays help on a package
537 void Factory::HelpPackage(const std::string& name, bool adaptors) const
539 bbtkDebugMessageInc("Kernel",9,"Factory::HelpPackage(\""<<name<<"\")"
542 PackageMapType::const_iterator i = mPackageMap.find(name);
543 if ( i != mPackageMap.end() )
545 bbtkMessage("Help",1, "Package "<<i->first<<" ");
547 if (i->second.mPackage->GetVersion().length()>0)
548 bbtkMessageCont("Help",1,"v" <<i->second.mPackage->GetVersion());
550 if (i->second.mPackage->GetAuthor().length()>0)
551 bbtkMessageCont("Help",1,"- "<<i->second.mPackage->GetAuthor());
553 if (i->second.mPackage->GetCategory().length()>0)
554 bbtkMessageCont("Help",1,"- "<<i->second.mPackage->GetCategory());
556 bbtkMessageCont("Help",1,std::endl);
557 bbtkIncTab("Help",1);
558 bbtkMessage("Help",1,i->second.mPackage->GetDescription()<<std::endl);
559 if (i->second.mPackage->GetNumberOfBlackBoxes()>0)
561 bbtkMessage("Help",1, "Black boxes : "<<std::endl);
562 i->second.mPackage->PrintBlackBoxes(true,adaptors);
566 bbtkMessage("Help",1, "No black boxes"<<std::endl);
568 bbtkDecTab("Help",1);
572 bbtkDebugDecTab("Kernel",9);
573 bbtkError("package \""<<name<<"\" unknown");
576 bbtkDebugDecTab("Kernel",9);
578 //===================================================================
580 //===================================================================
581 /// Prints help on the black box of type <name>
582 /// Returns the package to which it belongs
583 void Factory::HelpBlackBox(const std::string& name,
584 std::string& package,
587 bbtkDebugMessageInc("Kernel",9,"Factory::HelpBlackBox(\""<<name<<"\")"
591 PackageMapType::const_iterator i;
592 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
594 if (i->second.mPackage->ContainsBlackBox(name))
596 i->second.mPackage->HelpBlackBox(name,full);
597 package = i->second.mPackage->GetName();
602 bbtkDebugDecTab("Kernel",9);
605 bbtkError("No package of the factory contains any black box <"
609 //===================================================================
612 //===================================================================
613 /// Inserts a package in the factory
614 void Factory::InsertPackage( Package* p )
616 bbtkDebugMessageInc("Kernel",9,"Factory::InsertPackage(\""<<
617 p->GetName()<<"\")"<<std::endl);
620 PackageInfoType pack;
621 pack.mDynamicLibraryHandler = 0;
623 mPackageMap[p->GetName()] = pack;
625 bbtkDebugDecTab("Kernel",9);
627 //===================================================================
629 //===================================================================
630 /// Removes a package from the factory (and deletes it)
631 void Factory::RemovePackage( Package* p )
633 bbtkDebugMessageInc("Kernel",9,"Factory::RemovePackage(\""<<
634 p->GetName()<<"\")"<<std::endl);
636 PackageMapType::iterator i;
637 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
639 if (i->second.mPackage == p) break;
642 if (i!=mPackageMap.end())
648 bbtkError("Factory::RemovePackage(\""<<
649 p->GetName()<<"\") : package absent from factory");
652 bbtkDebugDecTab("Kernel",9);
654 //===================================================================
657 //===================================================================
658 /// Creates an instance of a black box of type <type> with name <name>
659 BlackBox* Factory::NewBlackBox(const std::string& type,
660 const std::string& name) const
662 bbtkDebugMessageInc("Kernel",7,"Factory::NewBlackBox(\""
663 <<type<<"\",\""<<name<<"\")"<<std::endl);
666 PackageMapType::const_iterator i;
667 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
669 b = i->second.mPackage->NewBlackBox(type,name);
674 bbtkError("black box type \""<<type<<"\" unknown");
677 bbtkDebugDecTab("Kernel",7);
680 //===================================================================
682 //===================================================================
683 /// Creates an instance of a black box of type <type> with name <name>
684 BlackBox* Factory::NewAdaptor(TypeInfo typein,
686 const std::string& name) const
688 bbtkDebugMessageInc("Kernel",8,"Factory::NewAdaptor(<"
689 <<TypeName(typein)<<">,<"
690 <<TypeName(typeout)<<">,\""
691 <<name<<"\")"<<bbtkendl);
695 PackageMapType::const_iterator i;
696 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
698 b = i->second.mPackage->NewAdaptor(typein,typeout,name);
704 <<TypeName(typein)<<"> to <"
706 <<"> adaptor available");
709 bbtkDebugDecTab("Kernel",7);
712 //===================================================================
714 //===================================================================
715 /// Creates an instance of a connection
716 Connection* Factory::NewConnection(BlackBox* from,
717 const std::string& output,
719 const std::string& input) const
721 bbtkDebugMessage("Kernel",7,"Factory::NewConnection(\""
722 <<from->bbGetName()<<"\",\""<<output<<"\",\""
723 <<to->bbGetName()<<"\",\""<<input
726 return new Connection(from,output,to,input);
729 // !!! WARNING : WE NEED TO TEST THE TYPE NAME EQUALITY
730 // BECAUSE IN DIFFERENT DYN LIBS THE type_info EQUALITY CAN
731 // BE FALSE (DIFFERENT INSTANCES !)
733 std::string t1 ( from->bbGetOutputType(output).name() );
734 std::string t2 ( to->bbGetInputType(input).name() );
738 //from->bbGetOutputType(output) ==
739 // to->bbGetInputType(input) )
741 c = new Connection(from,output,to,input);
745 // std::cout << "Adaptive connection "<<std::endl;
747 name = from->bbGetName() + "." + output + "-"
748 + to->bbGetName() + "." + input;
751 PackageMapType::const_iterator i;
752 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
754 b = i->second.mPackage->NewAdaptor(from->bbGetOutputType(output),
755 to->bbGetInputType(input),
761 bbtkError("did not find any <"
762 <<TypeName(from->bbGetOutputType(output))
764 <<TypeName(to->bbGetInputType(input))
767 c = new AdaptiveConnection(from,output,to,input,b);
769 bbtkDebugDecTab("Kernel",7);
774 //===================================================================
778 //===================================================================
779 const Package* Factory::GetPackage(const std::string& name) const
781 bbtkDebugMessageInc("Kernel",9,"Factory::GetPackage(\""<<name<<"\")"
784 PackageMapType::const_iterator i = mPackageMap.find(name);
785 if ( i != mPackageMap.end() )
787 bbtkDebugDecTab("Kernel",9);
788 return i->second.mPackage;
792 bbtkDebugDecTab("Kernel",9);
793 bbtkError("package \""<<name<<"\" unknown");
796 bbtkDebugDecTab("Kernel",9);
798 //===================================================================
800 //===================================================================
801 Package* Factory::GetPackage(const std::string& name)
803 bbtkDebugMessageInc("Kernel",9,"Factory::GetPackage(\""<<name<<"\")"
806 PackageMapType::const_iterator i = mPackageMap.find(name);
807 if ( i != mPackageMap.end() )
809 bbtkDebugDecTab("Kernel",9);
810 return i->second.mPackage;
814 bbtkDebugDecTab("Kernel",9);
815 bbtkError("package \""<<name<<"\" unknown");
818 bbtkDebugDecTab("Kernel",9);
820 //===================================================================
822 //===================================================================
823 void Factory::WriteDotFilePackagesList(FILE *ff)
826 bbtkDebugMessageInc("Kernel",9,"Factory::WriteDotFilePackagesList()"
830 fprintf( ff , "subgraph cluster_FACTORY {\n");
831 fprintf( ff , " label = \"PACKAGES\"%s\n", ";");
832 fprintf( ff , " style=filled%s\n",";");
833 fprintf( ff , " color=lightgrey%s\n",";");
834 fprintf( ff , " rankdir=TB%s\n",";");
837 PackageMapType::const_iterator i;
838 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
840 url=GetPackage(i->first)->GetDocURL();
841 fprintf(ff," %s [shape=ellipse, URL=\"%s\"]%s\n",i->first.c_str(),url.c_str(),";" );
843 fprintf( ff , "}\n\n");
844 bbtkDebugDecTab("Kernel",9);
846 //===================================================================
849 void Factory::ShowGraphTypes(const std::string& name) const
853 PackageMapType::const_iterator i;
854 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
856 if (i->second.mPackage->ContainsBlackBox(name))
858 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
860 // Don't pollute the file store with "temp_dir" directories ...
861 std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
862 std::string directory = "\"" + default_doc_dir + separator + "temp_dir" +separator + "\"";
863 std::string filename2 = default_doc_dir + separator + "temp_dir" + separator + "tmp.html";
866 std::string command("start \"Titre\" /D ");
868 std::string command("gnome-open ");
870 command=command + directory +" tmp.html";
872 ff=fopen(filename2.c_str(),"w");
874 fprintf(ff,"<html><head><title>TMP</title> <script type=\"text/javascript\"> <!--\n");
875 fprintf(ff," window.location=\"%s#%s\";\n" , i->second.mPackage->GetDocURL().c_str(),name.c_str() );
876 fprintf(ff,"//--></script></head><body></body></html>\n");
879 //fprintf(ff, "<a href=\"%s#%s\">Link</a>\n", i->second.mPackage->GetDocURL().c_str(),name.c_str() );
881 system( command.c_str() );
886 bbtkDebugDecTab("Kernel",9);
889 bbtkError("No package of the factory contains any black box <"
897 void Factory::CreateHtmlIndex(IndexEntryType type,
898 const std::string& filename)
900 bbtkDebugMessageInc("Kernel",9,"Factory::CreateHtmlIndex(\""
901 <<filename<<"\")"<<bbtkendl);
905 typedef std::map<std::string, std::vector<BlackBoxDescriptor*> > IndexType;
907 // Builds the index map
908 PackageMapType::const_iterator i;
909 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
911 Package* pack = i->second.mPackage;
912 if (pack->GetName()=="user") continue;
913 Package::BlackBoxMapType::const_iterator j;
914 for (j = pack->GetBlackBoxMap().begin();
915 j!= pack->GetBlackBoxMap().end();
920 if ( type==Adaptors )
922 if (j->second->GetKind() == BlackBoxDescriptor::STANDARD )
926 if (j->second->GetKind() != BlackBoxDescriptor::STANDARD )
929 std::vector<std::string> keys;
933 k += pack->GetName();
935 title = "Boxes by package";
937 else if ((type==Initials) || (type==Adaptors))
939 std::string init(" ");
940 init[0] = std::toupper(j->second->GetTypeName()[0]);
941 keys.push_back(init);
942 title = "Alphabetical list";
944 else if (type==Categories)
946 // Split the category string
947 std::string delimiters = ";,";
948 Utilities::SplitString(j->second->GetCategory(),
951 keys.push_back(" NONE");
952 title = "Boxes by category";
956 std::vector<std::string>::const_iterator k;
957 for (k=keys.begin(); k!=keys.end(); ++k )
959 IndexType::iterator p;
961 if (p != index.end())
963 p->second.push_back(j->second);
967 std::vector<BlackBoxDescriptor*> v;
968 v.push_back(j->second);
976 //---------------------
979 s.open(filename.c_str());
982 bbtkError("Factory::CreateHtmlIndex : could not open file '"
986 //----------------------
988 s << "<html lang=\"en\">\n";
990 s << "<title>"<<title<<"</title>\n";
991 s << "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n";
992 s << "<meta name=\"description\" content=\""<<title<<"\">\n";
993 s << "<meta name=\"generator\" content=\"\">\n";
994 s << "<link title=\"Top\" rel=\"top\" href=\"#Top\">\n";
995 //<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
996 s << "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><style type=\"text/css\"><!--\n";
997 s << "pre.display { font-family:inherit }\n";
998 s << "pre.format { font-family:inherit }\n";
999 s << "pre.smalldisplay { font-family:inherit; font-size:smaller }\n";
1000 s << "pre.smallformat { font-family:inherit; font-size:smaller }\n";
1001 s << "pre.smallexample { font-size:smaller }\n";
1002 s << "pre.smalllisp { font-size:smaller }\n";
1003 s << "span.sc { font-variant:small-caps }\n";
1004 s << "span.roman { font-family:serif; font-weight:normal; } \n";
1005 s << "span.sansserif { font-family:sans-serif; font-weight:normal; }\n";
1006 s << "--></style>\n";
1008 //----------------------
1010 //----------------------
1013 s << "<a name=\"Top\"></a>\n";
1014 s << "<h1 class=\"settitle\">"<<title<<"</h1>\n";
1016 IndexType::iterator ii;
1017 for (ii=index.begin();ii!=index.end();++ii)
1019 s << "<a href=\"#"<<ii->first<<"\">"<<ii->first<<"</a> ";
1022 for (ii=index.begin();ii!=index.end();++ii)
1025 s << "<p><a href=\"#Top\">Top</a>";
1028 s << "<a name=\""<<ii->first<<"\"></a>\n";
1029 s << "<p><a href=\""<<ii->first<<"/index.html\">"
1030 << ii->first<<"</a>\n";
1032 s << " - \n";
1034 s << "<a name=\"doxygen\"></a>\n";
1035 s << "<a href=..\\doxygen\\" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1039 s << "<a name=\""<<ii->first<<"\"></a>\n";
1040 s << "<p><b>"<<ii->first<<"</b>\n";
1044 s << "<p><TABLE cellspacing=0 cellpadding=3>\n";
1046 std::vector<BlackBoxDescriptor*>::iterator di;
1047 for (di=ii->second.begin();di!=ii->second.end();++di)
1049 std::string pack = (*di)->GetPackage()->GetName();
1050 std::string name = (*di)->GetTypeName();
1051 Utilities::html_format(name);
1052 std::string descr = (*di)->GetDescription();
1053 Utilities::html_format(descr);
1055 s << "<TD style='vertical-align: top;'>";
1056 s << " <a href=\""<<pack
1057 <<"/index.html#"<<name<<"\">"
1058 <<pack<<"::"<<name<<"</a>";
1060 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1067 //----------------------
1072 ptm = gmtime ( &rawtime );
1075 s << "Automatically generated by <b>bbi</b> on "
1076 << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900
1077 << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n";
1078 s << "</body></html>\n";
1080 //----------------------
1083 bbtkDebugDecTab("Kernel",9);