1 /*=========================================================================
4 Module: $RCSfile: bbtkFactory.cxx,v $
7 Date: $Date: 2008/03/04 08:09:04 $
8 Version: $Revision: 1.26 $
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 # define getcwd _getcwd
46 #if defined(_MSC_VER) || defined(__BORLANDC__)
57 typedef Package* (*PackageAccessor)();
58 typedef void (*PackageDeleteFunction)();
61 //===================================================================
65 bbtkDebugMessage("Kernel",7,"Factory::Factory()"<<std::endl);
67 //===================================================================
69 //===================================================================
73 bbtkDebugMessageInc("Kernel",7,"Factory::~Factory()"<<std::endl);
75 bbtkDebugDecTab("Kernel",7);
77 //===================================================================
80 //===================================================================
81 void Factory::CloseAllPackages()
83 bbtkDebugMessageInc("Kernel",7,"Factory::CloseAllPackages()"<<std::endl);
84 while (mPackageMap.begin() != mPackageMap.end())
86 PackageMapType::iterator i = mPackageMap.begin();
89 bbtkDebugDecTab("Kernel",7);
91 //===================================================================
93 //===================================================================
96 bbtkDebugMessageInc("Kernel",7,"Factory::Reset()"<<std::endl);
98 bbtkDebugDecTab("Kernel",7);
100 //===================================================================
103 // ===================================================================
104 bool Factory::DoLoadPackage(std::string libname,
109 #if defined(__GNUC__)
112 handler = dlopen(libname.c_str(),
113 BBTK_RTLD_TIME | BBTK_RTLD_SCOPE );
116 // The following is *NOT* a debug time message :
117 // It's a user intended message.
118 // Please don't remove it.
119 bbtkError("Could not open shared library [" <<libname<<"] : "
120 <<dlerror() << std::endl);
122 return false; // try next path
125 // The following is *NOT* a debug time message :
126 // It's a user intended message.
127 // Please don't remove it.
128 bbtkMessage("Output",2," -->[" <<libname<<"] found" << std::endl);
130 // Loads the Package accessor
132 std::string getpackname(pkgname);
133 getpackname += "GetPackage";
134 void *getpack = dlsym(handler, getpackname.c_str());
138 bbtkError("Shared library ["<<libname<<"] is not a valid bbtk package."
139 <<" Symbol ["<<getpackname<<"] :"<<dlerror());
142 // Verifies that the Package delete function is present
143 std::string delfname(pkgname);
144 delfname += "DeletePackage";
145 void *delf = dlsym(handler, delfname.c_str());
149 bbtkError("Shared library ["<<libname<<"] is not a valid bbtk package."
150 <<" Symbol ["<<delfname<<"] :"<<dlerror());
153 #elif defined(_WIN32)
158 handler = LoadLibrary(libname.c_str());
161 // The following is *NOT* a debug time message :
162 // It's a user intended message.
163 // Please don't remove it.
164 bbtkError("Error loading library [" <<libname<<"]" << std::endl);
165 return false;// Problem with the found library
168 bbtkMessage("Output",2," --->[" <<libname<<"] found" << std::endl);
170 // Loads the Package accessor
172 std::string getpackname(pkgname);
173 getpackname += "GetPackage";
174 void *getpack = GetProcAddress(handler, getpackname.c_str());
177 FreeLibrary(handler);
178 bbtkError("[1] Could not load package \""<<pkgname
179 <<"\" : "<<getpackname<<" symbol not found (is it a bbtk package lib ?)");
180 // look how to get the error message on win
183 // Verifies that the Package delete function is present
184 std::string delfname(pkgname);
185 delfname += "DeletePackage";
186 void *delf = GetProcAddress(handler, delfname.c_str());
189 FreeLibrary(handler);
190 bbtkError("[2] Could not load package \""<<pkgname
191 <<"\" : "<<delfname<<" symbol not found (is it a bbtk package lib ?)");
192 // look how to get the error message on win
196 bbtkError("neither __GNUC__ nor _WIN32 ?!? How did you compile ?");
199 // Stores the package
200 PackageInfoType pack;
201 pack.mDynamicLibraryHandler = handler;
202 // Invokes the accessor to the PackageUnit pointer
203 pack.mPackage = ((PackageAccessor)getpack)();
205 mPackageMap[pkgname] = pack;
207 // Test bbtk build version ok
208 if ( pack.mPackage->GetBBTKVersion() != bbtk::GetVersion() )
210 std::string v(pack.mPackage->GetBBTKVersion());
211 UnLoadPackage(pkgname);
212 bbtkError("Cannot load package ["<<libname<<"]. "
213 <<"Package build with bbtk version "
215 << " whereas application build with version "
216 << bbtk::GetVersion());
219 std::string separator =
220 ConfigurationFile::GetInstance().Get_file_separator ();
221 //BBTK_STRINGIFY_SYMBOL(BBTK_DOC_REL_PATH)
222 std::string docreldoc =
223 separator + "bbdoc" + separator + pkgname + separator + "index.html";
225 ".." + separator + ".." + docreldoc;
226 std::string doc = path + separator + ".." + separator
227 + BBTK_STRINGIFY_SYMBOL(BBTK_DOC_REL_PATH)
230 pack.mPackage->SetDocURL(doc);
231 pack.mPackage->SetDocRelativeURL(reldoc);
233 //===================================================================
234 bbtkMessage("Output",2,pack.mPackage->GetName()<<" "
235 <<pack.mPackage->GetVersion()
237 <<pack.mPackage->GetBBTKVersion()<<") "
238 <<pack.mPackage->GetAuthor() << " Category(s) :"
239 <<pack.mPackage->GetCategory()
241 bbtkMessage("Output",2,pack.mPackage->GetDescription()<<std::endl);
242 //===================================================================
244 bbtkDebugDecTab("Kernel",7);
248 //===================================================================
249 /// \brief Loads a package.
251 /// The name is the system-independant name of the package (the name of the instance of bbtk::Package).
252 /// Tries to open the dynamic library :
253 /// - "libbb<name>.so" for linux systems,
254 /// - "bb<name>.dll" for windows systems.
255 /// If it succeeds, then tries to load the symbols "<name>GetPackage" and "<name>DeletePackage".
256 /// "<name>GetPackage" is called to get the pointer on the bbtk::Package of the library
257 /// ("<name>DeletePackage" is not used, its presence is just checked before loading the package).
259 /// now, filename is only the last name (no longer the full name!)
260 /// it will be searched within *all* the paths given in bbtk_config.xml
264 void Factory::LoadPackage( const std::string& name )
266 // Note : in the following :
267 // name : the user supplied name
268 // - abreviated name e.g. pkg pkg.so libbpkg libbbpkg.so
269 // - relative full name e.g. ./libbbpkg.so ../../libbbpkg.so
270 // - absolute full name e.g. /home/usrname/proj/lib/libbbpkg.so
271 // same for Windows, with c:, d: ...
273 // lastname : string before the last / (if any), or user supplied name
275 bbtkDebugMessageInc("Kernel",7,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
276 bbtkMessage("Debug",1,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
278 std::vector<std::string> package_paths;
279 std::string libname; // full path library name
280 std::string pkgname; // e.g. libbb<pkgname>.so
283 pkgname = Utilities::ExtractPackageName(name,upath);
285 bbtkMessage("Debug",1,"Package name ["<<pkgname<<"]"<<std::endl);
286 bbtkMessage("Debug",1,"Package path ["<<upath<<"]"<<std::endl);
288 // no loading package if already loaded
289 PackageMapType::iterator iUnload;
290 iUnload = mPackageMap.find(pkgname);
291 if (iUnload != mPackageMap.end())
293 bbtkMessage("Output",2,"["<< pkgname <<"] already loaded" << std::endl);
297 // =================================================
298 // The following structure was checked to work
299 // with any type of relative/absolute path.
300 // Please don't modify it without checking
301 // *all* the cases. JP
302 //==================================================
304 //std::cout << "upath [" << upath << "]" << std::endl;
307 bool foundFile = false;
309 // If path provided by user will be the first scanned :
310 // push it into vector of paths
311 if (upath.length()>0) // ------------------------------------- check user supplied location
313 if (name[0] != '.' && name[0] != '/' && name[1]!= ':')
315 bbtkError("Use absolute or relative path name! ["<<name<<"] is an illegal name");
319 // std::string path = Utilities::ExpandLibName(upath, false);
320 std::string path = Utilities::ExpandLibName(name,false); // keep last item, here.
325 Utilities::ExtractPackageName(path,p2);
326 //libname = Utilities::MakeLibnameFromPath(path, pkgname);
327 libname = Utilities::MakeLibnameFromPath(p2, pkgname); // remove last item
328 // Check if library exists
329 if ( !Utilities::FileExists(libname) )
331 // The following is *NOT* a debug time message :
332 // It's a user intended message.
333 // Please don't remove it.
334 bbtkMessage("Output",3," [" <<libname
335 <<"] : doesn't exist" <<std::endl);
339 ok = DoLoadPackage( libname, pkgname, path);
344 bbtkError("Path ["<<upath<<"] doesn't exist");
348 else // ----------------------------------------------------- iterate on the paths
352 package_paths = ConfigurationFile::GetInstance().Get_package_paths();
353 std::vector<std::string>::iterator i;
354 for (i=package_paths.begin();i!=package_paths.end();++i)
359 // we *really* want '.' to be the current working directory
362 char buf[2048]; // for getcwd
363 char * currentDir = getcwd(buf, 2048);
364 std::string cwd(currentDir);
368 libname = Utilities::MakeLibnameFromPath(path, pkgname);
370 bbtkMessage("Debug",2,"-> Trying to load [" << libname << "]" <<std::endl);
372 // Check if library exists
373 if ( !Utilities::FileExists(libname) )
375 // The following is *NOT* a debug time message :
376 // It's a user intended message.
377 // Please don't remove it.
378 bbtkMessage("Output",3,
379 " [" <<libname <<"] : doesn't exist" <<std::endl);
380 continue; // try next path
384 // Try to Load the library
386 ok = DoLoadPackage( libname, pkgname, path);
389 bbtkMessage("Debug",2," OK"<<std::endl);
390 break; // a package was found; we stop iterating
392 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
396 if( !ok ) // nothing was loaded
400 bbtkError("Could not find package ["<<pkgname<< "]");
404 #if defined(__GNUC__)
405 bbtkError("Could not load package ["<< pkgname
406 <<"] :" << std::endl << " " << dlerror());
407 #elif defined(_WIN32)
408 bbtkError("Could not load package ["<<pkgname
409 <<"] : " << std::endl << " " <<libname<<" not found");
411 // look how to get the error message on win
413 // it is the bordel !! (the bloody fucking bordel, you mean?)
414 // look : http://msdn2.microsoft.com/en-us/library/ms680582.aspx
418 bbtkMessage("Output",2,"[" << libname << "] loaded" << std::endl);
422 //===================================================================
423 /// \brief UnLoads a package.
425 /// The package must have been previously loaded by LoadPackage.
426 /// If the entry is found in the map, calls ClosePackage
427 void Factory::UnLoadPackage( const std::string& name )
429 bbtkDebugMessageInc("Kernel",7,"Factory::UnLoadPackage(\""
430 <<name<<"\")"<<std::endl);
432 PackageMapType::iterator i;
433 i = mPackageMap.find(name);
434 if (i == mPackageMap.end())
436 bbtkError("cannot unload package \""<<name
437 <<"\" : package not loaded !");
440 bbtkDebugDecTab("Kernel",7);
442 //===================================================================
445 //===================================================================
446 /// \brief Close the package referenced by the iterator
448 /// If it is a dynamically loaded package
449 /// - Loads and calls the function "<name>DeletePackage" of the dynamic library (responsible for package desallocation)
450 /// - Closes the dynamic library
451 /// - Erases the package entry in the packages map
453 /// Else simply erases the package entry in the packages map
454 void Factory::ClosePackage(PackageMapType::iterator& i)
456 bbtkDebugMessageInc("Kernel",7,"Factory::ClosePackage(\""
457 <<i->second.mPackage->GetName()
460 if (i->second.mDynamicLibraryHandler)
463 // If it is a dynamically loaded package
464 // Loads the Package delete function
466 std::string delfname(i->second.mPackage->GetName());
467 delfname += "DeletePackage";
468 #if defined(__GNUC__)
469 void *delf = dlsym(i->second.mDynamicLibraryHandler, delfname.c_str());
472 bbtkError("could not close package \""
473 <<i->second.mPackage->GetName()
474 <<"\" :"<<dlerror());
476 #elif defined(_WIN32)
477 void *delf = GetProcAddress(i->second.mDynamicLibraryHandler,
481 bbtkError("could not close package \""
482 <<i->second.mPackage->GetName()
484 <<" symbol not found (how did you open it ???");
485 //<<"\" :"<<dlerror());
489 // deletes the package
490 ((PackageDeleteFunction)delf)();
492 // closes the dl handler
493 #if defined(__GNUC__)
494 dlclose(i->second.mDynamicLibraryHandler);
495 #elif defined(_WIN32)
497 FreeLibrary(i->second.mDynamicLibraryHandler);
502 // If it is a manually inserted package
503 delete i->second.mPackage;
506 // remove the entry in the map
507 mPackageMap.erase(i);
508 bbtkDebugDecTab("Kernel",7);
510 //===================================================================
514 //===================================================================
515 /// Displays the list of packages loaded
516 void Factory::PrintPackages(bool details, bool adaptors) const
518 bbtkDebugMessageInc("Kernel",9,"Factory::PrintPackages"<<std::endl);
520 PackageMapType::const_iterator i;
521 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
523 bbtkMessage("Help",1, i->first << std::endl);
525 i->second.mPackage->PrintBlackBoxes(false,adaptors);
529 bbtkDebugDecTab("Kernel",9);
531 //===================================================================
533 //===================================================================
534 /// Displays help on a package
535 void Factory::HelpPackage(const std::string& name, bool adaptors) const
537 bbtkDebugMessageInc("Kernel",9,"Factory::HelpPackage(\""<<name<<"\")"
540 PackageMapType::const_iterator i = mPackageMap.find(name);
541 if ( i != mPackageMap.end() )
543 bbtkMessage("Help",1, "Package "<<i->first<<" ");
545 if (i->second.mPackage->GetVersion().length()>0)
546 bbtkMessageCont("Help",1,"v" <<i->second.mPackage->GetVersion());
548 if (i->second.mPackage->GetAuthor().length()>0)
549 bbtkMessageCont("Help",1,"- "<<i->second.mPackage->GetAuthor());
551 if (i->second.mPackage->GetCategory().length()>0)
552 bbtkMessageCont("Help",1,"- "<<i->second.mPackage->GetCategory());
554 bbtkMessageCont("Help",1,std::endl);
555 bbtkIncTab("Help",1);
556 bbtkMessage("Help",1,i->second.mPackage->GetDescription()<<std::endl);
557 if (i->second.mPackage->GetNumberOfBlackBoxes()>0)
559 bbtkMessage("Help",1, "Black boxes : "<<std::endl);
560 i->second.mPackage->PrintBlackBoxes(true,adaptors);
564 bbtkMessage("Help",1, "No black boxes"<<std::endl);
566 bbtkDecTab("Help",1);
570 bbtkDebugDecTab("Kernel",9);
571 bbtkError("package \""<<name<<"\" unknown");
574 bbtkDebugDecTab("Kernel",9);
576 //===================================================================
578 //===================================================================
579 /// Prints help on the black box of type <name>
580 /// Returns the package to which it belongs
581 void Factory::HelpBlackBox(const std::string& name,
582 std::string& package,
585 bbtkDebugMessageInc("Kernel",9,"Factory::HelpBlackBox(\""<<name<<"\")"
589 PackageMapType::const_iterator i;
590 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
592 if (i->second.mPackage->ContainsBlackBox(name))
594 i->second.mPackage->HelpBlackBox(name,full);
595 package = i->second.mPackage->GetName();
600 bbtkDebugDecTab("Kernel",9);
603 bbtkError("No package of the factory contains any black box <"
607 //===================================================================
610 //===================================================================
611 /// Inserts a package in the factory
612 void Factory::InsertPackage( Package* p )
614 bbtkDebugMessageInc("Kernel",9,"Factory::InsertPackage(\""<<
615 p->GetName()<<"\")"<<std::endl);
617 PackageInfoType pack;
618 pack.mDynamicLibraryHandler = 0;
622 mPackageMap[p->GetName()] = pack;
623 bbtkDebugDecTab("Kernel",9);
625 //===================================================================
627 //===================================================================
628 /// Removes a package from the factory (and deletes it)
629 void Factory::RemovePackage( Package* p )
631 bbtkDebugMessageInc("Kernel",9,"Factory::RemovePackage(\""<<
632 p->GetName()<<"\")"<<std::endl);
634 PackageMapType::iterator i;
635 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
637 if (i->second.mPackage == p) break;
640 if (i!=mPackageMap.end())
646 bbtkError("Factory::RemovePackage(\""<<
647 p->GetName()<<"\") : package absent from factory");
650 bbtkDebugDecTab("Kernel",9);
652 //===================================================================
655 //===================================================================
656 /// Creates an instance of a black box of type <type> with name <name>
657 BlackBox* Factory::NewBlackBox(const std::string& type,
658 const std::string& name) const
660 bbtkDebugMessageInc("Kernel",7,"Factory::NewBlackBox(\""
661 <<type<<"\",\""<<name<<"\")"<<std::endl);
664 PackageMapType::const_iterator i;
665 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
667 b = i->second.mPackage->NewBlackBox(type,name);
672 bbtkError("black box type \""<<type<<"\" unknown");
675 bbtkDebugDecTab("Kernel",7);
678 //===================================================================
680 //===================================================================
681 /// Creates an instance of a black box of type <type> with name <name>
682 BlackBox* Factory::NewAdaptor(TypeInfo typein,
684 const std::string& name) const
686 bbtkDebugMessageInc("Kernel",8,"Factory::NewAdaptor(<"
687 <<TypeName(typein)<<">,<"
688 <<TypeName(typeout)<<">,\""
689 <<name<<"\")"<<bbtkendl);
693 PackageMapType::const_iterator i;
694 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
696 b = i->second.mPackage->NewAdaptor(typein,typeout,name);
702 <<TypeName(typein)<<"> to <"
704 <<"> adaptor available");
707 bbtkDebugDecTab("Kernel",7);
710 //===================================================================
712 //===================================================================
713 /// Creates an instance of a connection
714 Connection* Factory::NewConnection(BlackBox* from,
715 const std::string& output,
717 const std::string& input) const
719 bbtkDebugMessage("Kernel",7,"Factory::NewConnection(\""
720 <<from->bbGetName()<<"\",\""<<output<<"\",\""
721 <<to->bbGetName()<<"\",\""<<input
724 return new Connection(from,output,to,input);
727 // !!! WARNING : WE NEED TO TEST THE TYPE NAME EQUALITY
728 // BECAUSE IN DIFFERENT DYN LIBS THE type_info EQUALITY CAN
729 // BE FALSE (DIFFERENT INSTANCES !)
731 std::string t1 ( from->bbGetOutputType(output).name() );
732 std::string t2 ( to->bbGetInputType(input).name() );
736 //from->bbGetOutputType(output) ==
737 // to->bbGetInputType(input) )
739 c = new Connection(from,output,to,input);
743 // std::cout << "Adaptive connection "<<std::endl;
745 name = from->bbGetName() + "." + output + "-"
746 + to->bbGetName() + "." + input;
749 PackageMapType::const_iterator i;
750 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
752 b = i->second.mPackage->NewAdaptor(from->bbGetOutputType(output),
753 to->bbGetInputType(input),
759 bbtkError("did not find any <"
760 <<TypeName(from->bbGetOutputType(output))
762 <<TypeName(to->bbGetInputType(input))
765 c = new AdaptiveConnection(from,output,to,input,b);
767 bbtkDebugDecTab("Kernel",7);
772 //===================================================================
776 //===================================================================
777 const Package* Factory::GetPackage(const std::string& name) const
779 bbtkDebugMessageInc("Kernel",9,"Factory::GetPackage(\""<<name<<"\")"
782 PackageMapType::const_iterator i = mPackageMap.find(name);
783 if ( i != mPackageMap.end() )
785 bbtkDebugDecTab("Kernel",9);
786 return i->second.mPackage;
790 bbtkDebugDecTab("Kernel",9);
791 bbtkError("package \""<<name<<"\" unknown");
794 bbtkDebugDecTab("Kernel",9);
796 //===================================================================
798 //===================================================================
799 Package* Factory::GetPackage(const std::string& name)
801 bbtkDebugMessageInc("Kernel",9,"Factory::GetPackage(\""<<name<<"\")"
804 PackageMapType::const_iterator i = mPackageMap.find(name);
805 if ( i != mPackageMap.end() )
807 bbtkDebugDecTab("Kernel",9);
808 return i->second.mPackage;
812 bbtkDebugDecTab("Kernel",9);
813 bbtkError("package \""<<name<<"\" unknown");
816 bbtkDebugDecTab("Kernel",9);
818 //===================================================================
820 //===================================================================
821 void Factory::WriteDotFilePackagesList(FILE *ff)
824 bbtkDebugMessageInc("Kernel",9,"Factory::WriteDotFilePackagesList()"
828 fprintf( ff , "subgraph cluster_FACTORY {\n");
829 fprintf( ff , " label = \"PACKAGES\"%s\n", ";");
830 fprintf( ff , " style=filled%s\n",";");
831 fprintf( ff , " color=lightgrey%s\n",";");
832 fprintf( ff , " rankdir=TB%s\n",";");
835 PackageMapType::const_iterator i;
836 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
838 url=GetPackage(i->first)->GetDocURL();
839 fprintf(ff," %s [shape=ellipse, URL=\"%s\"]%s\n",i->first.c_str(),url.c_str(),";" );
841 fprintf( ff , "}\n\n");
842 bbtkDebugDecTab("Kernel",9);
844 //===================================================================
847 void Factory::ShowGraphTypes(const std::string& name) const
851 PackageMapType::const_iterator i;
852 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
854 if (i->second.mPackage->ContainsBlackBox(name))
856 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
858 // Don't pollute the file store with "temp_dir" directories ...
859 std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
860 std::string directory = "\"" + default_doc_dir + separator + "temp_dir" +separator + "\"";
861 std::string filename2 = default_doc_dir + separator + "temp_dir" + separator + "tmp.html";
864 std::string command("start \"Titre\" /D ");
866 std::string command("gnome-open ");
868 command=command + directory +" tmp.html";
870 ff=fopen(filename2.c_str(),"w");
872 fprintf(ff,"<html><head><title>TMP</title> <script type=\"text/javascript\"> <!--\n");
873 fprintf(ff," window.location=\"%s#%s\";\n" , i->second.mPackage->GetDocURL().c_str(),name.c_str() );
874 fprintf(ff,"//--></script></head><body></body></html>\n");
877 //fprintf(ff, "<a href=\"%s#%s\">Link</a>\n", i->second.mPackage->GetDocURL().c_str(),name.c_str() );
879 system( command.c_str() );
884 bbtkDebugDecTab("Kernel",9);
887 bbtkError("No package of the factory contains any black box <"
895 void Factory::CreateHtmlIndex(IndexEntryType type,
896 const std::string& filename)
898 bbtkDebugMessageInc("Kernel",9,"Factory::CreateHtmlIndex(\""
899 <<filename<<"\")"<<bbtkendl);
903 typedef std::map<std::string, std::vector<BlackBoxDescriptor*> > IndexType;
905 // Builds the index map
906 PackageMapType::const_iterator i;
907 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
909 Package* pack = i->second.mPackage;
910 if (pack->GetName()=="user") continue;
911 Package::BlackBoxMapType::const_iterator j;
912 for (j = pack->GetBlackBoxMap().begin();
913 j!= pack->GetBlackBoxMap().end();
918 if ( type==Adaptors )
920 if (j->second->GetKind() == BlackBoxDescriptor::STANDARD )
924 if (j->second->GetKind() != BlackBoxDescriptor::STANDARD )
927 std::vector<std::string> keys;
931 k += pack->GetName();
933 title = "Boxes by package";
935 else if ((type==Initials) || (type==Adaptors))
937 std::string init(" ");
938 init[0] = std::toupper(j->second->GetTypeName()[0]);
939 keys.push_back(init);
940 title = "Alphabetical list";
942 else if (type==Categories)
944 // Split the category string
945 std::string delimiters = ";,";
946 Utilities::SplitString(j->second->GetCategory(),
949 keys.push_back(" NONE");
950 title = "Boxes by category";
954 std::vector<std::string>::const_iterator k;
955 for (k=keys.begin(); k!=keys.end(); ++k )
957 IndexType::iterator p;
959 if (p != index.end())
961 p->second.push_back(j->second);
965 std::vector<BlackBoxDescriptor*> v;
966 v.push_back(j->second);
974 //---------------------
977 s.open(filename.c_str());
980 bbtkError("Factory::CreateHtmlIndex : could not open file '"
984 //----------------------
986 s << "<html lang=\"en\">\n";
988 s << "<title>"<<title<<"</title>\n";
989 s << "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n";
990 s << "<meta name=\"description\" content=\""<<title<<"\">\n";
991 s << "<meta name=\"generator\" content=\"\">\n";
992 s << "<link title=\"Top\" rel=\"top\" href=\"#Top\">\n";
993 //<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
994 s << "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><style type=\"text/css\"><!--\n";
995 s << "pre.display { font-family:inherit }\n";
996 s << "pre.format { font-family:inherit }\n";
997 s << "pre.smalldisplay { font-family:inherit; font-size:smaller }\n";
998 s << "pre.smallformat { font-family:inherit; font-size:smaller }\n";
999 s << "pre.smallexample { font-size:smaller }\n";
1000 s << "pre.smalllisp { font-size:smaller }\n";
1001 s << "span.sc { font-variant:small-caps }\n";
1002 s << "span.roman { font-family:serif; font-weight:normal; } \n";
1003 s << "span.sansserif { font-family:sans-serif; font-weight:normal; }\n";
1004 s << "--></style>\n";
1006 //----------------------
1008 //----------------------
1011 s << "<a name=\"Top\"></a>\n";
1012 s << "<h1 class=\"settitle\">"<<title<<"</h1>\n";
1014 IndexType::iterator ii;
1015 for (ii=index.begin();ii!=index.end();++ii)
1017 s << "<a href=\"#"<<ii->first<<"\">"<<ii->first<<"</a> ";
1020 for (ii=index.begin();ii!=index.end();++ii)
1023 s << "<p><a href=\"#Top\">Top</a>";
1026 s << "<a name=\""<<ii->first<<"\"></a>\n";
1027 s << "<p><a href=\""<<ii->first<<"/index.html\">"
1028 << ii->first<<"</a>\n";
1030 s << " - \n";
1032 s << "<a name=\"doxygen\"></a>\n";
1033 s << "<a href=..\\doxygen\\" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1037 s << "<a name=\""<<ii->first<<"\"></a>\n";
1038 s << "<p><b>"<<ii->first<<"</b>\n";
1042 s << "<p><TABLE cellspacing=0 cellpadding=3>\n";
1044 std::vector<BlackBoxDescriptor*>::iterator di;
1045 for (di=ii->second.begin();di!=ii->second.end();++di)
1047 std::string pack = (*di)->GetPackage()->GetName();
1048 std::string name = (*di)->GetTypeName();
1049 Utilities::html_format(name);
1050 std::string descr = (*di)->GetDescription();
1051 Utilities::html_format(descr);
1053 s << "<TD style='vertical-align: top;'>";
1054 s << " <a href=\""<<pack
1055 <<"/index.html#"<<name<<"\">"
1056 <<pack<<"::"<<name<<"</a>";
1058 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1065 //----------------------
1070 ptm = gmtime ( &rawtime );
1073 s << "Automatically generated by <b>bbi</b> on "
1074 << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900
1075 << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n";
1076 s << "</body></html>\n";
1078 //----------------------
1081 bbtkDebugDecTab("Kernel",9);