1 /*=========================================================================
3 Module: $RCSfile: bbtkFactory.cxx,v $
5 Date: $Date: 2009/05/28 14:22:10 $
6 Version: $Revision: 1.44 $
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 /// Displays the list of packages loaded
394 void Factory::PrintPackages(bool details, bool adaptors) const
396 bbtkDebugMessageInc("kernel",9,"Factory::PrintPackages"<<std::endl);
398 PackageMapType::const_iterator i;
399 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
401 bbtkMessage("help",1, i->first << std::endl);
403 i->second->PrintBlackBoxes(false,adaptors);
407 bbtkDebugDecTab("kernel",9);
409 //===================================================================
411 //===================================================================
412 /// Displays help on a package
413 void Factory::HelpPackage(const std::string& name, bool adaptors) const
415 bbtkDebugMessageInc("kernel",9,"Factory::HelpPackage(\""<<name<<"\")"
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->GetNumberOfBlackBoxes()>0)
437 bbtkMessage("help",1, "Black boxes : "<<std::endl);
438 i->second->PrintBlackBoxes(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::HelpBlackBox(const std::string& name,
460 std::string& package,
463 bbtkDebugMessageInc("kernel",9,"Factory::HelpBlackBox(\""<<name<<"\")"
467 PackageMapType::const_iterator i;
468 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
470 if (i->second->ContainsBlackBox(name))
472 i->second->HelpBlackBox(name,full);
473 package = i->second->GetName();
478 bbtkDebugDecTab("kernel",9);
481 bbtkError("No package of the factory contains any black box <"
485 //===================================================================
488 //===================================================================
489 /// Inserts a package in the factory
490 void Factory::InsertPackage( Package::Pointer p )
492 bbtkDebugMessageInc("kernel",9,"Factory::InsertPackage(\""<<
493 p->GetName()<<"\")"<<std::endl);
495 p->AddFactory(GetThisPointer<Factory>());
496 mPackageMap[p->GetName()] = p;
498 bbtkDebugDecTab("kernel",9);
500 //===================================================================
502 //===================================================================
503 /// Removes a package from the factory (and deletes it)
504 void Factory::RemovePackage( Package::Pointer p )
506 bbtkDebugMessageInc("kernel",9,"Factory::RemovePackage(\""<<
507 p->GetName()<<"\")"<<std::endl);
509 PackageMapType::iterator i;
510 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
512 if (i->second == p) break;
515 if (i!=mPackageMap.end())
521 bbtkError("Factory::RemovePackage(\""<<
522 p->GetName()<<"\") : package absent from factory");
525 bbtkDebugDecTab("kernel",9);
527 //===================================================================
530 //===================================================================
531 /// Creates an instance of a black box of type <type> with name <name>
532 BlackBox::Pointer Factory::NewBlackBox(const std::string& type,
533 const std::string& name) const
535 bbtkDebugMessageInc("kernel",7,"Factory::NewBlackBox(\""
536 <<type<<"\",\""<<name<<"\")"<<std::endl);
539 PackageMapType::const_iterator i;
540 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
542 b = i->second->NewBlackBox(type,name);
547 bbtkError("black box type \""<<type<<"\" unknown");
550 bbtkDebugDecTab("kernel",7);
553 //===================================================================
555 //===================================================================
556 /// Creates an instance of a black box of type <type> with name <name>
557 BlackBox::Pointer Factory::NewAdaptor(const DataInfo& typein,
558 const DataInfo& typeout,
559 const std::string& name) const
561 bbtkDebugMessageInc("kernel",8,"Factory::NewAdaptor("
564 <<name<<"\")"<<bbtkendl);
568 PackageMapType::const_iterator i;
569 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
571 b = i->second->NewAdaptor(typein,typeout,name);
576 bbtkError("no "<<typein<<" to "<<typeout
577 <<" adaptor available");
580 bbtkDebugDecTab("kernel",7);
583 //===================================================================
586 //===================================================================
587 /// Creates an instance of a black box of type <type> with name <name>
588 BlackBox::Pointer Factory::NewWidgetAdaptor(const DataInfo& typein,
589 const DataInfo& typeout,
590 const std::string& name) const
592 bbtkDebugMessageInc("kernel",8,"Factory::NewWidgetAdaptor(<"
595 <<name<<"\")"<<bbtkendl);
599 PackageMapType::const_iterator i;
600 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
602 b = i->second->NewWidgetAdaptor(typein,
609 bbtkError("no "<<typein<<" to "<<typeout
610 <<"> widget adaptor available");
613 bbtkDebugDecTab("kernel",7);
616 //===================================================================
618 //===================================================================
619 /// Creates an instance of a black box of type <type> with name <name>
620 bool Factory::FindAdaptor(const DataInfo& typein,
621 const DataInfo& typeout,
622 std::string& adaptor) const
624 bbtkDebugMessageInc("kernel",8,"Factory::FindAdaptor(<"
626 <<typeout<<">)"<<bbtkendl);
629 PackageMapType::const_iterator i;
630 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
632 b = i->second->FindAdaptor(typein,
640 bbtkError("no "<<typein<<" to "<<typeout
641 <<"> widget adaptor available");
645 bbtkDebugDecTab("kernel",7);
648 //===================================================================
650 //===================================================================
651 /// Creates an instance of a black box of type <type> with name <name>
652 bool Factory::FindWidgetAdaptor(const DataInfo& typein,
653 const DataInfo& typeout,
654 std::string& adaptor) const
656 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
658 <<typeout<<">)"<<bbtkendl);
661 PackageMapType::const_iterator i;
662 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
664 b = i->second->FindWidgetAdaptor(typein,
669 bbtkDebugDecTab("kernel",7);
672 //===================================================================
674 //===================================================================
675 /// Creates an instance of a black box of type <type> with name <name>
676 bool Factory::FindWidgetAdaptor2(const DataInfo& typein,
677 const DataInfo& typeout,
679 std::string& adaptor) const
681 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
683 <<typeout<<">)"<<bbtkendl);
686 adaptor = widget = "";
687 PackageMapType::const_iterator i;
688 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
690 b = i->second->FindWidgetAdaptor(typein,
697 // Look for a widget adaptor with good nature out
698 bbtkMessage("kernel",5,
699 "*** Looking for a two pieces widget adaptor for : "
700 << typein << "->"<<typeout<<std::endl);
701 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
703 Package::AdaptorMapType::const_iterator j;
704 for (j=i->second->GetAdaptorMap().begin();
705 j!=i->second->GetAdaptorMap().end();
708 if ( ( j->first.mKind ==
709 BlackBoxDescriptor::DEFAULT_GUI) &&
710 //(j->first.mTypeIn == typein) &&
711 (j->first.mTypeOut.GetNature() == typeout.GetNature() )
714 widget = j->second.lock()->GetTypeName();
715 bbtkMessage("kernel",5,
716 "===> Found first part : "<<widget
717 << " "<<j->first.mTypeIn<<"->"
718 <<j->first.mTypeOut<<std::endl);
719 DataInfo ti( j->first.mTypeOut.GetType(), "");
720 DataInfo to( typeout.GetType(), "");
721 b = FindAdaptor( ti, to, adaptor );
724 bbtkMessage("kernel",5,
725 "===> Found second part : "<<adaptor
731 bbtkMessage("kernel",5,
732 "===> No second part found"<<std::endl);
739 bbtkDebugDecTab("kernel",7);
742 //===================================================================
744 //===================================================================
745 /// Creates an instance of a connection
746 Connection::Pointer Factory::NewConnection(BlackBox::Pointer from,
747 const std::string& output,
748 BlackBox::Pointer to,
749 const std::string& input) const
751 bbtkDebugMessage("kernel",7,"Factory::NewConnection(\""
752 <<from->bbGetName()<<"\",\""<<output<<"\",\""
753 <<to->bbGetName()<<"\",\""<<input
756 return Connection::New(from,output,to,input,
757 GetThisPointer<Factory>());
759 //===================================================================
763 //===================================================================
764 Package::Pointer Factory::GetPackage(const std::string& name) const
766 bbtkDebugMessageInc("kernel",9,"Factory::GetPackage(\""<<name<<"\")"
769 PackageMapType::const_iterator i = mPackageMap.find(name);
770 if ( i != mPackageMap.end() )
772 bbtkDebugDecTab("kernel",9);
777 bbtkDebugDecTab("kernel",9);
778 bbtkError("package \""<<name<<"\" unknown");
781 bbtkDebugDecTab("kernel",9);
783 //===================================================================
786 //===================================================================
787 void Factory::CheckPackages() const
789 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
791 PackageMapType::const_iterator i;
792 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
794 i->second->CheckBoxes();
796 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
797 <<" ... OK"<<std::endl);
799 //===================================================================
801 //===================================================================
802 void Factory::WriteDotFilePackagesList(FILE *ff)
805 bbtkDebugMessageInc("kernel",9,"Factory::WriteDotFilePackagesList()"
809 fprintf( ff , "subgraph cluster_FACTORY {\n");
810 fprintf( ff , " label = \"PACKAGES\"%s\n", ";");
811 fprintf( ff , " style=filled%s\n",";");
812 fprintf( ff , " color=lightgrey%s\n",";");
813 fprintf( ff , " rankdir=TB%s\n",";");
816 PackageMapType::const_iterator i;
817 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
819 url=GetPackage(i->first)->GetDocURL();
820 fprintf(ff," %s [shape=ellipse, URL=\"%s\"]%s\n",i->first.c_str(),url.c_str(),";" );
822 fprintf( ff , "}\n\n");
823 bbtkDebugDecTab("kernel",9);
825 //===================================================================
828 void Factory::ShowGraphTypes(const std::string& name) const
832 PackageMapType::const_iterator i;
833 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
835 if (i->second->ContainsBlackBox(name))
837 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
839 // Don't pollute the file store with "temp_dir" directories ...
840 std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
841 std::string directory = "\"" + default_doc_dir + separator + "temp_dir" +separator + "\"";
842 std::string filename2 = default_doc_dir + separator + "temp_dir" + separator + "tmp.html";
845 std::string command("start \"Titre\" /D ");
847 std::string command("gnome-open ");
849 command=command + directory +" tmp.html";
851 ff=fopen(filename2.c_str(),"w");
853 fprintf(ff,"<html><head><title>TMP</title> <script type=\"text/javascript\"> <!--\n");
854 fprintf(ff," window.location=\"%s#%s\";\n" , i->second->GetDocURL().c_str(),name.c_str() );
855 fprintf(ff,"//--></script></head><body></body></html>\n");
858 //fprintf(ff, "<a href=\"%s#%s\">Link</a>\n", i->second->GetDocURL().c_str(),name.c_str() );
860 system( command.c_str() );
865 bbtkDebugDecTab("kernel",9);
868 bbtkError("No package of the factory contains any black box <"
876 void Factory::CreateHtmlIndex(IndexEntryType type,
877 const std::string& filename)
879 bbtkDebugMessageInc("kernel",9,"Factory::CreateHtmlIndex(\""
880 <<filename<<"\")"<<bbtkendl);
884 typedef std::map<std::string,
885 std::vector<BlackBoxDescriptor::Pointer> > IndexType;
887 // Builds the index map
888 PackageMapType::const_iterator i;
889 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
891 Package::Pointer pack = i->second;
892 if (pack->GetName()=="user") continue;
893 Package::BlackBoxMapType::const_iterator j;
894 for (j = pack->GetBlackBoxMap().begin();
895 j!= pack->GetBlackBoxMap().end();
900 if ( type==Adaptors )
902 if (j->second->GetKind() == BlackBoxDescriptor::STANDARD )
906 if (j->second->GetKind() != BlackBoxDescriptor::STANDARD )
909 std::vector<std::string> keys;
913 k += pack->GetName();
915 title = "Boxes by package";
917 else if ((type==Initials) || (type==Adaptors))
919 std::string init(" ");
920 init[0] = std::toupper(j->second->GetTypeName()[0]);
921 keys.push_back(init);
922 title = "Alphabetical list";
924 else if (type==Categories)
926 // Split the category string
927 std::string delimiters = ";,";
928 Utilities::SplitString(j->second->GetCategory(),
931 keys.push_back(" NONE");
932 title = "Boxes by category";
936 std::vector<std::string>::const_iterator k;
937 for (k=keys.begin(); k!=keys.end(); ++k )
939 IndexType::iterator p;
941 if (p != index.end())
943 p->second.push_back(j->second);
947 std::vector<BlackBoxDescriptor::Pointer> v;
948 v.push_back(j->second);
956 //---------------------
959 s.open(filename.c_str());
962 bbtkError("Factory::CreateHtmlIndex : could not open file '"
966 //----------------------
968 s << "<html lang=\"en\">\n";
970 s << "<title>"<<title<<"</title>\n";
971 s << "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n";
972 s << "<meta name=\"description\" content=\""<<title<<"\">\n";
973 s << "<meta name=\"generator\" content=\"\">\n";
974 s << "<link title=\"Top\" rel=\"top\" href=\"#Top\">\n";
975 //<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
976 s << "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><style type=\"text/css\"><!--\n";
977 s << "pre.display { font-family:inherit }\n";
978 s << "pre.format { font-family:inherit }\n";
979 s << "pre.smalldisplay { font-family:inherit; font-size:smaller }\n";
980 s << "pre.smallformat { font-family:inherit; font-size:smaller }\n";
981 s << "pre.smallexample { font-size:smaller }\n";
982 s << "pre.smalllisp { font-size:smaller }\n";
983 s << "span.sc { font-variant:small-caps }\n";
984 s << "span.roman { font-family:serif; font-weight:normal; } \n";
985 s << "span.sansserif { font-family:sans-serif; font-weight:normal; }\n";
986 s << "--></style>\n";
988 //----------------------
990 //----------------------
993 s << "<a name=\"Top\"></a>\n";
994 s << "<h1 class=\"settitle\">"<<title<<"</h1>\n";
996 IndexType::iterator ii;
997 for (ii=index.begin();ii!=index.end();++ii)
999 s << "<a href=\"#"<<ii->first<<"\">"<<ii->first<<"</a> ";
1002 for (ii=index.begin();ii!=index.end();++ii)
1005 s << "<p><a href=\"#Top\">Top</a>";
1008 s << "<a name=\""<<ii->first<<"\"></a>\n";
1009 s << "<p><a href=\""<<ii->first<<"/index.html\">"
1010 << ii->first<<"</a>\n";
1012 s << " - \n";
1014 s << "<a name=\"doxygen\"></a>\n";
1016 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1017 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1021 s << "<a name=\""<<ii->first<<"\"></a>\n";
1022 s << "<p><b>"<<ii->first<<"</b>\n";
1026 s << "<p><TABLE cellspacing=0 cellpadding=3>\n";
1028 std::vector<BlackBoxDescriptor::Pointer>::iterator di;
1029 for (di=ii->second.begin();di!=ii->second.end();++di)
1031 std::string pack = (*di)->GetPackage()->GetName();
1032 std::string name = (*di)->GetTypeName();
1033 Utilities::html_format(name);
1034 std::string descr = (*di)->GetDescription();
1035 Utilities::html_format(descr);
1037 s << "<TD style='vertical-align: top;'>";
1038 s << " <a href=\""<<pack
1039 <<"/index.html#"<<name<<"\">"
1040 <<pack<<"::"<<name<<"</a>";
1042 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1049 //----------------------
1054 ptm = gmtime ( &rawtime );
1057 s << "Automatically generated by <b>bbtk</b> on "
1058 << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900
1059 << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n";
1060 s << "</body></html>\n";
1062 //----------------------
1065 bbtkDebugDecTab("kernel",9);
1068 //==========================================================================
1069 std::string Factory::GetObjectName() const
1071 return std::string("Factory");
1073 //==========================================================================
1075 //==========================================================================
1076 std::string Factory::GetObjectInfo() const
1078 std::stringstream i;
1081 //==========================================================================
1083 //==========================================================================
1084 size_t Factory::GetObjectSize() const
1086 size_t s = Superclass::GetObjectSize();
1087 s += Factory::GetObjectInternalSize();
1090 //==========================================================================
1091 //==========================================================================
1092 size_t Factory::GetObjectInternalSize() const
1094 size_t s = sizeof(Factory);
1097 //==========================================================================
1098 //==========================================================================
1099 size_t Factory::GetObjectRecursiveSize() const
1101 size_t s = Superclass::GetObjectRecursiveSize();
1102 s += Factory::GetObjectInternalSize();
1104 PackageMapType::const_iterator i;
1105 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
1107 s += i->second->GetObjectRecursiveSize();
1111 //==========================================================================