1 /*=========================================================================
4 Module: $RCSfile: bbtkFactory.cxx,v $
7 Date: $Date: 2008/02/14 12:15:59 $
8 Version: $Revision: 1.20 $
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 // ===================================================================================
105 bool Factory::DoLoadPackage(std::string libname,
111 #if defined(__GNUC__)
115 handler = dlopen(libname.c_str(),
116 BBTK_RTLD_TIME | BBTK_RTLD_SCOPE );
119 // The following is *NOT* a debug time message :
120 // It's a user intended message.
121 // Please don't remove it.
123 std::cout <<"[" <<libname<<"] can't be open" << std::endl;
124 std::cout << " " <<dlerror() << std::endl;
126 return false; // try next path
129 // The following is *NOT* a debug time message :
130 // It's a user intended message.
131 // Please don't remove it.
133 std::cout <<" -->[" <<libname<<"] found" << std::endl;
135 // Loads the Package accessor
137 std::string getpackname(pkgname);
138 getpackname += "GetPackage";
139 void *getpack = dlsym(handler, getpackname.c_str());
143 bbtkError("GetPackage : could not load package \""<<pkgname
144 <<"\" [symbol "<<getpackname<<"] :"<<dlerror());
147 // Verifies that the Package delete function is present
148 std::string delfname(pkgname);
149 delfname += "DeletePackage";
150 void *delf = dlsym(handler, delfname.c_str());
154 bbtkError("DeletePackage : could not load package \""<<pkgname
155 <<"\" [symbol "<<delfname<<"] :"<<dlerror());
158 #elif defined(_WIN32)
163 handler = LoadLibrary(libname.c_str());
166 // The following is *NOT* a debug time message :
167 // It's a user intended message.
168 // Please don't remove it.
169 std::cout <<" no handler for [" <<libname<<"];" << std::endl;
170 return false;// Problem with the found library
173 std::cout <<" --->[" <<libname<<"] found" << std::endl;
175 // Loads the Package accessor
177 std::string getpackname(pkgname);
178 getpackname += "GetPackage";
179 void *getpack = GetProcAddress(handler, getpackname.c_str());
182 FreeLibrary(handler);
183 bbtkError("[1]could not load package \""<<pkgname
184 <<"\" : "<<getpackname<<" symbol not found (is it a bbtk package lib ?)");
185 // look how to get the error message on win
188 // Verifies that the Package delete function is present
189 std::string delfname(pkgname);
190 delfname += "DeletePackage";
191 void *delf = GetProcAddress(handler, delfname.c_str());
194 FreeLibrary(handler);
195 bbtkError("[2]could not load package \""<<pkgname
196 <<"\" : "<<delfname<<" symbol not found (is it a bbtk package lib ?)");
197 // look how to get the error message on win
201 bbtkError("neither __GNUC__ nor _WIN32 ?!? How did you compile ?");
204 // Stores the package
205 PackageInfoType pack;
206 pack.mDynamicLibraryHandler = handler;
207 // Invokes the accessor to the PackageUnit pointer
208 pack.mPackage = ((PackageAccessor)getpack)();
210 mPackageMap[pkgname] = pack;
212 // Test bbtk build version ok
213 if ( pack.mPackage->GetBBTKVersion() != bbtk::GetVersion() )
215 std::string v(pack.mPackage->GetBBTKVersion());
216 UnLoadPackage(pkgname);
217 bbtkError(" package build with bbtk version "
219 << " whereas application build with version "
220 << bbtk::GetVersion());
223 std::string separator =
224 ConfigurationFile::GetInstance().Get_file_separator ();
225 //BBTK_STRINGIFY_SYMBOL(BBTK_DOC_REL_PATH)
226 std::string docreldoc =
227 separator + "bbdoc" + separator + pkgname + separator + "index.html";
229 ".." + separator + ".." + docreldoc;
230 std::string doc = path + separator + ".." + separator
231 + BBTK_STRINGIFY_SYMBOL(BBTK_DOC_REL_PATH)
234 pack.mPackage->SetDocURL(doc);
235 pack.mPackage->SetDocRelativeURL(reldoc);
237 //===================================================================
238 bbtkMessage("Output",2,pack.mPackage->GetName()<<" "
239 <<pack.mPackage->GetVersion()
241 <<pack.mPackage->GetBBTKVersion()<<") "
242 <<pack.mPackage->GetAuthor() << " Category(s) :"
243 <<pack.mPackage->GetCategory()
245 bbtkMessage("Output",2,pack.mPackage->GetDescription()<<std::endl);
246 //===================================================================
248 bbtkDebugDecTab("Kernel",7);
252 //===================================================================
253 /// \brief Loads a package.
255 /// The name is the system-independant name of the package (the name of the instance of bbtk::Package).
256 /// Tries to open the dynamic library :
257 /// - "libbb<name>.so" for linux systems,
258 /// - "bb<name>.dll" for windows systems.
259 /// If it succeeds, then tries to load the symbols "<name>GetPackage" and "<name>DeletePackage".
260 /// "<name>GetPackage" is called to get the pointer on the bbtk::Package of the library
261 /// ("<name>DeletePackage" is not used, its presence is just checked before loading the package).
263 /// now, filename is only the last name (no longer the full name!)
264 /// it will be searched within *all* the paths given in bbtk_config.xml
266 /// verbose = true (set by "config v") displays the loading process
268 void Factory::LoadPackage( const std::string& name,
269 bool use_configuration_file, bool verbose)
271 // Note : in the following :
272 // name : the user supplied name
273 // - abreviated name e.g. pkg pkg.so libbpkg libbbpkg.so
274 // - relative full name e.g. ./libbbpkg.so ../../libbbpkg.so
275 // - absolute full name e.g. /home/usrname/proj/lib/libbbpkg.so
276 // same for Windows, with c:, d: ...
278 // lastname : string before the last / (if any), or user supplied name
280 bbtkDebugMessageInc("Kernel",7,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
281 bbtkMessage("Debug",1,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
282 bbtkMessage("Debug",1,"use_configuration_file ["
283 << use_configuration_file << "]" << std::endl);
285 std::vector<std::string> package_paths;
286 std::string libname; // full path library name
287 std::string pkgname; // e.g. libbb<pkgname>.so
290 pkgname = Utilities::ExtractPackageName(name,upath);
292 bbtkMessage("Debug",1,"Package name ["<<pkgname<<"]"<<std::endl);
293 bbtkMessage("Debug",1,"Package path ["<<upath<<"]"<<std::endl);
295 // no loading package if already loaded
296 PackageMapType::iterator iUnload;
297 iUnload = mPackageMap.find(pkgname);
298 if (iUnload != mPackageMap.end())
300 bbtkMessage("Output",2,"["<< pkgname <<"] already loaded" << std::endl);
304 // =================================================
305 // The following structure was checked to work
306 // with any type of relative/absolute path.
307 // Please don't modify it without checking
308 // *all* the cases. JP
309 //==================================================
311 //std::cout << "upath [" << upath << "]" << std::endl;
314 bool foundFile = false;
316 // If path provided by user will be the first scanned :
317 // push it into vector of paths
318 if (upath.length()>0) // ------------------------------------- check user supplied location
320 if (name[0] != '.' && name[0] != '/' && name[1]!= ':')
322 bbtkError("Use absolute or relative path name! ["<<name<<"] is an illegal name");
326 // std::string path = Utilities::ExpandLibName(upath, verbose);
327 std::string path = Utilities::ExpandLibName(name, verbose); // keep last item, here.
332 Utilities::ExtractPackageName(path,p2);
333 //libname = Utilities::MakeLibnameFromPath(path, pkgname);
334 libname = Utilities::MakeLibnameFromPath(p2, pkgname); // remove last item
335 // Check if library exists
336 if ( !Utilities::FileExists(libname) )
338 // The following is *NOT* a debug time message :
339 // It's a user intended message.
340 // Please don't remove it.
342 std::cout <<" [" <<libname <<"] : doesn't exist" <<std::endl;
346 ok = DoLoadPackage( libname, pkgname, path, verbose);
351 bbtkError("Path ["<<upath<<"] doesn't exist");
355 else // ----------------------------------------------------- iterate on the paths
359 package_paths = ConfigurationFile::GetInstance().Get_package_paths();
360 std::vector<std::string>::iterator i;
361 for (i=package_paths.begin();i!=package_paths.end();++i)
366 // we *really* want '.' to be the current working directory
369 char buf[2048]; // for getcwd
370 char * currentDir = getcwd(buf, 2048);
371 std::string cwd(currentDir);
375 libname = Utilities::MakeLibnameFromPath(path, pkgname);
377 bbtkMessage("Debug",2,"-> Trying to load [" << libname << "]" <<std::endl);
379 // Check if library exists
380 if ( !Utilities::FileExists(libname) )
382 // The following is *NOT* a debug time message :
383 // It's a user intended message.
384 // Please don't remove it.
386 std::cout <<" [" <<libname <<"] : doesn't exist" <<std::endl;
387 continue; // try next path
391 // Try to Load the library
393 ok = DoLoadPackage( libname, pkgname, path, verbose);
396 bbtkMessage("Debug",2," OK"<<std::endl);
397 break; // a package was found; we stop iterating
399 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
403 if( !ok ) // nothing was loaded
407 bbtkError("could not find package ["<<pkgname<< "]");
411 #if defined(__GNUC__)
412 bbtkError("could not load package ["<< pkgname
413 <<"] :" << std::endl << " " << dlerror());
414 #elif defined(_WIN32)
415 bbtkError("could not load package ["<<pkgname
416 <<"] : " << std::endl << " " <<libname<<" not found");
418 // look how to get the error message on win
420 // it is the bordel !! (the bloody fucking bordel, you mean?)
421 // look : http://msdn2.microsoft.com/en-us/library/ms680582.aspx
425 bbtkMessage("Output",2,"[" << libname << "] loaded" << std::endl);
429 //===================================================================
430 /// \brief UnLoads a package.
432 /// The package must have been previously loaded by LoadPackage.
433 /// If the entry is found in the map, calls ClosePackage
434 void Factory::UnLoadPackage( const std::string& name )
436 bbtkDebugMessageInc("Kernel",7,"Factory::UnLoadPackage(\""
437 <<name<<"\")"<<std::endl);
439 PackageMapType::iterator i;
440 i = mPackageMap.find(name);
441 if (i == mPackageMap.end())
443 bbtkError("cannot unload package \""<<name
444 <<"\" : package not loaded !");
447 bbtkDebugDecTab("Kernel",7);
449 //===================================================================
452 //===================================================================
453 /// \brief Close the package referenced by the iterator
455 /// If it is a dynamically loaded package
456 /// - Loads and calls the function "<name>DeletePackage" of the dynamic library (responsible for package desallocation)
457 /// - Closes the dynamic library
458 /// - Erases the package entry in the packages map
460 /// Else simply erases the package entry in the packages map
461 void Factory::ClosePackage(PackageMapType::iterator& i)
463 bbtkDebugMessageInc("Kernel",7,"Factory::ClosePackage(\""
464 <<i->second.mPackage->GetName()
467 if (i->second.mDynamicLibraryHandler)
470 // If it is a dynamically loaded package
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);
509 // If it is a manually inserted package
510 delete i->second.mPackage;
513 // remove the entry in the map
514 mPackageMap.erase(i);
515 bbtkDebugDecTab("Kernel",7);
517 //===================================================================
521 //===================================================================
522 /// Displays the list of packages loaded
523 void Factory::PrintPackages(bool details, bool adaptors) const
525 bbtkDebugMessageInc("Kernel",9,"Factory::PrintPackages"<<std::endl);
527 PackageMapType::const_iterator i;
528 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
530 bbtkMessage("Help",1, i->first << std::endl);
532 i->second.mPackage->PrintBlackBoxes(false,adaptors);
536 bbtkDebugDecTab("Kernel",9);
538 //===================================================================
540 //===================================================================
541 /// Displays help on a package
542 void Factory::HelpPackage(const std::string& name, bool adaptors) const
544 bbtkDebugMessageInc("Kernel",9,"Factory::HelpPackage(\""<<name<<"\")"
547 PackageMapType::const_iterator i = mPackageMap.find(name);
548 if ( i != mPackageMap.end() )
550 bbtkMessage("Help",1, "Package "<<i->first<<" ");
552 if (i->second.mPackage->GetVersion().length()>0)
553 bbtkMessageCont("Help",1,"v" <<i->second.mPackage->GetVersion());
555 if (i->second.mPackage->GetAuthor().length()>0)
556 bbtkMessageCont("Help",1,"- "<<i->second.mPackage->GetAuthor());
558 if (i->second.mPackage->GetCategory().length()>0)
559 bbtkMessageCont("Help",1,"- "<<i->second.mPackage->GetCategory());
561 bbtkMessageCont("Help",1,std::endl);
562 bbtkIncTab("Help",1);
563 bbtkMessage("Help",1,i->second.mPackage->GetDescription()<<std::endl);
564 if (i->second.mPackage->GetNumberOfBlackBoxes()>0)
566 bbtkMessage("Help",1, "Black boxes : "<<std::endl);
567 i->second.mPackage->PrintBlackBoxes(true,adaptors);
571 bbtkMessage("Help",1, "No black boxes"<<std::endl);
573 bbtkDecTab("Help",1);
577 bbtkDebugDecTab("Kernel",9);
578 bbtkError("package \""<<name<<"\" unknown");
581 bbtkDebugDecTab("Kernel",9);
583 //===================================================================
585 //===================================================================
586 /// Prints help on the black box of type <name>
587 /// Returns the package to which it belongs
588 void Factory::HelpBlackBox(const std::string& name,
589 std::string& package,
592 bbtkDebugMessageInc("Kernel",9,"Factory::HelpBlackBox(\""<<name<<"\")"
596 PackageMapType::const_iterator i;
597 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
599 if (i->second.mPackage->ContainsBlackBox(name))
601 i->second.mPackage->HelpBlackBox(name,full);
602 package = i->second.mPackage->GetName();
607 bbtkDebugDecTab("Kernel",9);
610 bbtkError("No package of the factory contains any black box <"
614 //===================================================================
617 //===================================================================
618 /// Inserts a package in the factory
619 void Factory::InsertPackage( Package* p )
621 bbtkDebugMessageInc("Kernel",9,"Factory::InsertPackage(\""<<
622 p->GetName()<<"\")"<<std::endl);
624 PackageInfoType pack;
625 pack.mDynamicLibraryHandler = 0;
629 mPackageMap[p->GetName()] = pack;
630 bbtkDebugDecTab("Kernel",9);
632 //===================================================================
634 //===================================================================
635 /// Removes a package from the factory (and deletes it)
636 void Factory::RemovePackage( Package* p )
638 bbtkDebugMessageInc("Kernel",9,"Factory::RemovePackage(\""<<
639 p->GetName()<<"\")"<<std::endl);
641 PackageMapType::iterator i;
642 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
644 if (i->second.mPackage == p) break;
647 if (i!=mPackageMap.end())
653 bbtkError("Factory::RemovePackage(\""<<
654 p->GetName()<<"\") : package absent from factory");
657 bbtkDebugDecTab("Kernel",9);
659 //===================================================================
662 //===================================================================
663 /// Creates an instance of a black box of type <type> with name <name>
664 BlackBox* Factory::NewBlackBox(const std::string& type,
665 const std::string& name) const
667 bbtkDebugMessageInc("Kernel",7,"Factory::NewBlackBox(\""
668 <<type<<"\",\""<<name<<"\")"<<std::endl);
671 PackageMapType::const_iterator i;
672 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
674 b = i->second.mPackage->NewBlackBox(type,name);
679 bbtkError("black box type \""<<type<<"\" unknown");
682 bbtkDebugDecTab("Kernel",7);
685 //===================================================================
687 //===================================================================
688 /// Creates an instance of a black box of type <type> with name <name>
689 BlackBox* Factory::NewAdaptor(TypeInfo typein,
691 const std::string& name) const
693 bbtkDebugMessageInc("Kernel",8,"Factory::NewAdaptor(<"
694 <<TypeName(typein)<<">,<"
695 <<TypeName(typeout)<<">,\""
696 <<name<<"\")"<<bbtkendl);
700 PackageMapType::const_iterator i;
701 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
703 b = i->second.mPackage->NewAdaptor(typein,typeout,name);
709 <<TypeName(typein)<<"> to <"
711 <<"> adaptor available");
714 bbtkDebugDecTab("Kernel",7);
717 //===================================================================
719 //===================================================================
720 /// Creates an instance of a connection
721 Connection* Factory::NewConnection(BlackBox* from,
722 const std::string& output,
724 const std::string& input) const
726 bbtkDebugMessage("Kernel",7,"Factory::NewConnection(\""
727 <<from->bbGetName()<<"\",\""<<output<<"\",\""
728 <<to->bbGetName()<<"\",\""<<input
731 return new Connection(from,output,to,input);
734 // !!! WARNING : WE NEED TO TEST THE TYPE NAME EQUALITY
735 // BECAUSE IN DIFFERENT DYN LIBS THE type_info EQUALITY CAN
736 // BE FALSE (DIFFERENT INSTANCES !)
738 std::string t1 ( from->bbGetOutputType(output).name() );
739 std::string t2 ( to->bbGetInputType(input).name() );
743 //from->bbGetOutputType(output) ==
744 // to->bbGetInputType(input) )
746 c = new Connection(from,output,to,input);
750 // std::cout << "Adaptive connection "<<std::endl;
752 name = from->bbGetName() + "." + output + "-"
753 + to->bbGetName() + "." + input;
756 PackageMapType::const_iterator i;
757 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
759 b = i->second.mPackage->NewAdaptor(from->bbGetOutputType(output),
760 to->bbGetInputType(input),
766 bbtkError("did not find any <"
767 <<TypeName(from->bbGetOutputType(output))
769 <<TypeName(to->bbGetInputType(input))
772 c = new AdaptiveConnection(from,output,to,input,b);
774 bbtkDebugDecTab("Kernel",7);
779 //===================================================================
783 //===================================================================
784 const Package* Factory::GetPackage(const std::string& name) const
786 bbtkDebugMessageInc("Kernel",9,"Factory::GetPackage(\""<<name<<"\")"
789 PackageMapType::const_iterator i = mPackageMap.find(name);
790 if ( i != mPackageMap.end() )
792 bbtkDebugDecTab("Kernel",9);
793 return i->second.mPackage;
797 bbtkDebugDecTab("Kernel",9);
798 bbtkError("package \""<<name<<"\" unknown");
801 bbtkDebugDecTab("Kernel",9);
803 //===================================================================
805 //===================================================================
806 Package* Factory::GetPackage(const std::string& name)
808 bbtkDebugMessageInc("Kernel",9,"Factory::GetPackage(\""<<name<<"\")"
811 PackageMapType::const_iterator i = mPackageMap.find(name);
812 if ( i != mPackageMap.end() )
814 bbtkDebugDecTab("Kernel",9);
815 return i->second.mPackage;
819 bbtkDebugDecTab("Kernel",9);
820 bbtkError("package \""<<name<<"\" unknown");
823 bbtkDebugDecTab("Kernel",9);
825 //===================================================================
827 //===================================================================
828 void Factory::WriteDotFilePackagesList(FILE *ff)
830 bbtkDebugMessageInc("Kernel",9,"Factory::WriteDotFilePackagesList()"
834 fprintf( ff , "subgraph cluster_FACTORY {\n");
835 fprintf( ff , " label = \"PACKAGES\"%s\n", ";");
836 fprintf( ff , " style=filled%s\n",";");
837 fprintf( ff , " color=lightgrey%s\n",";");
838 fprintf( ff , " rankdir=TB%s\n",";");
841 PackageMapType::const_iterator i;
842 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
844 url=GetPackage(i->first)->GetDocURL();
845 fprintf(ff," %s [shape=ellipse, URL=\"%s\"]%s\n",i->first.c_str(),url.c_str(),";" );
847 fprintf( ff , "}\n\n");
848 bbtkDebugDecTab("Kernel",9);
850 //===================================================================
853 void Factory::ShowGraphTypes(const std::string& name) const
856 PackageMapType::const_iterator i;
857 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
859 if (i->second.mPackage->ContainsBlackBox(name))
861 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
863 // Don't pollute the file store with "temp_dir" directories ...
864 std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
865 std::string directory = "\"" + default_doc_dir + separator + "temp_dir" +separator + "\"";
866 std::string filename2 = default_doc_dir + separator + "temp_dir" + separator + "tmp.html";
869 std::string command("start \"Titre\" /D ");
871 std::string command("gnome-open ");
873 command=command + directory +" tmp.html";
875 ff=fopen(filename2.c_str(),"w");
877 fprintf(ff,"<html><head><title>TMP</title> <script type=\"text/javascript\"> <!--\n");
878 fprintf(ff," window.location=\"%s#%s\";\n" , i->second.mPackage->GetDocURL().c_str(),name.c_str() );
879 fprintf(ff,"//--></script></head><body></body></html>\n");
882 //fprintf(ff, "<a href=\"%s#%s\">Link</a>\n", i->second.mPackage->GetDocURL().c_str(),name.c_str() );
884 system( command.c_str() );
889 bbtkDebugDecTab("Kernel",9);
892 bbtkError("No package of the factory contains any black box <"
900 void Factory::CreateHtmlIndex(IndexEntryType type,
901 const std::string& filename)
903 bbtkDebugMessageInc("Kernel",9,"Factory::CreateHtmlIndex(\""
904 <<filename<<"\")"<<bbtkendl);
908 typedef std::map<std::string, std::vector<BlackBoxDescriptor*> > IndexType;
910 // Builds the index map
911 PackageMapType::const_iterator i;
912 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
914 Package* pack = i->second.mPackage;
915 if (pack->GetName()=="user") continue;
916 Package::BlackBoxMapType::const_iterator j;
917 for (j = pack->GetBlackBoxMap().begin();
918 j!= pack->GetBlackBoxMap().end();
922 std::vector<std::string> keys;
926 k += pack->GetName();
928 title = "Boxes by package";
930 else if (type==Initials)
932 std::string init(" ");
933 init[0] = std::toupper(j->second->GetTypeName()[0]);
934 keys.push_back(init);
935 title = "Alphabetical list";
937 else if (type==Categories)
939 // Split the category string
940 std::string delimiters = ";,";
941 Utilities::SplitString(j->second->GetCategory(),
944 keys.push_back(" NONE");
945 title = "Boxes by category";
948 std::vector<std::string>::const_iterator k;
949 for (k=keys.begin(); k!=keys.end(); ++k )
951 IndexType::iterator p;
953 if (p != index.end())
955 p->second.push_back(j->second);
959 std::vector<BlackBoxDescriptor*> v;
960 v.push_back(j->second);
968 //---------------------
971 s.open(filename.c_str());
974 bbtkError("Factory::CreateHtmlIndex : could not open file '"
978 //----------------------
980 s << "<html lang=\"en\">\n";
982 s << "<title>"<<title<<"</title>\n";
983 s << "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n";
984 s << "<meta name=\"description\" content=\""<<title<<"\">\n";
985 s << "<meta name=\"generator\" content=\"\">\n";
986 s << "<link title=\"Top\" rel=\"top\" href=\"#Top\">\n";
987 //<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
988 s << "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><style type=\"text/css\"><!--\n";
989 s << "pre.display { font-family:inherit }\n";
990 s << "pre.format { font-family:inherit }\n";
991 s << "pre.smalldisplay { font-family:inherit; font-size:smaller }\n";
992 s << "pre.smallformat { font-family:inherit; font-size:smaller }\n";
993 s << "pre.smallexample { font-size:smaller }\n";
994 s << "pre.smalllisp { font-size:smaller }\n";
995 s << "span.sc { font-variant:small-caps }\n";
996 s << "span.roman { font-family:serif; font-weight:normal; } \n";
997 s << "span.sansserif { font-family:sans-serif; font-weight:normal; }\n";
998 s << "--></style>\n";
1000 //----------------------
1002 //----------------------
1005 s << "<a name=\"Top\"></a>\n";
1006 s << "<h1 class=\"settitle\">"<<title<<"</h1>\n";
1008 IndexType::iterator ii;
1009 for (ii=index.begin();ii!=index.end();++ii)
1011 s << "<a href=\"#"<<ii->first<<"\">"<<ii->first<<"</a> ";
1014 for (ii=index.begin();ii!=index.end();++ii)
1017 s << "<p><a href=\"#Top\">Top</a>";
1020 s << "<a name=\""<<ii->first<<"\"></a>\n";
1021 s << "<p><a href=\""<<ii->first<<"/index.html\">"
1022 << ii->first<<"</a>\n";
1026 s << "<a name=\""<<ii->first<<"\"></a>\n";
1027 s << "<p><b>"<<ii->first<<"</b>\n";
1031 s << "<p><TABLE cellspacing=0 cellpadding=3>\n";
1033 std::vector<BlackBoxDescriptor*>::iterator di;
1034 for (di=ii->second.begin();di!=ii->second.end();++di)
1036 std::string pack = (*di)->GetPackage()->GetName();
1037 std::string name = (*di)->GetTypeName();
1038 Utilities::html_format(name);
1039 std::string descr = (*di)->GetDescription();
1040 Utilities::html_format(descr);
1042 s << "<TD style='vertical-align: top;'>";
1043 s << " <a href=\""<<pack
1044 <<"/index.html#"<<name<<"\">"
1045 <<pack<<"::"<<name<<"</a>";
1047 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1054 //----------------------
1059 ptm = gmtime ( &rawtime );
1062 s << "Automatically generated by <b>bbi</b> on "
1063 << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900
1064 << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n";
1065 s << "</body></html>\n";
1067 //----------------------
1070 bbtkDebugDecTab("Kernel",9);