1 /*=========================================================================
3 Module: $RCSfile: bbtkFactory.cxx,v $
5 Date: $Date: 2009/02/27 11:20:25 $
6 Version: $Revision: 1.41 $
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"
43 #include <sys/stat.h> // for struct stat stFileInfo
46 #include <direct.h> // for getcwd
49 #include <cctype> // std::toupper
56 //===================================================================
58 Factory::Pointer Factory::New()
60 bbtkDebugMessage("Kernel",9,"Factory::New()"<<std::endl);
61 return MakePointer(new Factory());
63 //===================================================================
65 //===================================================================
70 bbtkDebugMessage("Kernel",7,"Factory::Factory()"<<std::endl);
72 //===================================================================
74 //===================================================================
78 bbtkDebugMessageInc("Kernel",7,"Factory::~Factory()"<<std::endl);
80 bbtkDebugDecTab("Kernel",7);
82 //===================================================================
86 //===================================================================
89 bbtkDebugMessageInc("Kernel",7,"Factory::Reset()"<<std::endl);
91 bbtkDebugDecTab("Kernel",7);
93 //===================================================================
96 // ===================================================================
97 bool Factory::DoLoadPackage(std::string libname,
102 Package::Pointer p = Package::CreateFromDynamicLibrary(libname,
107 //===================================================================
108 bbtkMessage("Output",2,p->GetName()<<" "
111 <<p->GetAuthor() << " Category(s) :"
114 bbtkMessage("Output",2,p->GetDescription()<<std::endl);
115 //===================================================================
116 p->AddFactory(GetThisPointer<Factory>());
117 mPackageMap[pkgname] = p;
124 //===================================================================
125 /// \brief Loads a package.
127 /// The name is the system-independant name of the package (the name of the instance of bbtk::Package).
128 /// Tries to open the dynamic library :
129 /// - "libbb<name>.so" for linux systems,
130 /// - "bb<name>.dll" for windows systems.
131 /// If it succeeds, then tries to load the symbols "<name>GetPackage" and "<name>DeletePackage".
132 /// "<name>GetPackage" is called to get the pointer on the bbtk::Package of the library
133 /// ("<name>DeletePackage" is not used, its presence is just checked before loading the package).
135 /// now, filename is only the last name (no longer the full name!)
136 /// it will be searched within *all* the paths given in bbtk_config.xml
140 void Factory::LoadPackage( const std::string& name )
142 // Note : in the following :
143 // name : the user supplied name
144 // - abreviated name e.g. pkg pkg.so libbpkg libbbpkg.so
145 // - relative full name e.g. ./libbbpkg.so ../../libbbpkg.so
146 // - absolute full name e.g. /home/usrname/proj/lib/libbbpkg.so
147 // same for Windows, with c:, d: ...
149 // lastname : string before the last / (if any), or user supplied name
151 bbtkDebugMessageInc("Kernel",7,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
152 bbtkMessage("debug",1,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
154 std::vector<std::string> package_paths;
155 std::string libname; // full path library name
156 std::string pkgname; // e.g. libbb<pkgname>.so
159 pkgname = Utilities::ExtractPackageName(name,upath);
161 bbtkMessage("debug",1,"Package name ["<<pkgname<<"]"<<std::endl);
162 bbtkMessage("debug",1,"Package path ["<<upath<<"]"<<std::endl);
164 // no loading package if already loaded
165 PackageMapType::iterator iUnload;
166 iUnload = mPackageMap.find(pkgname);
167 if (iUnload != mPackageMap.end())
169 bbtkMessage("Output",2,"["<< pkgname <<"] already loaded" << std::endl);
173 // =================================================
174 // The following structure was checked to work
175 // with any type of relative/absolute path.
176 // Please don't modify it without checking
177 // *all* the cases. JP
178 //==================================================
180 //std::cout << "upath [" << upath << "]" << std::endl;
183 bool foundFile = false;
185 // If path provided by user will be the first scanned :
186 // push it into vector of paths
187 if (upath.length()>0) // ------------------------------------- check user supplied location
189 if (name[0] != '.' && name[0] != '/' && name[1]!= ':')
191 bbtkError("Use absolute or relative path name! ["<<name<<"] is an illegal name");
195 // std::string path = Utilities::ExpandLibName(upath, false);
196 std::string path = Utilities::ExpandLibName(name,false); // keep last item, here.
201 Utilities::ExtractPackageName(path,p2);
202 //libname = Utilities::MakeLibnameFromPath(path, pkgname);
203 libname = Utilities::MakeLibnameFromPath(p2, pkgname); // remove last item
204 // Check if library exists
205 if ( !Utilities::FileExists(libname) )
207 // The following is *NOT* a debug time message :
208 // It's a user intended message.
209 // Please don't remove it.
210 bbtkMessage("Output",3," [" <<libname
211 <<"] : doesn't exist" <<std::endl);
215 ok = DoLoadPackage( libname, pkgname, path);
220 bbtkError("Path ["<<upath<<"] doesn't exist");
224 else // ----------------------------------------------------- iterate on the paths
228 package_paths = ConfigurationFile::GetInstance().Get_package_paths();
229 std::vector<std::string>::iterator i;
230 for (i=package_paths.begin();i!=package_paths.end();++i)
235 // we *really* want '.' to be the current working directory
238 char buf[2048]; // for getcwd
239 char * currentDir = getcwd(buf, 2048);
240 std::string cwd(currentDir);
244 libname = Utilities::MakeLibnameFromPath(path, pkgname);
246 bbtkMessage("debug",2,"-> Trying to load [" << libname << "]" <<std::endl);
248 // Check if library exists
249 if ( !Utilities::FileExists(libname) )
251 // The following is *NOT* a debug time message :
252 // It's a user intended message.
253 // Please don't remove it.
254 bbtkMessage("Output",3,
255 " [" <<libname <<"] : doesn't exist" <<std::endl);
256 continue; // try next path
260 // Try to Load the library
262 ok = DoLoadPackage( libname, pkgname, path);
265 bbtkMessage("debug",2," OK"<<std::endl);
267 break; // we stop iterating even if error : have to signal it to user
268 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
272 if( !ok ) // nothing was loaded
276 bbtkError("Could not find package ["<<pkgname<< "]");
280 #if defined(__GNUC__)
281 bbtkError("Could not load package ["<< pkgname
283 << " Opening "<<libname<<" failed"
284 << " Reason: "<< dlerror());
285 #elif defined(_WIN32)
286 bbtkError("Could not load package ["<<pkgname
287 <<"] :"<< std::endl << " Error loading " <<libname);
289 // look how to get the error message on win
291 // it is the bordel !! (the bloody fucking bordel, you mean?)
292 // look : http://msdn2.microsoft.com/en-us/library/ms680582.aspx
296 bbtkMessage("Output",2,"[" << libname << "] loaded" << std::endl);
300 //===================================================================
301 /// \brief UnLoads a package.
303 /// The package must have been previously loaded by LoadPackage.
304 /// If the entry is found in the map, calls ClosePackage
305 void Factory::UnLoadPackage( const std::string& name )
307 bbtkDebugMessageInc("Kernel",7,"Factory::UnLoadPackage(\""
308 <<name<<"\")"<<std::endl);
310 PackageMapType::iterator i;
311 i = mPackageMap.find(name);
312 if (i == mPackageMap.end())
314 bbtkError("cannot unload package \""<<name
315 <<"\" : package not loaded !");
318 bbtkDebugDecTab("Kernel",7);
320 //===================================================================
323 //===================================================================
324 void Factory::CloseAllPackages()
326 bbtkDebugMessageInc("Kernel",7,"Factory::CloseAllPackages()"<<std::endl);
328 std::vector< Package::WeakPointer > mAlive;
331 while (mPackageMap.begin() != mPackageMap.end())
333 PackageMapType::iterator i = mPackageMap.begin();
334 Package::WeakPointer p = i->second;
336 if (p.lock()) mAlive.push_back(p);
338 std::vector< Package::WeakPointer >::iterator i;
339 for (i=mAlive.begin();i!=mAlive.end();++i)
341 // If not dead : reinsert
344 bbtkDebugMessage("Kernel",7,"Package "<<i->lock()->GetName()
345 <<" still alive"<<std::endl);
346 // InsertPackage(i->lock());
350 while (mPackageMap.size()>0);
352 bbtkDebugDecTab("Kernel",7);
354 //===================================================================
356 //===================================================================
357 /// \brief Close the package referenced by the iterator
359 /// First removes the factory from the set of factories which use the package
360 /// If the set is empty then :
361 /// If it is a dynamically loaded package :
362 /// - Loads and calls the function "<name>DeletePackage" of the dynamic library (responsible for package desallocation)
363 /// - Closes the dynamic library
365 /// - deletes the package normally
367 /// Finally erases the package entry in the packages map
368 void Factory::ClosePackage(PackageMapType::iterator& i)
370 bbtkDebugMessageInc("Kernel",7,"Factory::ClosePackage(\""
371 <<i->second->GetName()
375 // Removes this from the set of factories which use the package
376 i->second->RemoveFactory(GetThisPointer<Factory>());
377 Package::WeakPointer p = i->second;
378 // remove the entry in the map
379 mPackageMap.erase(i);
380 // Release the package if not already destroyed
385 bbtkDebugDecTab("Kernel",7);
387 //===================================================================
391 //===================================================================
392 /// Displays the list of packages loaded
393 void Factory::PrintPackages(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->PrintBlackBoxes(false,adaptors);
406 bbtkDebugDecTab("Kernel",9);
408 //===================================================================
410 //===================================================================
411 /// Displays help on a package
412 void Factory::HelpPackage(const std::string& name, bool adaptors) const
414 bbtkDebugMessageInc("Kernel",9,"Factory::HelpPackage(\""<<name<<"\")"
417 PackageMapType::const_iterator i = mPackageMap.find(name);
418 if ( i != mPackageMap.end() )
420 bbtkMessage("Help",1, "Package "<<i->first<<" ");
422 if (i->second->GetVersion().length()>0)
423 bbtkMessageCont("Help",1,"v" <<i->second->GetVersion());
425 if (i->second->GetAuthor().length()>0)
426 bbtkMessageCont("Help",1,"- "<<i->second->GetAuthor());
428 if (i->second->GetCategory().length()>0)
429 bbtkMessageCont("Help",1,"- "<<i->second->GetCategory());
431 bbtkMessageCont("Help",1,std::endl);
432 bbtkIncTab("Help",1);
433 bbtkMessage("Help",1,i->second->GetDescription()<<std::endl);
434 if (i->second->GetNumberOfBlackBoxes()>0)
436 bbtkMessage("Help",1, "Black boxes : "<<std::endl);
437 i->second->PrintBlackBoxes(true,adaptors);
441 bbtkMessage("Help",1, "No black boxes"<<std::endl);
443 bbtkDecTab("Help",1);
447 bbtkDebugDecTab("Kernel",9);
448 bbtkError("package \""<<name<<"\" unknown");
451 bbtkDebugDecTab("Kernel",9);
453 //===================================================================
455 //===================================================================
456 /// Prints help on the black box of type <name>
457 /// Returns the package to which it belongs
458 void Factory::HelpBlackBox(const std::string& name,
459 std::string& package,
462 bbtkDebugMessageInc("Kernel",9,"Factory::HelpBlackBox(\""<<name<<"\")"
466 PackageMapType::const_iterator i;
467 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
469 if (i->second->ContainsBlackBox(name))
471 i->second->HelpBlackBox(name,full);
472 package = i->second->GetName();
477 bbtkDebugDecTab("Kernel",9);
480 bbtkError("No package of the factory contains any black box <"
484 //===================================================================
487 //===================================================================
488 /// Inserts a package in the factory
489 void Factory::InsertPackage( Package::Pointer p )
491 bbtkDebugMessageInc("Kernel",9,"Factory::InsertPackage(\""<<
492 p->GetName()<<"\")"<<std::endl);
494 p->AddFactory(GetThisPointer<Factory>());
495 mPackageMap[p->GetName()] = p;
497 bbtkDebugDecTab("Kernel",9);
499 //===================================================================
501 //===================================================================
502 /// Removes a package from the factory (and deletes it)
503 void Factory::RemovePackage( Package::Pointer p )
505 bbtkDebugMessageInc("Kernel",9,"Factory::RemovePackage(\""<<
506 p->GetName()<<"\")"<<std::endl);
508 PackageMapType::iterator i;
509 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
511 if (i->second == p) break;
514 if (i!=mPackageMap.end())
520 bbtkError("Factory::RemovePackage(\""<<
521 p->GetName()<<"\") : package absent from factory");
524 bbtkDebugDecTab("Kernel",9);
526 //===================================================================
529 //===================================================================
530 /// Creates an instance of a black box of type <type> with name <name>
531 BlackBox::Pointer Factory::NewBlackBox(const std::string& type,
532 const std::string& name) const
534 bbtkDebugMessageInc("Kernel",7,"Factory::NewBlackBox(\""
535 <<type<<"\",\""<<name<<"\")"<<std::endl);
538 PackageMapType::const_iterator i;
539 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
541 b = i->second->NewBlackBox(type,name);
546 bbtkError("black box type \""<<type<<"\" unknown");
549 bbtkDebugDecTab("Kernel",7);
552 //===================================================================
554 //===================================================================
555 /// Creates an instance of a black box of type <type> with name <name>
556 BlackBox::Pointer Factory::NewAdaptor(const DataInfo& typein,
557 const DataInfo& typeout,
558 const std::string& name) const
560 bbtkDebugMessageInc("Kernel",8,"Factory::NewAdaptor("
563 <<name<<"\")"<<bbtkendl);
567 PackageMapType::const_iterator i;
568 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
570 b = i->second->NewAdaptor(typein,typeout,name);
575 bbtkError("no "<<typein<<" to "<<typeout
576 <<" adaptor available");
579 bbtkDebugDecTab("Kernel",7);
582 //===================================================================
585 //===================================================================
586 /// Creates an instance of a black box of type <type> with name <name>
587 BlackBox::Pointer Factory::NewWidgetAdaptor(const DataInfo& typein,
588 const DataInfo& typeout,
589 const std::string& name) const
591 bbtkDebugMessageInc("Kernel",8,"Factory::NewWidgetAdaptor(<"
594 <<name<<"\")"<<bbtkendl);
598 PackageMapType::const_iterator i;
599 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
601 b = i->second->NewWidgetAdaptor(typein,
608 bbtkError("no "<<typein<<" to "<<typeout
609 <<"> widget adaptor available");
612 bbtkDebugDecTab("Kernel",7);
615 //===================================================================
617 //===================================================================
618 /// Creates an instance of a black box of type <type> with name <name>
619 bool Factory::FindAdaptor(const DataInfo& typein,
620 const DataInfo& typeout,
621 std::string& adaptor) const
623 bbtkDebugMessageInc("Kernel",8,"Factory::FindAdaptor(<"
625 <<typeout<<">)"<<bbtkendl);
628 PackageMapType::const_iterator i;
629 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
631 b = i->second->FindAdaptor(typein,
639 bbtkError("no "<<typein<<" to "<<typeout
640 <<"> widget adaptor available");
644 bbtkDebugDecTab("Kernel",7);
647 //===================================================================
649 //===================================================================
650 /// Creates an instance of a black box of type <type> with name <name>
651 bool Factory::FindWidgetAdaptor(const DataInfo& typein,
652 const DataInfo& typeout,
653 std::string& adaptor) const
655 bbtkDebugMessageInc("Kernel",8,"Factory::FindWidgetAdaptor(<"
657 <<typeout<<">)"<<bbtkendl);
660 PackageMapType::const_iterator i;
661 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
663 b = i->second->FindWidgetAdaptor(typein,
668 bbtkDebugDecTab("Kernel",7);
671 //===================================================================
673 //===================================================================
674 /// Creates an instance of a black box of type <type> with name <name>
675 bool Factory::FindWidgetAdaptor2(const DataInfo& typein,
676 const DataInfo& typeout,
678 std::string& adaptor) const
680 bbtkDebugMessageInc("Kernel",8,"Factory::FindWidgetAdaptor(<"
682 <<typeout<<">)"<<bbtkendl);
685 adaptor = widget = "";
686 PackageMapType::const_iterator i;
687 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
689 b = i->second->FindWidgetAdaptor(typein,
696 // Look for a widget adaptor with good nature out
697 bbtkMessage("Kernel",5,
698 "*** Looking for a two pieces widget adaptor for : "
699 << typein << "->"<<typeout<<std::endl);
700 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
702 Package::AdaptorMapType::const_iterator j;
703 for (j=i->second->GetAdaptorMap().begin();
704 j!=i->second->GetAdaptorMap().end();
707 if ( ( j->first.mKind ==
708 BlackBoxDescriptor::DEFAULT_GUI) &&
709 //(j->first.mTypeIn == typein) &&
710 (j->first.mTypeOut.GetNature() == typeout.GetNature() )
713 widget = j->second.lock()->GetTypeName();
714 bbtkMessage("Kernel",5,
715 "===> Found first part : "<<widget
716 << " "<<j->first.mTypeIn<<"->"
717 <<j->first.mTypeOut<<std::endl);
718 DataInfo ti( j->first.mTypeOut.GetType(), "");
719 DataInfo to( typeout.GetType(), "");
720 b = FindAdaptor( ti, to, adaptor );
723 bbtkMessage("Kernel",5,
724 "===> Found second part : "<<adaptor
730 bbtkMessage("Kernel",5,
731 "===> No second part found"<<std::endl);
738 bbtkDebugDecTab("Kernel",7);
741 //===================================================================
743 //===================================================================
744 /// Creates an instance of a connection
745 Connection::Pointer Factory::NewConnection(BlackBox::Pointer from,
746 const std::string& output,
747 BlackBox::Pointer to,
748 const std::string& input) const
750 bbtkDebugMessage("Kernel",7,"Factory::NewConnection(\""
751 <<from->bbGetName()<<"\",\""<<output<<"\",\""
752 <<to->bbGetName()<<"\",\""<<input
755 return Connection::New(from,output,to,input,
756 GetThisPointer<Factory>());
758 //===================================================================
762 //===================================================================
763 Package::Pointer Factory::GetPackage(const std::string& name) const
765 bbtkDebugMessageInc("Kernel",9,"Factory::GetPackage(\""<<name<<"\")"
768 PackageMapType::const_iterator i = mPackageMap.find(name);
769 if ( i != mPackageMap.end() )
771 bbtkDebugDecTab("Kernel",9);
776 bbtkDebugDecTab("Kernel",9);
777 bbtkError("package \""<<name<<"\" unknown");
780 bbtkDebugDecTab("Kernel",9);
782 //===================================================================
785 //===================================================================
786 void Factory::CheckPackages() const
788 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
790 PackageMapType::const_iterator i;
791 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
793 i->second->CheckBoxes();
795 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
796 <<" ... OK"<<std::endl);
798 //===================================================================
800 //===================================================================
801 void Factory::WriteDotFilePackagesList(FILE *ff)
804 bbtkDebugMessageInc("Kernel",9,"Factory::WriteDotFilePackagesList()"
808 fprintf( ff , "subgraph cluster_FACTORY {\n");
809 fprintf( ff , " label = \"PACKAGES\"%s\n", ";");
810 fprintf( ff , " style=filled%s\n",";");
811 fprintf( ff , " color=lightgrey%s\n",";");
812 fprintf( ff , " rankdir=TB%s\n",";");
815 PackageMapType::const_iterator i;
816 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
818 url=GetPackage(i->first)->GetDocURL();
819 fprintf(ff," %s [shape=ellipse, URL=\"%s\"]%s\n",i->first.c_str(),url.c_str(),";" );
821 fprintf( ff , "}\n\n");
822 bbtkDebugDecTab("Kernel",9);
824 //===================================================================
827 void Factory::ShowGraphTypes(const std::string& name) const
831 PackageMapType::const_iterator i;
832 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
834 if (i->second->ContainsBlackBox(name))
836 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
838 // Don't pollute the file store with "temp_dir" directories ...
839 std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
840 std::string directory = "\"" + default_doc_dir + separator + "temp_dir" +separator + "\"";
841 std::string filename2 = default_doc_dir + separator + "temp_dir" + separator + "tmp.html";
844 std::string command("start \"Titre\" /D ");
846 std::string command("gnome-open ");
848 command=command + directory +" tmp.html";
850 ff=fopen(filename2.c_str(),"w");
852 fprintf(ff,"<html><head><title>TMP</title> <script type=\"text/javascript\"> <!--\n");
853 fprintf(ff," window.location=\"%s#%s\";\n" , i->second->GetDocURL().c_str(),name.c_str() );
854 fprintf(ff,"//--></script></head><body></body></html>\n");
857 //fprintf(ff, "<a href=\"%s#%s\">Link</a>\n", i->second->GetDocURL().c_str(),name.c_str() );
859 system( command.c_str() );
864 bbtkDebugDecTab("Kernel",9);
867 bbtkError("No package of the factory contains any black box <"
875 void Factory::CreateHtmlIndex(IndexEntryType type,
876 const std::string& filename)
878 bbtkDebugMessageInc("Kernel",9,"Factory::CreateHtmlIndex(\""
879 <<filename<<"\")"<<bbtkendl);
883 typedef std::map<std::string,
884 std::vector<BlackBoxDescriptor::Pointer> > IndexType;
886 // Builds the index map
887 PackageMapType::const_iterator i;
888 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
890 Package::Pointer pack = i->second;
891 if (pack->GetName()=="user") continue;
892 Package::BlackBoxMapType::const_iterator j;
893 for (j = pack->GetBlackBoxMap().begin();
894 j!= pack->GetBlackBoxMap().end();
899 if ( type==Adaptors )
901 if (j->second->GetKind() == BlackBoxDescriptor::STANDARD )
905 if (j->second->GetKind() != BlackBoxDescriptor::STANDARD )
908 std::vector<std::string> keys;
912 k += pack->GetName();
914 title = "Boxes by package";
916 else if ((type==Initials) || (type==Adaptors))
918 std::string init(" ");
919 init[0] = std::toupper(j->second->GetTypeName()[0]);
920 keys.push_back(init);
921 title = "Alphabetical list";
923 else if (type==Categories)
925 // Split the category string
926 std::string delimiters = ";,";
927 Utilities::SplitString(j->second->GetCategory(),
930 keys.push_back(" NONE");
931 title = "Boxes by category";
935 std::vector<std::string>::const_iterator k;
936 for (k=keys.begin(); k!=keys.end(); ++k )
938 IndexType::iterator p;
940 if (p != index.end())
942 p->second.push_back(j->second);
946 std::vector<BlackBoxDescriptor::Pointer> v;
947 v.push_back(j->second);
955 //---------------------
958 s.open(filename.c_str());
961 bbtkError("Factory::CreateHtmlIndex : could not open file '"
965 //----------------------
967 s << "<html lang=\"en\">\n";
969 s << "<title>"<<title<<"</title>\n";
970 s << "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n";
971 s << "<meta name=\"description\" content=\""<<title<<"\">\n";
972 s << "<meta name=\"generator\" content=\"\">\n";
973 s << "<link title=\"Top\" rel=\"top\" href=\"#Top\">\n";
974 //<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
975 s << "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><style type=\"text/css\"><!--\n";
976 s << "pre.display { font-family:inherit }\n";
977 s << "pre.format { font-family:inherit }\n";
978 s << "pre.smalldisplay { font-family:inherit; font-size:smaller }\n";
979 s << "pre.smallformat { font-family:inherit; font-size:smaller }\n";
980 s << "pre.smallexample { font-size:smaller }\n";
981 s << "pre.smalllisp { font-size:smaller }\n";
982 s << "span.sc { font-variant:small-caps }\n";
983 s << "span.roman { font-family:serif; font-weight:normal; } \n";
984 s << "span.sansserif { font-family:sans-serif; font-weight:normal; }\n";
985 s << "--></style>\n";
987 //----------------------
989 //----------------------
992 s << "<a name=\"Top\"></a>\n";
993 s << "<h1 class=\"settitle\">"<<title<<"</h1>\n";
995 IndexType::iterator ii;
996 for (ii=index.begin();ii!=index.end();++ii)
998 s << "<a href=\"#"<<ii->first<<"\">"<<ii->first<<"</a> ";
1001 for (ii=index.begin();ii!=index.end();++ii)
1004 s << "<p><a href=\"#Top\">Top</a>";
1007 s << "<a name=\""<<ii->first<<"\"></a>\n";
1008 s << "<p><a href=\""<<ii->first<<"/index.html\">"
1009 << ii->first<<"</a>\n";
1011 s << " - \n";
1013 s << "<a name=\"doxygen\"></a>\n";
1014 s << "<a href=..\\doxygen\\" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1018 s << "<a name=\""<<ii->first<<"\"></a>\n";
1019 s << "<p><b>"<<ii->first<<"</b>\n";
1023 s << "<p><TABLE cellspacing=0 cellpadding=3>\n";
1025 std::vector<BlackBoxDescriptor::Pointer>::iterator di;
1026 for (di=ii->second.begin();di!=ii->second.end();++di)
1028 std::string pack = (*di)->GetPackage()->GetName();
1029 std::string name = (*di)->GetTypeName();
1030 Utilities::html_format(name);
1031 std::string descr = (*di)->GetDescription();
1032 Utilities::html_format(descr);
1034 s << "<TD style='vertical-align: top;'>";
1035 s << " <a href=\""<<pack
1036 <<"/index.html#"<<name<<"\">"
1037 <<pack<<"::"<<name<<"</a>";
1039 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1046 //----------------------
1051 ptm = gmtime ( &rawtime );
1054 s << "Automatically generated by <b>bbtk</b> on "
1055 << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900
1056 << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n";
1057 s << "</body></html>\n";
1059 //----------------------
1062 bbtkDebugDecTab("Kernel",9);
1065 //==========================================================================
1066 std::string Factory::GetObjectName() const
1068 return std::string("Factory");
1070 //==========================================================================
1072 //==========================================================================
1073 std::string Factory::GetObjectInfo() const
1075 std::stringstream i;
1078 //==========================================================================
1080 //==========================================================================
1081 size_t Factory::GetObjectSize() const
1083 size_t s = Superclass::GetObjectSize();
1084 s += Factory::GetObjectInternalSize();
1087 //==========================================================================
1088 //==========================================================================
1089 size_t Factory::GetObjectInternalSize() const
1091 size_t s = sizeof(Factory);
1094 //==========================================================================
1095 //==========================================================================
1096 size_t Factory::GetObjectRecursiveSize() const
1098 size_t s = Superclass::GetObjectRecursiveSize();
1099 s += Factory::GetObjectInternalSize();
1101 PackageMapType::const_iterator i;
1102 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
1104 s += i->second->GetObjectRecursiveSize();
1108 //==========================================================================