1 /*=========================================================================
3 Module: $RCSfile: bbtkFactory.cxx,v $
5 Date: $Date: 2010/09/12 14:59:29 $
6 Version: $Revision: 1.51 $
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 //===================================================================
537 std::string Factory::GetPackageNameOfaBlackBox(std::string boxType)
539 std::string result="<void bbtk package name>";
540 PackageMapType::const_iterator i;
541 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
543 if ( i->second->ifBoxExist( boxType ) == true)
552 //===================================================================
553 /// Creates an instance of a black box of type <type> with name <name>
554 BlackBox::Pointer Factory::NewBlackBox(const std::string& type,
555 const std::string& name) const
557 bbtkDebugMessageInc("kernel",7,"Factory::NewBlackBox(\""
558 <<type<<"\",\""<<name<<"\")"<<std::endl);
561 PackageMapType::const_iterator i;
562 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
564 b = i->second->NewBlackBox(type,name);
569 bbtkError("black box type \""<<type<<"\" unknown");
572 bbtkDebugDecTab("kernel",7);
575 //===================================================================
577 //===================================================================
578 /// Creates an instance of a black box of type <type> with name <name>
579 BlackBox::Pointer Factory::NewAdaptor(const DataInfo& typein,
580 const DataInfo& typeout,
581 const std::string& name) const
583 bbtkDebugMessageInc("kernel",8,"Factory::NewAdaptor("
586 <<name<<"\")"<<bbtkendl);
590 PackageMapType::const_iterator i;
591 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
593 b = i->second->NewAdaptor(typein,typeout,name);
598 bbtkError("no "<<typein<<" to "<<typeout
599 <<" adaptor available");
602 bbtkDebugDecTab("kernel",7);
605 //===================================================================
608 //===================================================================
609 /// Creates an instance of a black box of type <type> with name <name>
610 BlackBox::Pointer Factory::NewWidgetAdaptor(const DataInfo& typein,
611 const DataInfo& typeout,
612 const std::string& name) const
614 bbtkDebugMessageInc("kernel",8,"Factory::NewWidgetAdaptor(<"
617 <<name<<"\")"<<bbtkendl);
621 PackageMapType::const_iterator i;
622 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
624 b = i->second->NewWidgetAdaptor(typein,
631 bbtkError("no "<<typein<<" to "<<typeout
632 <<"> widget adaptor available");
635 bbtkDebugDecTab("kernel",7);
638 //===================================================================
640 //===================================================================
641 /// Creates an instance of a black box of type <type> with name <name>
642 bool Factory::FindAdaptor(const DataInfo& typein,
643 const DataInfo& typeout,
644 std::string& adaptor) const
646 bbtkDebugMessageInc("kernel",8,"Factory::FindAdaptor(<"
648 <<typeout<<">)"<<bbtkendl);
651 PackageMapType::const_iterator i;
652 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
654 b = i->second->FindAdaptor(typein,
662 bbtkError("no "<<typein<<" to "<<typeout
663 <<"> widget adaptor available");
667 bbtkDebugDecTab("kernel",7);
670 //===================================================================
672 //===================================================================
673 /// Creates an instance of a black box of type <type> with name <name>
674 bool Factory::FindWidgetAdaptor(const DataInfo& typein,
675 const DataInfo& typeout,
676 std::string& adaptor) const
678 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
680 <<typeout<<">)"<<bbtkendl);
683 PackageMapType::const_iterator i;
684 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
686 b = i->second->FindWidgetAdaptor(typein,
691 bbtkDebugDecTab("kernel",7);
694 //===================================================================
696 //===================================================================
697 /// Creates an instance of a black box of type <type> with name <name>
698 bool Factory::FindWidgetAdaptor2(const DataInfo& typein,
699 const DataInfo& typeout,
701 std::string& adaptor) const
703 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
705 <<typeout<<">)"<<bbtkendl);
708 adaptor = widget = "";
709 PackageMapType::const_iterator i;
710 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
712 b = i->second->FindWidgetAdaptor(typein,
719 // Look for a widget adaptor with good nature out
720 bbtkMessage("kernel",5,
721 "*** Looking for a two pieces widget adaptor for : "
722 << typein << "->"<<typeout<<std::endl);
723 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
725 Package::AdaptorMapType::const_iterator j;
726 for (j=i->second->GetAdaptorMap().begin();
727 j!=i->second->GetAdaptorMap().end();
730 if ( ( j->first.mKind ==
731 BlackBoxDescriptor::DEFAULT_GUI) &&
732 //(j->first.mTypeIn == typein) &&
733 (j->first.mTypeOut.GetNature() == typeout.GetNature() )
736 widget = j->second.lock()->GetTypeName();
737 bbtkMessage("kernel",5,
738 "===> Found first part : "<<widget
739 << " "<<j->first.mTypeIn<<"->"
740 <<j->first.mTypeOut<<std::endl);
741 DataInfo ti( j->first.mTypeOut.GetType(), "");
742 DataInfo to( typeout.GetType(), "");
743 b = FindAdaptor( ti, to, adaptor );
746 bbtkMessage("kernel",5,
747 "===> Found second part : "<<adaptor
753 bbtkMessage("kernel",5,
754 "===> No second part found"<<std::endl);
761 bbtkDebugDecTab("kernel",7);
764 //===================================================================
766 //===================================================================
767 /// Creates an instance of a connection
768 Connection::Pointer Factory::NewConnection(BlackBox::Pointer from,
769 const std::string& output,
770 BlackBox::Pointer to,
771 const std::string& input) const
773 bbtkDebugMessage("kernel",7,"Factory::NewConnection(\""
774 <<from->bbGetName()<<"\",\""<<output<<"\",\""
775 <<to->bbGetName()<<"\",\""<<input
778 return Connection::New(from,output,to,input,
779 GetThisPointer<Factory>());
781 //===================================================================
785 //===================================================================
786 Package::Pointer Factory::GetPackage(const std::string& name) const
788 bbtkDebugMessageInc("kernel",9,"Factory::GetPackage(\""<<name<<"\")"
791 PackageMapType::const_iterator i = mPackageMap.find(name);
792 if ( i != mPackageMap.end() )
794 bbtkDebugDecTab("kernel",9);
799 bbtkDebugDecTab("kernel",9);
800 bbtkError("package \""<<name<<"\" unknown");
803 bbtkDebugDecTab("kernel",9);
805 //===================================================================
808 //===================================================================
809 void Factory::Check() const
811 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
813 PackageMapType::const_iterator i;
814 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
818 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
819 <<" ... OK"<<std::endl);
821 //===================================================================
823 //===================================================================
824 void Factory::WriteDotFilePackagesList(FILE *ff)
827 bbtkDebugMessageInc("kernel",9,"Factory::WriteDotFilePackagesList()"
831 fprintf( ff , "subgraph cluster_FACTORY {\n");
832 fprintf( ff , " label = \"PACKAGES\"%s\n", ";");
833 fprintf( ff , " style=filled%s\n",";");
834 fprintf( ff , " color=lightgrey%s\n",";");
835 fprintf( ff , " rankdir=TB%s\n",";");
838 PackageMapType::const_iterator i;
839 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
841 url=GetPackage(i->first)->GetDocURL();
842 fprintf(ff," %s [shape=ellipse, URL=\"%s\"]%s\n",i->first.c_str(),url.c_str(),";" );
844 fprintf( ff , "}\n\n");
845 bbtkDebugDecTab("kernel",9);
847 //===================================================================
850 void Factory::ShowGraphTypes(const std::string& name) const
853 PackageMapType::const_iterator i;
854 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
856 if (i->second->ContainsDescriptor(name))
858 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
860 // Don't pollute the file store with "temp_dir" directories ...
861 std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
862 std::string directory = "\"" + default_doc_dir + separator + "temp_dir" +separator + "\"";
863 std::string filename2 = default_doc_dir + separator + "temp_dir" + separator + "tmp.html";
866 std::string command("start \"Titre\" /D ");
868 std::string command("gnome-open ");
870 command=command + directory +" tmp.html";
872 ff=fopen(filename2.c_str(),"w");
874 fprintf(ff,"<html><head><title>TMP</title> <script type=\"text/javascript\"> <!--\n");
875 fprintf(ff," window.location=\"%s#%s\";\n" , i->second->GetDocURL().c_str(),name.c_str() );
876 fprintf(ff,"//--></script></head><body></body></html>\n");
879 //fprintf(ff, "<a href=\"%s#%s\">Link</a>\n", i->second->GetDocURL().c_str(),name.c_str() );
881 system( command.c_str() );
886 bbtkDebugDecTab("kernel",9);
889 bbtkError("No package of the factory contains any black box <"
897 void Factory::CreateHtmlIndex(IndexEntryType type,
898 const std::string& filename)
900 bbtkDebugMessageInc("kernel",9,"Factory::CreateHtmlIndex(\""
901 <<filename<<"\")"<<bbtkendl);
905 typedef std::map<std::string,
906 std::vector<BlackBoxDescriptor::Pointer> > IndexType;
908 // Builds the index map
909 PackageMapType::const_iterator i;
910 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
912 Package::Pointer pack = i->second;
913 if (pack->GetName()=="user") continue;
914 Package::DescriptorMapType::const_iterator j;
915 for (j = pack->GetDescriptorMap().begin();
916 j!= pack->GetDescriptorMap().end();
921 if ( type==Adaptors )
923 if (j->second->GetKind() == BlackBoxDescriptor::STANDARD )
927 if (j->second->GetKind() != BlackBoxDescriptor::STANDARD )
930 std::vector<std::string> keys;
934 k += pack->GetName();
936 title = "Boxes by package";
938 else if ((type==Initials) || (type==Adaptors))
940 std::string init(" ");
941 init[0] = std::toupper(j->second->GetTypeName()[0]);
942 keys.push_back(init);
943 title = "Alphabetical list";
945 else if (type==Categories)
947 // Split the category string
948 std::string delimiters = ";,";
949 Utilities::SplitString(j->second->GetCategory(),
952 keys.push_back(" NONE");
953 title = "Boxes by category";
956 std::vector<std::string>::const_iterator k;
957 for (k=keys.begin(); k!=keys.end(); ++k )
959 IndexType::iterator p;
961 if (p != index.end())
963 p->second.push_back(j->second);
967 std::vector<BlackBoxDescriptor::Pointer> v;
968 v.push_back(j->second);
975 //---------------------
978 s.open(filename.c_str());
981 bbtkError("Factory::CreateHtmlIndex : could not open file '"
985 //----------------------
987 s << "<html lang=\"en\">\n";
989 s << "<title>"<<title<<"</title>\n";
990 s << "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n";
991 s << "<meta name=\"description\" content=\""<<title<<"\">\n";
992 s << "<meta name=\"generator\" content=\"\">\n";
993 s << "<link title=\"Top\" rel=\"top\" href=\"#Top\">\n";
994 //<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
995 s << "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><style type=\"text/css\"><!--\n";
996 s << "pre.display { font-family:inherit }\n";
997 s << "pre.format { font-family:inherit }\n";
998 s << "pre.smalldisplay { font-family:inherit; font-size:smaller }\n";
999 s << "pre.smallformat { font-family:inherit; font-size:smaller }\n";
1000 s << "pre.smallexample { font-size:smaller }\n";
1001 s << "pre.smalllisp { font-size:smaller }\n";
1002 s << "span.sc { font-variant:small-caps }\n";
1003 s << "span.roman { font-family:serif; font-weight:normal; } \n";
1004 s << "span.sansserif { font-family:sans-serif; font-weight:normal; }\n";
1005 s << "--></style>\n";
1007 //----------------------
1009 //----------------------
1012 s << "<a name=\"Top\"></a>\n";
1013 s << "<h1 class=\"settitle\">"<<title<<"</h1>\n";
1015 IndexType::iterator ii;
1016 for (ii=index.begin();ii!=index.end();++ii)
1018 s << "<a href=\"#"<<ii->first<<"\">"<<ii->first<<"</a> ";
1021 for (ii=index.begin();ii!=index.end();++ii)
1024 s << "<p><a href=\"#Top\">Top</a>";
1027 s << "<a name=\""<<ii->first<<"\"></a>\n";
1028 s << "<p><a href=\""<<ii->first<<"/index.html\">"
1029 << ii->first<<"</a>\n";
1031 s << " - \n";
1033 s << "<a name=\"doxygen\"></a>\n";
1037 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1038 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1040 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1041 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1045 s << "<a name=\""<<ii->first<<"\"></a>\n";
1046 s << "<p><b>"<<ii->first<<"</b>\n";
1050 s << "<p><TABLE cellspacing=0 cellpadding=3>\n";
1052 std::vector<BlackBoxDescriptor::Pointer>::iterator di;
1053 for (di=ii->second.begin();di!=ii->second.end();++di)
1055 std::string pack = (*di)->GetPackage()->GetName();
1056 std::string name = (*di)->GetTypeName();
1057 Utilities::html_format(name);
1058 std::string descr = (*di)->GetDescription();
1059 Utilities::html_format(descr);
1061 s << "<TD style='vertical-align: top;'>";
1062 s << " <a href=\""<<pack
1063 <<"/index.html#"<<name<<"\">"
1064 <<pack<<"::"<<name<<"</a>";
1066 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1073 //----------------------
1078 ptm = gmtime ( &rawtime );
1081 s << "Automatically generated by <b>bbtk</b> on "
1082 << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900
1083 << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n";
1084 s << "</body></html>\n";
1086 //----------------------
1089 bbtkDebugDecTab("kernel",9);
1092 //==========================================================================
1093 std::string Factory::GetObjectName() const
1095 return std::string("Factory");
1097 //==========================================================================
1099 //==========================================================================
1100 std::string Factory::GetObjectInfo() const
1102 std::stringstream i;
1105 //==========================================================================
1107 //==========================================================================
1108 size_t Factory::GetObjectSize() const
1110 size_t s = Superclass::GetObjectSize();
1111 s += Factory::GetObjectInternalSize();
1114 //==========================================================================
1115 //==========================================================================
1116 size_t Factory::GetObjectInternalSize() const
1118 size_t s = sizeof(Factory);
1121 //==========================================================================
1122 //==========================================================================
1123 size_t Factory::GetObjectRecursiveSize() const
1125 size_t s = Superclass::GetObjectRecursiveSize();
1126 s += Factory::GetObjectInternalSize();
1128 PackageMapType::const_iterator i;
1129 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
1131 s += i->second->GetObjectRecursiveSize();
1135 //==========================================================================