1 /*=========================================================================
3 Module: $RCSfile: bbtkFactory.cxx,v $
5 Date: $Date: 2009/10/05 22:44:48 $
6 Version: $Revision: 1.46 $
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
153 bbtkDebugMessageInc("kernel",7,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
154 bbtkMessage("debug",1,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
156 std::vector<std::string> package_paths;
157 std::string libname; // full path library name
158 std::string pkgname; // e.g. libbb<pkgname>.so
161 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);
169 if (iUnload != mPackageMap.end())
171 bbtkMessage("output",2,"["<< pkgname <<"] already loaded" << std::endl);
175 // =================================================
176 // The following structure was checked to work
177 // with any type of relative/absolute path.
178 // Please don't modify it without checking
179 // *all* the cases. JP
180 //==================================================
182 //std::cout << "upath [" << upath << "]" << std::endl;
185 bool foundFile = false;
187 // If path provided by user will be the first scanned :
188 // push it into vector of paths
189 if (upath.length()>0) // ------------------------------------- check user supplied location
191 if (name[0] != '.' && name[0] != '/' && name[1]!= ':')
193 bbtkError("Use absolute or relative path name! ["<<name<<"] is an illegal name");
197 // std::string path = Utilities::ExpandLibName(upath, false);
199 std::string path = Utilities::ExpandLibName(name,false); // keep last item, here.
203 Utilities::ExtractPackageName(path,p2);
204 //libname = Utilities::MakeLibnameFromPath(path, pkgname);
205 libname = Utilities::MakeLibnameFromPath(p2, pkgname); // remove last item
206 // Check if library exists
207 if ( !Utilities::FileExists(libname) )
209 // The following is *NOT* a debug time message :
210 // It's a user intended message.
211 // Please don't remove it.
212 bbtkMessage("output",3," [" <<libname
213 <<"] : doesn't exist" <<std::endl);
217 ok = DoLoadPackage( libname, pkgname, path);
222 bbtkError("Path ["<<upath<<"] doesn't exist");
226 else // ----------------------------------------------------- iterate on the paths
229 std::string path = ".";
230 package_paths = ConfigurationFile::GetInstance().Get_package_paths();
231 std::vector<std::string>::iterator i;
232 for (i=package_paths.begin();i!=package_paths.end();++i)
236 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = path "<<path<<std::endl;
237 // we *really* want '.' to be the current working directory
240 char buf[2048]; // for getcwd
241 char * currentDir = getcwd(buf, 2048);
242 std::string cwd(currentDir);
243 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = currentDir "<<currentDir<<std::endl;
246 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = path "<<path<<" pkgnam="<<pkgname<<std::endl;
247 libname = Utilities::MakeLibnameFromPath(path, pkgname);
249 bbtkMessage("debug",2,"-> Trying to load [" << libname << "]" <<std::endl);
251 // Check if library exists
252 if ( !Utilities::FileExists(libname) )
254 // The following is *NOT* a debug time message :
255 // It's a user intended message.
256 // Please don't remove it.
257 bbtkMessage("output",3,
258 " [" <<libname <<"] : doesn't exist" <<std::endl);
259 continue; // try next path
263 // Try to Load the library
265 ok = DoLoadPackage( libname, pkgname, path);
268 bbtkMessage("debug",2," OK"<<std::endl);
270 break; // we stop iterating even if error : have to signal it to user
271 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
275 if( !ok ) // nothing was loaded
279 bbtkError("Could not find package ["<<pkgname<< "]");
283 #if defined(__GNUC__)
284 bbtkError("Could not load package ["<< pkgname
286 << " Opening "<<libname<<" failed"
287 << " Reason: "<< dlerror());
288 #elif defined(_WIN32)
289 bbtkError("Could not load package ["<<pkgname
290 <<"] :"<< std::endl << " Error loading " <<libname);
292 // look how to get the error message on win
294 // it is the bordel !! (the bloody fucking bordel, you mean?)
295 // look : http://msdn2.microsoft.com/en-us/library/ms680582.aspx
299 bbtkMessage("output",2,"[" << libname << "] loaded" << std::endl);
306 //===================================================================
307 /// \brief UnLoads a package.
309 /// The package must have been previously loaded by LoadPackage.
310 /// If the entry is found in the map, calls ClosePackage
311 void Factory::UnLoadPackage( const std::string& name )
313 bbtkDebugMessageInc("kernel",7,"Factory::UnLoadPackage(\""
314 <<name<<"\")"<<std::endl);
316 PackageMapType::iterator i;
317 i = mPackageMap.find(name);
318 if (i == mPackageMap.end())
320 bbtkError("cannot unload package \""<<name
321 <<"\" : package not loaded !");
324 bbtkDebugDecTab("kernel",7);
326 //===================================================================
329 //===================================================================
330 void Factory::CloseAllPackages()
332 bbtkDebugMessageInc("kernel",7,"Factory::CloseAllPackages()"<<std::endl);
334 std::vector< Package::WeakPointer > mAlive;
337 while (mPackageMap.begin() != mPackageMap.end())
339 PackageMapType::iterator i = mPackageMap.begin();
340 Package::WeakPointer p = i->second;
342 if (p.lock()) mAlive.push_back(p);
344 std::vector< Package::WeakPointer >::iterator i;
345 for (i=mAlive.begin();i!=mAlive.end();++i)
347 // If not dead : reinsert
350 bbtkDebugMessage("kernel",7,"Package "<<i->lock()->GetName()
351 <<" still alive"<<std::endl);
352 // InsertPackage(i->lock());
356 while (mPackageMap.size()>0);
358 bbtkDebugDecTab("kernel",7);
360 //===================================================================
362 //===================================================================
363 /// \brief Close the package referenced by the iterator
365 /// First removes the factory from the set of factories which use the package
366 /// If the set is empty then :
367 /// If it is a dynamically loaded package :
368 /// - Loads and calls the function "<name>DeletePackage" of the dynamic library (responsible for package desallocation)
369 /// - Closes the dynamic library
371 /// - deletes the package normally
373 /// Finally erases the package entry in the packages map
374 void Factory::ClosePackage(PackageMapType::iterator& i)
376 bbtkDebugMessageInc("kernel",7,"Factory::ClosePackage(\""
377 <<i->second->GetName()
381 // Removes this from the set of factories which use the package
382 i->second->RemoveFactory(GetThisPointer<Factory>());
383 Package::WeakPointer p = i->second;
384 // remove the entry in the map
385 mPackageMap.erase(i);
386 // Release the package if not already destroyed
391 bbtkDebugDecTab("kernel",7);
393 //===================================================================
397 //===================================================================
398 void Factory::PrintHelpListPackages(bool details, bool adaptors) const
400 bbtkDebugMessageInc("kernel",9,"Factory::PrintPackages"<<std::endl);
402 PackageMapType::const_iterator i;
403 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
405 bbtkMessage("help",1, i->first << std::endl);
407 i->second->PrintHelpListDescriptors(false,adaptors);
411 bbtkDebugDecTab("kernel",9);
413 //===================================================================
415 //===================================================================
416 /// Displays help on a package
417 void Factory::PrintHelpPackage(const std::string& name, bool adaptors) const
419 bbtkDebugMessageInc("kernel",9,"Factory::PrintHelpPackage(\""
423 PackageMapType::const_iterator i = mPackageMap.find(name);
424 if ( i != mPackageMap.end() )
426 bbtkMessage("help",1, "Package "<<i->first<<" ");
428 if (i->second->GetVersion().length()>0)
429 bbtkMessageCont("help",1,"v" <<i->second->GetVersion());
431 if (i->second->GetAuthor().length()>0)
432 bbtkMessageCont("help",1,"- "<<i->second->GetAuthor());
434 if (i->second->GetCategory().length()>0)
435 bbtkMessageCont("help",1,"- "<<i->second->GetCategory());
437 bbtkMessageCont("help",1,std::endl);
438 bbtkIncTab("help",1);
439 bbtkMessage("help",1,i->second->GetDescription()<<std::endl);
440 if (i->second->GetNumberOfDescriptors()>0)
442 bbtkMessage("help",1, "Black boxes : "<<std::endl);
443 i->second->PrintHelpListDescriptors(true,adaptors);
447 bbtkMessage("help",1, "No black boxes"<<std::endl);
449 bbtkDecTab("help",1);
453 bbtkDebugDecTab("kernel",9);
454 bbtkError("package \""<<name<<"\" unknown");
457 bbtkDebugDecTab("kernel",9);
459 //===================================================================
461 //===================================================================
462 /// Prints help on the black box of type <name>
463 /// Returns the package to which it belongs
464 void Factory::PrintHelpDescriptor(const std::string& name,
465 std::string& package,
468 bbtkDebugMessageInc("kernel",9,"Factory::PrintHelpDescriptor(\""
473 PackageMapType::const_iterator i;
474 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
476 if (i->second->ContainsDescriptor(name))
478 i->second->PrintHelpDescriptor(name,full);
479 package = i->second->GetName();
484 bbtkDebugDecTab("kernel",9);
487 bbtkError("No package of the factory contains any black box <"
491 //===================================================================
494 //===================================================================
495 /// Inserts a package in the factory
496 void Factory::InsertPackage( Package::Pointer p )
498 bbtkDebugMessageInc("kernel",9,"Factory::InsertPackage(\""<<
499 p->GetName()<<"\")"<<std::endl);
501 p->AddFactory(GetThisPointer<Factory>());
502 mPackageMap[p->GetName()] = p;
504 bbtkDebugDecTab("kernel",9);
506 //===================================================================
508 //===================================================================
509 /// Removes a package from the factory (and deletes it)
510 void Factory::RemovePackage( Package::Pointer p )
512 bbtkDebugMessageInc("kernel",9,"Factory::RemovePackage(\""<<
513 p->GetName()<<"\")"<<std::endl);
515 PackageMapType::iterator i;
516 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
518 if (i->second == p) break;
521 if (i!=mPackageMap.end())
527 bbtkError("Factory::RemovePackage(\""<<
528 p->GetName()<<"\") : package absent from factory");
531 bbtkDebugDecTab("kernel",9);
533 //===================================================================
536 //===================================================================
537 /// Creates an instance of a black box of type <type> with name <name>
538 BlackBox::Pointer Factory::NewBlackBox(const std::string& type,
539 const std::string& name) const
541 bbtkDebugMessageInc("kernel",7,"Factory::NewBlackBox(\""
542 <<type<<"\",\""<<name<<"\")"<<std::endl);
545 PackageMapType::const_iterator i;
546 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
548 b = i->second->NewBlackBox(type,name);
553 bbtkError("black box type \""<<type<<"\" unknown");
556 bbtkDebugDecTab("kernel",7);
559 //===================================================================
561 //===================================================================
562 /// Creates an instance of a black box of type <type> with name <name>
563 BlackBox::Pointer Factory::NewAdaptor(const DataInfo& typein,
564 const DataInfo& typeout,
565 const std::string& name) const
567 bbtkDebugMessageInc("kernel",8,"Factory::NewAdaptor("
570 <<name<<"\")"<<bbtkendl);
574 PackageMapType::const_iterator i;
575 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
577 b = i->second->NewAdaptor(typein,typeout,name);
582 bbtkError("no "<<typein<<" to "<<typeout
583 <<" adaptor available");
586 bbtkDebugDecTab("kernel",7);
589 //===================================================================
592 //===================================================================
593 /// Creates an instance of a black box of type <type> with name <name>
594 BlackBox::Pointer Factory::NewWidgetAdaptor(const DataInfo& typein,
595 const DataInfo& typeout,
596 const std::string& name) const
598 bbtkDebugMessageInc("kernel",8,"Factory::NewWidgetAdaptor(<"
601 <<name<<"\")"<<bbtkendl);
605 PackageMapType::const_iterator i;
606 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
608 b = i->second->NewWidgetAdaptor(typein,
615 bbtkError("no "<<typein<<" to "<<typeout
616 <<"> widget adaptor available");
619 bbtkDebugDecTab("kernel",7);
622 //===================================================================
624 //===================================================================
625 /// Creates an instance of a black box of type <type> with name <name>
626 bool Factory::FindAdaptor(const DataInfo& typein,
627 const DataInfo& typeout,
628 std::string& adaptor) const
630 bbtkDebugMessageInc("kernel",8,"Factory::FindAdaptor(<"
632 <<typeout<<">)"<<bbtkendl);
635 PackageMapType::const_iterator i;
636 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
638 b = i->second->FindAdaptor(typein,
646 bbtkError("no "<<typein<<" to "<<typeout
647 <<"> widget adaptor available");
651 bbtkDebugDecTab("kernel",7);
654 //===================================================================
656 //===================================================================
657 /// Creates an instance of a black box of type <type> with name <name>
658 bool Factory::FindWidgetAdaptor(const DataInfo& typein,
659 const DataInfo& typeout,
660 std::string& adaptor) const
662 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
664 <<typeout<<">)"<<bbtkendl);
667 PackageMapType::const_iterator i;
668 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
670 b = i->second->FindWidgetAdaptor(typein,
675 bbtkDebugDecTab("kernel",7);
678 //===================================================================
680 //===================================================================
681 /// Creates an instance of a black box of type <type> with name <name>
682 bool Factory::FindWidgetAdaptor2(const DataInfo& typein,
683 const DataInfo& typeout,
685 std::string& adaptor) const
687 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
689 <<typeout<<">)"<<bbtkendl);
692 adaptor = widget = "";
693 PackageMapType::const_iterator i;
694 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
696 b = i->second->FindWidgetAdaptor(typein,
703 // Look for a widget adaptor with good nature out
704 bbtkMessage("kernel",5,
705 "*** Looking for a two pieces widget adaptor for : "
706 << typein << "->"<<typeout<<std::endl);
707 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
709 Package::AdaptorMapType::const_iterator j;
710 for (j=i->second->GetAdaptorMap().begin();
711 j!=i->second->GetAdaptorMap().end();
714 if ( ( j->first.mKind ==
715 BlackBoxDescriptor::DEFAULT_GUI) &&
716 //(j->first.mTypeIn == typein) &&
717 (j->first.mTypeOut.GetNature() == typeout.GetNature() )
720 widget = j->second.lock()->GetTypeName();
721 bbtkMessage("kernel",5,
722 "===> Found first part : "<<widget
723 << " "<<j->first.mTypeIn<<"->"
724 <<j->first.mTypeOut<<std::endl);
725 DataInfo ti( j->first.mTypeOut.GetType(), "");
726 DataInfo to( typeout.GetType(), "");
727 b = FindAdaptor( ti, to, adaptor );
730 bbtkMessage("kernel",5,
731 "===> Found second part : "<<adaptor
737 bbtkMessage("kernel",5,
738 "===> No second part found"<<std::endl);
745 bbtkDebugDecTab("kernel",7);
748 //===================================================================
750 //===================================================================
751 /// Creates an instance of a connection
752 Connection::Pointer Factory::NewConnection(BlackBox::Pointer from,
753 const std::string& output,
754 BlackBox::Pointer to,
755 const std::string& input) const
757 bbtkDebugMessage("kernel",7,"Factory::NewConnection(\""
758 <<from->bbGetName()<<"\",\""<<output<<"\",\""
759 <<to->bbGetName()<<"\",\""<<input
762 return Connection::New(from,output,to,input,
763 GetThisPointer<Factory>());
765 //===================================================================
769 //===================================================================
770 Package::Pointer Factory::GetPackage(const std::string& name) const
772 bbtkDebugMessageInc("kernel",9,"Factory::GetPackage(\""<<name<<"\")"
775 PackageMapType::const_iterator i = mPackageMap.find(name);
776 if ( i != mPackageMap.end() )
778 bbtkDebugDecTab("kernel",9);
783 bbtkDebugDecTab("kernel",9);
784 bbtkError("package \""<<name<<"\" unknown");
787 bbtkDebugDecTab("kernel",9);
789 //===================================================================
792 //===================================================================
793 void Factory::Check() const
795 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
797 PackageMapType::const_iterator i;
798 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
802 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
803 <<" ... OK"<<std::endl);
805 //===================================================================
807 //===================================================================
808 void Factory::WriteDotFilePackagesList(FILE *ff)
811 bbtkDebugMessageInc("kernel",9,"Factory::WriteDotFilePackagesList()"
815 fprintf( ff , "subgraph cluster_FACTORY {\n");
816 fprintf( ff , " label = \"PACKAGES\"%s\n", ";");
817 fprintf( ff , " style=filled%s\n",";");
818 fprintf( ff , " color=lightgrey%s\n",";");
819 fprintf( ff , " rankdir=TB%s\n",";");
822 PackageMapType::const_iterator i;
823 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
825 url=GetPackage(i->first)->GetDocURL();
826 fprintf(ff," %s [shape=ellipse, URL=\"%s\"]%s\n",i->first.c_str(),url.c_str(),";" );
828 fprintf( ff , "}\n\n");
829 bbtkDebugDecTab("kernel",9);
831 //===================================================================
834 void Factory::ShowGraphTypes(const std::string& name) const
838 PackageMapType::const_iterator i;
839 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
841 if (i->second->ContainsDescriptor(name))
843 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
845 // Don't pollute the file store with "temp_dir" directories ...
846 std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
847 std::string directory = "\"" + default_doc_dir + separator + "temp_dir" +separator + "\"";
848 std::string filename2 = default_doc_dir + separator + "temp_dir" + separator + "tmp.html";
851 std::string command("start \"Titre\" /D ");
853 std::string command("gnome-open ");
855 command=command + directory +" tmp.html";
857 ff=fopen(filename2.c_str(),"w");
859 fprintf(ff,"<html><head><title>TMP</title> <script type=\"text/javascript\"> <!--\n");
860 fprintf(ff," window.location=\"%s#%s\";\n" , i->second->GetDocURL().c_str(),name.c_str() );
861 fprintf(ff,"//--></script></head><body></body></html>\n");
864 //fprintf(ff, "<a href=\"%s#%s\">Link</a>\n", i->second->GetDocURL().c_str(),name.c_str() );
866 system( command.c_str() );
871 bbtkDebugDecTab("kernel",9);
874 bbtkError("No package of the factory contains any black box <"
882 void Factory::CreateHtmlIndex(IndexEntryType type,
883 const std::string& filename)
885 bbtkDebugMessageInc("kernel",9,"Factory::CreateHtmlIndex(\""
886 <<filename<<"\")"<<bbtkendl);
890 typedef std::map<std::string,
891 std::vector<BlackBoxDescriptor::Pointer> > IndexType;
893 // Builds the index map
894 PackageMapType::const_iterator i;
895 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
897 Package::Pointer pack = i->second;
898 if (pack->GetName()=="user") continue;
899 Package::DescriptorMapType::const_iterator j;
900 for (j = pack->GetDescriptorMap().begin();
901 j!= pack->GetDescriptorMap().end();
906 if ( type==Adaptors )
908 if (j->second->GetKind() == BlackBoxDescriptor::STANDARD )
912 if (j->second->GetKind() != BlackBoxDescriptor::STANDARD )
915 std::vector<std::string> keys;
919 k += pack->GetName();
921 title = "Boxes by package";
923 else if ((type==Initials) || (type==Adaptors))
925 std::string init(" ");
926 init[0] = std::toupper(j->second->GetTypeName()[0]);
927 keys.push_back(init);
928 title = "Alphabetical list";
930 else if (type==Categories)
932 // Split the category string
933 std::string delimiters = ";,";
934 Utilities::SplitString(j->second->GetCategory(),
937 keys.push_back(" NONE");
938 title = "Boxes by category";
942 std::vector<std::string>::const_iterator k;
943 for (k=keys.begin(); k!=keys.end(); ++k )
945 IndexType::iterator p;
947 if (p != index.end())
949 p->second.push_back(j->second);
953 std::vector<BlackBoxDescriptor::Pointer> v;
954 v.push_back(j->second);
962 //---------------------
965 s.open(filename.c_str());
968 bbtkError("Factory::CreateHtmlIndex : could not open file '"
972 //----------------------
974 s << "<html lang=\"en\">\n";
976 s << "<title>"<<title<<"</title>\n";
977 s << "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n";
978 s << "<meta name=\"description\" content=\""<<title<<"\">\n";
979 s << "<meta name=\"generator\" content=\"\">\n";
980 s << "<link title=\"Top\" rel=\"top\" href=\"#Top\">\n";
981 //<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
982 s << "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><style type=\"text/css\"><!--\n";
983 s << "pre.display { font-family:inherit }\n";
984 s << "pre.format { font-family:inherit }\n";
985 s << "pre.smalldisplay { font-family:inherit; font-size:smaller }\n";
986 s << "pre.smallformat { font-family:inherit; font-size:smaller }\n";
987 s << "pre.smallexample { font-size:smaller }\n";
988 s << "pre.smalllisp { font-size:smaller }\n";
989 s << "span.sc { font-variant:small-caps }\n";
990 s << "span.roman { font-family:serif; font-weight:normal; } \n";
991 s << "span.sansserif { font-family:sans-serif; font-weight:normal; }\n";
992 s << "--></style>\n";
994 //----------------------
996 //----------------------
999 s << "<a name=\"Top\"></a>\n";
1000 s << "<h1 class=\"settitle\">"<<title<<"</h1>\n";
1002 IndexType::iterator ii;
1003 for (ii=index.begin();ii!=index.end();++ii)
1005 s << "<a href=\"#"<<ii->first<<"\">"<<ii->first<<"</a> ";
1008 for (ii=index.begin();ii!=index.end();++ii)
1011 s << "<p><a href=\"#Top\">Top</a>";
1014 s << "<a name=\""<<ii->first<<"\"></a>\n";
1015 s << "<p><a href=\""<<ii->first<<"/index.html\">"
1016 << ii->first<<"</a>\n";
1018 s << " - \n";
1020 s << "<a name=\"doxygen\"></a>\n";
1022 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1023 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1027 s << "<a name=\""<<ii->first<<"\"></a>\n";
1028 s << "<p><b>"<<ii->first<<"</b>\n";
1032 s << "<p><TABLE cellspacing=0 cellpadding=3>\n";
1034 std::vector<BlackBoxDescriptor::Pointer>::iterator di;
1035 for (di=ii->second.begin();di!=ii->second.end();++di)
1037 std::string pack = (*di)->GetPackage()->GetName();
1038 std::string name = (*di)->GetTypeName();
1039 Utilities::html_format(name);
1040 std::string descr = (*di)->GetDescription();
1041 Utilities::html_format(descr);
1043 s << "<TD style='vertical-align: top;'>";
1044 s << " <a href=\""<<pack
1045 <<"/index.html#"<<name<<"\">"
1046 <<pack<<"::"<<name<<"</a>";
1048 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1055 //----------------------
1060 ptm = gmtime ( &rawtime );
1063 s << "Automatically generated by <b>bbtk</b> on "
1064 << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900
1065 << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n";
1066 s << "</body></html>\n";
1068 //----------------------
1071 bbtkDebugDecTab("kernel",9);
1074 //==========================================================================
1075 std::string Factory::GetObjectName() const
1077 return std::string("Factory");
1079 //==========================================================================
1081 //==========================================================================
1082 std::string Factory::GetObjectInfo() const
1084 std::stringstream i;
1087 //==========================================================================
1089 //==========================================================================
1090 size_t Factory::GetObjectSize() const
1092 size_t s = Superclass::GetObjectSize();
1093 s += Factory::GetObjectInternalSize();
1096 //==========================================================================
1097 //==========================================================================
1098 size_t Factory::GetObjectInternalSize() const
1100 size_t s = sizeof(Factory);
1103 //==========================================================================
1104 //==========================================================================
1105 size_t Factory::GetObjectRecursiveSize() const
1107 size_t s = Superclass::GetObjectRecursiveSize();
1108 s += Factory::GetObjectInternalSize();
1110 PackageMapType::const_iterator i;
1111 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
1113 s += i->second->GetObjectRecursiveSize();
1117 //==========================================================================