1 /*=========================================================================
3 Module: $RCSfile: bbtkFactory.cxx,v $
5 Date: $Date: 2009/06/08 14:50:03 $
6 Version: $Revision: 1.45 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 *\brief Class bbtk::Factory : can load and unload dynamic libraries containing
34 * black boxes packages and create instances of the black boxes registered
35 * in the packages loaded.
37 #include "bbtkFactory.h"
38 #include "bbtkMessageManager.h"
39 #include "bbtkConnection.h"
40 #include "bbtkConfigurationFile.h"
41 #include "bbtkUtilities.h"
42 #include "bbtkConfigurationFile.h"
44 #include <sys/stat.h> // for struct stat stFileInfo
47 #include <direct.h> // for getcwd
50 #include <cctype> // std::toupper
57 //===================================================================
59 Factory::Pointer Factory::New()
61 bbtkDebugMessage("kernel",9,"Factory::New()"<<std::endl);
62 return MakePointer(new Factory());
64 //===================================================================
66 //===================================================================
71 bbtkDebugMessage("kernel",7,"Factory()"<<std::endl);
73 //===================================================================
75 //===================================================================
79 bbtkDebugMessage("kernel",7,"==> ~Factory()"<<std::endl);
81 bbtkDebugMessage("kernel",7,"<== ~Factory()"<<std::endl);
83 //===================================================================
87 //===================================================================
90 bbtkDebugMessage("kernel",7,"==> Factory::Reset()"<<std::endl);
92 bbtkDebugMessage("kernel",7,"<== Factory::Reset()"<<std::endl);
94 //===================================================================
97 // ===================================================================
98 bool Factory::DoLoadPackage(std::string libname,
103 Package::Pointer p = Package::CreateFromDynamicLibrary(libname,
108 //===================================================================
109 bbtkMessage("output",2,p->GetName()<<" "
112 <<p->GetAuthor() << " Category(s) :"
115 bbtkMessage("output",2,p->GetDescription()<<std::endl);
116 //===================================================================
117 p->AddFactory(GetThisPointer<Factory>());
118 mPackageMap[pkgname] = p;
125 //===================================================================
126 /// \brief Loads a package.
128 /// The name is the system-independant name of the package (the name of the instance of bbtk::Package).
129 /// Tries to open the dynamic library :
130 /// - "libbb<name>.so" for linux systems,
131 /// - "bb<name>.dll" for windows systems.
132 /// If it succeeds, then tries to load the symbols "<name>GetPackage" and "<name>DeletePackage".
133 /// "<name>GetPackage" is called to get the pointer on the bbtk::Package of the library
134 /// ("<name>DeletePackage" is not used, its presence is just checked before loading the package).
136 /// now, filename is only the last name (no longer the full name!)
137 /// it will be searched within *all* the paths given in bbtk_config.xml
141 void Factory::LoadPackage( const std::string& name )
143 // Note : in the following :
144 // name : the user supplied name
145 // - abreviated name e.g. pkg pkg.so libbpkg libbbpkg.so
146 // - relative full name e.g. ./libbbpkg.so ../../libbbpkg.so
147 // - absolute full name e.g. /home/usrname/proj/lib/libbbpkg.so
148 // same for Windows, with c:, d: ...
150 // lastname : string before the last / (if any), or user supplied name
152 bbtkDebugMessageInc("kernel",7,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
153 bbtkMessage("debug",1,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
155 std::vector<std::string> package_paths;
156 std::string libname; // full path library name
157 std::string pkgname; // e.g. libbb<pkgname>.so
160 pkgname = Utilities::ExtractPackageName(name,upath);
162 bbtkMessage("debug",1,"Package name ["<<pkgname<<"]"<<std::endl);
163 bbtkMessage("debug",1,"Package path ["<<upath<<"]"<<std::endl);
165 // no loading package if already loaded
166 PackageMapType::iterator iUnload;
167 iUnload = mPackageMap.find(pkgname);
168 if (iUnload != mPackageMap.end())
170 bbtkMessage("output",2,"["<< pkgname <<"] already loaded" << std::endl);
174 // =================================================
175 // The following structure was checked to work
176 // with any type of relative/absolute path.
177 // Please don't modify it without checking
178 // *all* the cases. JP
179 //==================================================
181 //std::cout << "upath [" << upath << "]" << std::endl;
184 bool foundFile = false;
186 // If path provided by user will be the first scanned :
187 // push it into vector of paths
188 if (upath.length()>0) // ------------------------------------- check user supplied location
190 if (name[0] != '.' && name[0] != '/' && name[1]!= ':')
192 bbtkError("Use absolute or relative path name! ["<<name<<"] is an illegal name");
196 // std::string path = Utilities::ExpandLibName(upath, false);
197 std::string path = Utilities::ExpandLibName(name,false); // keep last item, here.
202 Utilities::ExtractPackageName(path,p2);
203 //libname = Utilities::MakeLibnameFromPath(path, pkgname);
204 libname = Utilities::MakeLibnameFromPath(p2, pkgname); // remove last item
205 // Check if library exists
206 if ( !Utilities::FileExists(libname) )
208 // The following is *NOT* a debug time message :
209 // It's a user intended message.
210 // Please don't remove it.
211 bbtkMessage("output",3," [" <<libname
212 <<"] : doesn't exist" <<std::endl);
216 ok = DoLoadPackage( libname, pkgname, path);
221 bbtkError("Path ["<<upath<<"] doesn't exist");
225 else // ----------------------------------------------------- iterate on the paths
229 package_paths = ConfigurationFile::GetInstance().Get_package_paths();
230 std::vector<std::string>::iterator i;
231 for (i=package_paths.begin();i!=package_paths.end();++i)
236 // we *really* want '.' to be the current working directory
239 char buf[2048]; // for getcwd
240 char * currentDir = getcwd(buf, 2048);
241 std::string cwd(currentDir);
245 libname = Utilities::MakeLibnameFromPath(path, pkgname);
247 bbtkMessage("debug",2,"-> Trying to load [" << libname << "]" <<std::endl);
249 // Check if library exists
250 if ( !Utilities::FileExists(libname) )
252 // The following is *NOT* a debug time message :
253 // It's a user intended message.
254 // Please don't remove it.
255 bbtkMessage("output",3,
256 " [" <<libname <<"] : doesn't exist" <<std::endl);
257 continue; // try next path
261 // Try to Load the library
263 ok = DoLoadPackage( libname, pkgname, path);
266 bbtkMessage("debug",2," OK"<<std::endl);
268 break; // we stop iterating even if error : have to signal it to user
269 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
273 if( !ok ) // nothing was loaded
277 bbtkError("Could not find package ["<<pkgname<< "]");
281 #if defined(__GNUC__)
282 bbtkError("Could not load package ["<< pkgname
284 << " Opening "<<libname<<" failed"
285 << " Reason: "<< dlerror());
286 #elif defined(_WIN32)
287 bbtkError("Could not load package ["<<pkgname
288 <<"] :"<< std::endl << " Error loading " <<libname);
290 // look how to get the error message on win
292 // it is the bordel !! (the bloody fucking bordel, you mean?)
293 // look : http://msdn2.microsoft.com/en-us/library/ms680582.aspx
297 bbtkMessage("output",2,"[" << libname << "] loaded" << std::endl);
301 //===================================================================
302 /// \brief UnLoads a package.
304 /// The package must have been previously loaded by LoadPackage.
305 /// If the entry is found in the map, calls ClosePackage
306 void Factory::UnLoadPackage( const std::string& name )
308 bbtkDebugMessageInc("kernel",7,"Factory::UnLoadPackage(\""
309 <<name<<"\")"<<std::endl);
311 PackageMapType::iterator i;
312 i = mPackageMap.find(name);
313 if (i == mPackageMap.end())
315 bbtkError("cannot unload package \""<<name
316 <<"\" : package not loaded !");
319 bbtkDebugDecTab("kernel",7);
321 //===================================================================
324 //===================================================================
325 void Factory::CloseAllPackages()
327 bbtkDebugMessageInc("kernel",7,"Factory::CloseAllPackages()"<<std::endl);
329 std::vector< Package::WeakPointer > mAlive;
332 while (mPackageMap.begin() != mPackageMap.end())
334 PackageMapType::iterator i = mPackageMap.begin();
335 Package::WeakPointer p = i->second;
337 if (p.lock()) mAlive.push_back(p);
339 std::vector< Package::WeakPointer >::iterator i;
340 for (i=mAlive.begin();i!=mAlive.end();++i)
342 // If not dead : reinsert
345 bbtkDebugMessage("kernel",7,"Package "<<i->lock()->GetName()
346 <<" still alive"<<std::endl);
347 // InsertPackage(i->lock());
351 while (mPackageMap.size()>0);
353 bbtkDebugDecTab("kernel",7);
355 //===================================================================
357 //===================================================================
358 /// \brief Close the package referenced by the iterator
360 /// First removes the factory from the set of factories which use the package
361 /// If the set is empty then :
362 /// If it is a dynamically loaded package :
363 /// - Loads and calls the function "<name>DeletePackage" of the dynamic library (responsible for package desallocation)
364 /// - Closes the dynamic library
366 /// - deletes the package normally
368 /// Finally erases the package entry in the packages map
369 void Factory::ClosePackage(PackageMapType::iterator& i)
371 bbtkDebugMessageInc("kernel",7,"Factory::ClosePackage(\""
372 <<i->second->GetName()
376 // Removes this from the set of factories which use the package
377 i->second->RemoveFactory(GetThisPointer<Factory>());
378 Package::WeakPointer p = i->second;
379 // remove the entry in the map
380 mPackageMap.erase(i);
381 // Release the package if not already destroyed
386 bbtkDebugDecTab("kernel",7);
388 //===================================================================
392 //===================================================================
393 void Factory::PrintHelpListPackages(bool details, bool adaptors) const
395 bbtkDebugMessageInc("kernel",9,"Factory::PrintPackages"<<std::endl);
397 PackageMapType::const_iterator i;
398 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
400 bbtkMessage("help",1, i->first << std::endl);
402 i->second->PrintHelpListDescriptors(false,adaptors);
406 bbtkDebugDecTab("kernel",9);
408 //===================================================================
410 //===================================================================
411 /// Displays help on a package
412 void Factory::PrintHelpPackage(const std::string& name, bool adaptors) const
414 bbtkDebugMessageInc("kernel",9,"Factory::PrintHelpPackage(\""
418 PackageMapType::const_iterator i = mPackageMap.find(name);
419 if ( i != mPackageMap.end() )
421 bbtkMessage("help",1, "Package "<<i->first<<" ");
423 if (i->second->GetVersion().length()>0)
424 bbtkMessageCont("help",1,"v" <<i->second->GetVersion());
426 if (i->second->GetAuthor().length()>0)
427 bbtkMessageCont("help",1,"- "<<i->second->GetAuthor());
429 if (i->second->GetCategory().length()>0)
430 bbtkMessageCont("help",1,"- "<<i->second->GetCategory());
432 bbtkMessageCont("help",1,std::endl);
433 bbtkIncTab("help",1);
434 bbtkMessage("help",1,i->second->GetDescription()<<std::endl);
435 if (i->second->GetNumberOfDescriptors()>0)
437 bbtkMessage("help",1, "Black boxes : "<<std::endl);
438 i->second->PrintHelpListDescriptors(true,adaptors);
442 bbtkMessage("help",1, "No black boxes"<<std::endl);
444 bbtkDecTab("help",1);
448 bbtkDebugDecTab("kernel",9);
449 bbtkError("package \""<<name<<"\" unknown");
452 bbtkDebugDecTab("kernel",9);
454 //===================================================================
456 //===================================================================
457 /// Prints help on the black box of type <name>
458 /// Returns the package to which it belongs
459 void Factory::PrintHelpDescriptor(const std::string& name,
460 std::string& package,
463 bbtkDebugMessageInc("kernel",9,"Factory::PrintHelpDescriptor(\""
468 PackageMapType::const_iterator i;
469 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
471 if (i->second->ContainsDescriptor(name))
473 i->second->PrintHelpDescriptor(name,full);
474 package = i->second->GetName();
479 bbtkDebugDecTab("kernel",9);
482 bbtkError("No package of the factory contains any black box <"
486 //===================================================================
489 //===================================================================
490 /// Inserts a package in the factory
491 void Factory::InsertPackage( Package::Pointer p )
493 bbtkDebugMessageInc("kernel",9,"Factory::InsertPackage(\""<<
494 p->GetName()<<"\")"<<std::endl);
496 p->AddFactory(GetThisPointer<Factory>());
497 mPackageMap[p->GetName()] = p;
499 bbtkDebugDecTab("kernel",9);
501 //===================================================================
503 //===================================================================
504 /// Removes a package from the factory (and deletes it)
505 void Factory::RemovePackage( Package::Pointer p )
507 bbtkDebugMessageInc("kernel",9,"Factory::RemovePackage(\""<<
508 p->GetName()<<"\")"<<std::endl);
510 PackageMapType::iterator i;
511 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
513 if (i->second == p) break;
516 if (i!=mPackageMap.end())
522 bbtkError("Factory::RemovePackage(\""<<
523 p->GetName()<<"\") : package absent from factory");
526 bbtkDebugDecTab("kernel",9);
528 //===================================================================
531 //===================================================================
532 /// Creates an instance of a black box of type <type> with name <name>
533 BlackBox::Pointer Factory::NewBlackBox(const std::string& type,
534 const std::string& name) const
536 bbtkDebugMessageInc("kernel",7,"Factory::NewBlackBox(\""
537 <<type<<"\",\""<<name<<"\")"<<std::endl);
540 PackageMapType::const_iterator i;
541 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
543 b = i->second->NewBlackBox(type,name);
548 bbtkError("black box type \""<<type<<"\" unknown");
551 bbtkDebugDecTab("kernel",7);
554 //===================================================================
556 //===================================================================
557 /// Creates an instance of a black box of type <type> with name <name>
558 BlackBox::Pointer Factory::NewAdaptor(const DataInfo& typein,
559 const DataInfo& typeout,
560 const std::string& name) const
562 bbtkDebugMessageInc("kernel",8,"Factory::NewAdaptor("
565 <<name<<"\")"<<bbtkendl);
569 PackageMapType::const_iterator i;
570 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
572 b = i->second->NewAdaptor(typein,typeout,name);
577 bbtkError("no "<<typein<<" to "<<typeout
578 <<" adaptor available");
581 bbtkDebugDecTab("kernel",7);
584 //===================================================================
587 //===================================================================
588 /// Creates an instance of a black box of type <type> with name <name>
589 BlackBox::Pointer Factory::NewWidgetAdaptor(const DataInfo& typein,
590 const DataInfo& typeout,
591 const std::string& name) const
593 bbtkDebugMessageInc("kernel",8,"Factory::NewWidgetAdaptor(<"
596 <<name<<"\")"<<bbtkendl);
600 PackageMapType::const_iterator i;
601 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
603 b = i->second->NewWidgetAdaptor(typein,
610 bbtkError("no "<<typein<<" to "<<typeout
611 <<"> widget adaptor available");
614 bbtkDebugDecTab("kernel",7);
617 //===================================================================
619 //===================================================================
620 /// Creates an instance of a black box of type <type> with name <name>
621 bool Factory::FindAdaptor(const DataInfo& typein,
622 const DataInfo& typeout,
623 std::string& adaptor) const
625 bbtkDebugMessageInc("kernel",8,"Factory::FindAdaptor(<"
627 <<typeout<<">)"<<bbtkendl);
630 PackageMapType::const_iterator i;
631 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
633 b = i->second->FindAdaptor(typein,
641 bbtkError("no "<<typein<<" to "<<typeout
642 <<"> widget adaptor available");
646 bbtkDebugDecTab("kernel",7);
649 //===================================================================
651 //===================================================================
652 /// Creates an instance of a black box of type <type> with name <name>
653 bool Factory::FindWidgetAdaptor(const DataInfo& typein,
654 const DataInfo& typeout,
655 std::string& adaptor) const
657 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
659 <<typeout<<">)"<<bbtkendl);
662 PackageMapType::const_iterator i;
663 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
665 b = i->second->FindWidgetAdaptor(typein,
670 bbtkDebugDecTab("kernel",7);
673 //===================================================================
675 //===================================================================
676 /// Creates an instance of a black box of type <type> with name <name>
677 bool Factory::FindWidgetAdaptor2(const DataInfo& typein,
678 const DataInfo& typeout,
680 std::string& adaptor) const
682 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
684 <<typeout<<">)"<<bbtkendl);
687 adaptor = widget = "";
688 PackageMapType::const_iterator i;
689 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
691 b = i->second->FindWidgetAdaptor(typein,
698 // Look for a widget adaptor with good nature out
699 bbtkMessage("kernel",5,
700 "*** Looking for a two pieces widget adaptor for : "
701 << typein << "->"<<typeout<<std::endl);
702 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
704 Package::AdaptorMapType::const_iterator j;
705 for (j=i->second->GetAdaptorMap().begin();
706 j!=i->second->GetAdaptorMap().end();
709 if ( ( j->first.mKind ==
710 BlackBoxDescriptor::DEFAULT_GUI) &&
711 //(j->first.mTypeIn == typein) &&
712 (j->first.mTypeOut.GetNature() == typeout.GetNature() )
715 widget = j->second.lock()->GetTypeName();
716 bbtkMessage("kernel",5,
717 "===> Found first part : "<<widget
718 << " "<<j->first.mTypeIn<<"->"
719 <<j->first.mTypeOut<<std::endl);
720 DataInfo ti( j->first.mTypeOut.GetType(), "");
721 DataInfo to( typeout.GetType(), "");
722 b = FindAdaptor( ti, to, adaptor );
725 bbtkMessage("kernel",5,
726 "===> Found second part : "<<adaptor
732 bbtkMessage("kernel",5,
733 "===> No second part found"<<std::endl);
740 bbtkDebugDecTab("kernel",7);
743 //===================================================================
745 //===================================================================
746 /// Creates an instance of a connection
747 Connection::Pointer Factory::NewConnection(BlackBox::Pointer from,
748 const std::string& output,
749 BlackBox::Pointer to,
750 const std::string& input) const
752 bbtkDebugMessage("kernel",7,"Factory::NewConnection(\""
753 <<from->bbGetName()<<"\",\""<<output<<"\",\""
754 <<to->bbGetName()<<"\",\""<<input
757 return Connection::New(from,output,to,input,
758 GetThisPointer<Factory>());
760 //===================================================================
764 //===================================================================
765 Package::Pointer Factory::GetPackage(const std::string& name) const
767 bbtkDebugMessageInc("kernel",9,"Factory::GetPackage(\""<<name<<"\")"
770 PackageMapType::const_iterator i = mPackageMap.find(name);
771 if ( i != mPackageMap.end() )
773 bbtkDebugDecTab("kernel",9);
778 bbtkDebugDecTab("kernel",9);
779 bbtkError("package \""<<name<<"\" unknown");
782 bbtkDebugDecTab("kernel",9);
784 //===================================================================
787 //===================================================================
788 void Factory::Check() const
790 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
792 PackageMapType::const_iterator i;
793 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
797 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
798 <<" ... OK"<<std::endl);
800 //===================================================================
802 //===================================================================
803 void Factory::WriteDotFilePackagesList(FILE *ff)
806 bbtkDebugMessageInc("kernel",9,"Factory::WriteDotFilePackagesList()"
810 fprintf( ff , "subgraph cluster_FACTORY {\n");
811 fprintf( ff , " label = \"PACKAGES\"%s\n", ";");
812 fprintf( ff , " style=filled%s\n",";");
813 fprintf( ff , " color=lightgrey%s\n",";");
814 fprintf( ff , " rankdir=TB%s\n",";");
817 PackageMapType::const_iterator i;
818 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
820 url=GetPackage(i->first)->GetDocURL();
821 fprintf(ff," %s [shape=ellipse, URL=\"%s\"]%s\n",i->first.c_str(),url.c_str(),";" );
823 fprintf( ff , "}\n\n");
824 bbtkDebugDecTab("kernel",9);
826 //===================================================================
829 void Factory::ShowGraphTypes(const std::string& name) const
833 PackageMapType::const_iterator i;
834 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
836 if (i->second->ContainsDescriptor(name))
838 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
840 // Don't pollute the file store with "temp_dir" directories ...
841 std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
842 std::string directory = "\"" + default_doc_dir + separator + "temp_dir" +separator + "\"";
843 std::string filename2 = default_doc_dir + separator + "temp_dir" + separator + "tmp.html";
846 std::string command("start \"Titre\" /D ");
848 std::string command("gnome-open ");
850 command=command + directory +" tmp.html";
852 ff=fopen(filename2.c_str(),"w");
854 fprintf(ff,"<html><head><title>TMP</title> <script type=\"text/javascript\"> <!--\n");
855 fprintf(ff," window.location=\"%s#%s\";\n" , i->second->GetDocURL().c_str(),name.c_str() );
856 fprintf(ff,"//--></script></head><body></body></html>\n");
859 //fprintf(ff, "<a href=\"%s#%s\">Link</a>\n", i->second->GetDocURL().c_str(),name.c_str() );
861 system( command.c_str() );
866 bbtkDebugDecTab("kernel",9);
869 bbtkError("No package of the factory contains any black box <"
877 void Factory::CreateHtmlIndex(IndexEntryType type,
878 const std::string& filename)
880 bbtkDebugMessageInc("kernel",9,"Factory::CreateHtmlIndex(\""
881 <<filename<<"\")"<<bbtkendl);
885 typedef std::map<std::string,
886 std::vector<BlackBoxDescriptor::Pointer> > IndexType;
888 // Builds the index map
889 PackageMapType::const_iterator i;
890 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
892 Package::Pointer pack = i->second;
893 if (pack->GetName()=="user") continue;
894 Package::DescriptorMapType::const_iterator j;
895 for (j = pack->GetDescriptorMap().begin();
896 j!= pack->GetDescriptorMap().end();
901 if ( type==Adaptors )
903 if (j->second->GetKind() == BlackBoxDescriptor::STANDARD )
907 if (j->second->GetKind() != BlackBoxDescriptor::STANDARD )
910 std::vector<std::string> keys;
914 k += pack->GetName();
916 title = "Boxes by package";
918 else if ((type==Initials) || (type==Adaptors))
920 std::string init(" ");
921 init[0] = std::toupper(j->second->GetTypeName()[0]);
922 keys.push_back(init);
923 title = "Alphabetical list";
925 else if (type==Categories)
927 // Split the category string
928 std::string delimiters = ";,";
929 Utilities::SplitString(j->second->GetCategory(),
932 keys.push_back(" NONE");
933 title = "Boxes by category";
937 std::vector<std::string>::const_iterator k;
938 for (k=keys.begin(); k!=keys.end(); ++k )
940 IndexType::iterator p;
942 if (p != index.end())
944 p->second.push_back(j->second);
948 std::vector<BlackBoxDescriptor::Pointer> v;
949 v.push_back(j->second);
957 //---------------------
960 s.open(filename.c_str());
963 bbtkError("Factory::CreateHtmlIndex : could not open file '"
967 //----------------------
969 s << "<html lang=\"en\">\n";
971 s << "<title>"<<title<<"</title>\n";
972 s << "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n";
973 s << "<meta name=\"description\" content=\""<<title<<"\">\n";
974 s << "<meta name=\"generator\" content=\"\">\n";
975 s << "<link title=\"Top\" rel=\"top\" href=\"#Top\">\n";
976 //<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
977 s << "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><style type=\"text/css\"><!--\n";
978 s << "pre.display { font-family:inherit }\n";
979 s << "pre.format { font-family:inherit }\n";
980 s << "pre.smalldisplay { font-family:inherit; font-size:smaller }\n";
981 s << "pre.smallformat { font-family:inherit; font-size:smaller }\n";
982 s << "pre.smallexample { font-size:smaller }\n";
983 s << "pre.smalllisp { font-size:smaller }\n";
984 s << "span.sc { font-variant:small-caps }\n";
985 s << "span.roman { font-family:serif; font-weight:normal; } \n";
986 s << "span.sansserif { font-family:sans-serif; font-weight:normal; }\n";
987 s << "--></style>\n";
989 //----------------------
991 //----------------------
994 s << "<a name=\"Top\"></a>\n";
995 s << "<h1 class=\"settitle\">"<<title<<"</h1>\n";
997 IndexType::iterator ii;
998 for (ii=index.begin();ii!=index.end();++ii)
1000 s << "<a href=\"#"<<ii->first<<"\">"<<ii->first<<"</a> ";
1003 for (ii=index.begin();ii!=index.end();++ii)
1006 s << "<p><a href=\"#Top\">Top</a>";
1009 s << "<a name=\""<<ii->first<<"\"></a>\n";
1010 s << "<p><a href=\""<<ii->first<<"/index.html\">"
1011 << ii->first<<"</a>\n";
1013 s << " - \n";
1015 s << "<a name=\"doxygen\"></a>\n";
1017 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1018 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1022 s << "<a name=\""<<ii->first<<"\"></a>\n";
1023 s << "<p><b>"<<ii->first<<"</b>\n";
1027 s << "<p><TABLE cellspacing=0 cellpadding=3>\n";
1029 std::vector<BlackBoxDescriptor::Pointer>::iterator di;
1030 for (di=ii->second.begin();di!=ii->second.end();++di)
1032 std::string pack = (*di)->GetPackage()->GetName();
1033 std::string name = (*di)->GetTypeName();
1034 Utilities::html_format(name);
1035 std::string descr = (*di)->GetDescription();
1036 Utilities::html_format(descr);
1038 s << "<TD style='vertical-align: top;'>";
1039 s << " <a href=\""<<pack
1040 <<"/index.html#"<<name<<"\">"
1041 <<pack<<"::"<<name<<"</a>";
1043 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1050 //----------------------
1055 ptm = gmtime ( &rawtime );
1058 s << "Automatically generated by <b>bbtk</b> on "
1059 << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900
1060 << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n";
1061 s << "</body></html>\n";
1063 //----------------------
1066 bbtkDebugDecTab("kernel",9);
1069 //==========================================================================
1070 std::string Factory::GetObjectName() const
1072 return std::string("Factory");
1074 //==========================================================================
1076 //==========================================================================
1077 std::string Factory::GetObjectInfo() const
1079 std::stringstream i;
1082 //==========================================================================
1084 //==========================================================================
1085 size_t Factory::GetObjectSize() const
1087 size_t s = Superclass::GetObjectSize();
1088 s += Factory::GetObjectInternalSize();
1091 //==========================================================================
1092 //==========================================================================
1093 size_t Factory::GetObjectInternalSize() const
1095 size_t s = sizeof(Factory);
1098 //==========================================================================
1099 //==========================================================================
1100 size_t Factory::GetObjectRecursiveSize() const
1102 size_t s = Superclass::GetObjectRecursiveSize();
1103 s += Factory::GetObjectInternalSize();
1105 PackageMapType::const_iterator i;
1106 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
1108 s += i->second->GetObjectRecursiveSize();
1112 //==========================================================================