1 /*=========================================================================
3 Module: $RCSfile: bbtkFactory.cxx,v $
5 Date: $Date: 2012/11/14 07:12:00 $
6 Version: $Revision: 1.54 $
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 )
145 // Note : in the following :
146 // name : the user supplied name
147 // - abreviated name e.g. pkg pkg.so libbpkg libbbpkg.so
148 // - relative full name e.g. ./libbbpkg.so ../../libbbpkg.so
149 // - absolute full name e.g. /home/usrname/proj/lib/libbbpkg.so
150 // same for Windows, with c:, d: ...
152 // lastname : string before the last / (if any), or user supplied name
157 bbtkDebugMessageInc("kernel",7,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
158 bbtkMessage("debug",1,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
160 std::vector<std::string> package_paths;
161 std::string libname; // full path library name
162 std::string pkgname; // e.g. libbb<pkgname>.so
166 pkgname = Utilities::ExtractPackageName(name,upath);
168 bbtkMessage("debug",1,"Package name ["<<pkgname<<"]"<<std::endl);
169 bbtkMessage("debug",1,"Package path ["<<upath<<"]"<<std::endl);
171 // no loading package if already loaded
172 PackageMapType::iterator iUnload;
173 iUnload = mPackageMap.find(pkgname);
175 //EED Debuging message
176 // std::cout << "EED Factory::LoadPackage " << std::endl;
177 // PackageMapType::iterator it;
178 // for ( it=mPackageMap.begin() ; it != mPackageMap.end(); it++ )
179 // std::cout << (*it).first << " ";
180 // std::cout << std::endl;
183 if (iUnload != mPackageMap.end())
185 bbtkMessage("output",2,"["<< pkgname <<"] already loaded" << std::endl);
189 // =================================================
190 // The following structure was checked to work
191 // with any type of relative/absolute path.
192 // Please don't modify it without checking
193 // *all* the cases. JP
194 //==================================================
197 bool foundFile = false;
199 // If path provided by user will be the first scanned :
200 // push it into vector of paths
201 if (upath.length()>0) // ------------------------------------- check user supplied location
203 if (name[0] != '.' && name[0] != '/' && name[1]!= ':')
205 bbtkError("Use absolute or relative path name! ["<<name<<"] is an illegal name");
209 // std::string path = Utilities::ExpandLibName(upath, false);
211 std::string path = Utilities::ExpandLibName(name,false); // keep last item, here.
215 Utilities::ExtractPackageName(path,p2);
216 //libname = Utilities::MakeLibnameFromPath(path, pkgname);
217 libname = Utilities::MakeLibnameFromPath(p2, pkgname); // remove last item
218 // Check if library exists
219 if ( !Utilities::FileExists(libname) )
221 // The following is *NOT* a debug time message :
222 // It's a user intended message.
223 // Please don't remove it.
224 bbtkMessage("output",3," [" <<libname
225 <<"] : doesn't exist" <<std::endl);
229 ok = DoLoadPackage( libname, pkgname, path);
234 bbtkError("Path ["<<upath<<"] doesn't exist");
238 else // ----------------------------------------------------- iterate on the paths
241 std::string path = ".";
242 package_paths = ConfigurationFile::GetInstance().Get_package_paths();
243 std::vector<std::string>::iterator i;
244 for (i=package_paths.begin();i!=package_paths.end();++i)
248 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = path "<<path<<std::endl;
249 // we *really* want '.' to be the current working directory
252 char buf[2048]; // for getcwd
253 char * currentDir = getcwd(buf, 2048);
254 std::string cwd(currentDir);
255 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = currentDir "<<currentDir<<std::endl;
258 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = path "<<path<<" pkgnam="<<pkgname<<std::endl;
259 libname = Utilities::MakeLibnameFromPath(path, pkgname);
261 bbtkMessage("debug",2,"-> Trying to load [" << libname << "]" <<std::endl);
263 // Check if library exists
264 if ( !Utilities::FileExists(libname) )
266 // The following is *NOT* a debug time message :
267 // It's a user intended message.
268 // Please don't remove it.
269 bbtkMessage("output",3,
270 " [" <<libname <<"] : doesn't exist" <<std::endl);
271 continue; // try next path
275 // Try to Load the library
277 ok = DoLoadPackage( libname, pkgname, path);
280 bbtkMessage("debug",2," OK"<<std::endl);
282 break; // we stop iterating even if error : have to signal it to user
283 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
287 if( !ok ) // nothing was loaded
291 bbtkError("Could not find package ["<<pkgname<< "]");
295 #if defined(__GNUC__)
296 bbtkError("Could not load package ["<< pkgname
298 << " Opening "<<libname<<" failed"
299 << " Reason: "<< dlerror());
300 #elif defined(_WIN32)
301 bbtkError("Could not load package ["<<pkgname
302 <<"] :"<< std::endl << " Error loading " <<libname);
304 // look how to get the error message on win
306 // it is the bordel !! (the bloody fucking bordel, you mean?)
307 // look : http://msdn2.microsoft.com/en-us/library/ms680582.aspx
311 bbtkMessage("output",2,"[" << libname << "] loaded" << std::endl);
318 //===================================================================
319 /// \brief UnLoads a package.
321 /// The package must have been previously loaded by LoadPackage.
322 /// If the entry is found in the map, calls ClosePackage
323 void Factory::UnLoadPackage( const std::string& name )
325 bbtkDebugMessageInc("kernel",7,"Factory::UnLoadPackage(\""
326 <<name<<"\")"<<std::endl);
328 PackageMapType::iterator i;
329 i = mPackageMap.find(name);
330 if (i == mPackageMap.end())
332 bbtkError("cannot unload package \""<<name
333 <<"\" : package not loaded !");
336 bbtkDebugDecTab("kernel",7);
338 //===================================================================
341 //===================================================================
342 void Factory::CloseAllPackages()
344 bbtkDebugMessageInc("kernel",7,"Factory::CloseAllPackages()"<<std::endl);
346 std::vector< Package::WeakPointer > mAlive;
349 while (mPackageMap.begin() != mPackageMap.end())
351 PackageMapType::iterator i = mPackageMap.begin();
352 Package::WeakPointer p = i->second;
354 if (p.lock()) mAlive.push_back(p);
356 std::vector< Package::WeakPointer >::iterator i;
357 for (i=mAlive.begin();i!=mAlive.end();++i)
359 // If not dead : reinsert
362 bbtkDebugMessage("kernel",7,"Package "<<i->lock()->GetName()
363 <<" still alive"<<std::endl);
364 // InsertPackage(i->lock());
368 while (mPackageMap.size()>0);
370 bbtkDebugDecTab("kernel",7);
372 //===================================================================
374 //===================================================================
375 /// \brief Close the package referenced by the iterator
377 /// First removes the factory from the set of factories which use the package
378 /// If the set is empty then :
379 /// If it is a dynamically loaded package :
380 /// - Loads and calls the function "<name>DeletePackage" of the dynamic library (responsible for package desallocation)
381 /// - Closes the dynamic library
383 /// - deletes the package normally
385 /// Finally erases the package entry in the packages map
386 void Factory::ClosePackage(PackageMapType::iterator& i)
388 bbtkDebugMessageInc("kernel",7,"Factory::ClosePackage(\""
389 <<i->second->GetName()
393 // Removes this from the set of factories which use the package
394 i->second->RemoveFactory(GetThisPointer<Factory>());
395 Package::WeakPointer p = i->second;
396 // remove the entry in the map
397 mPackageMap.erase(i);
398 // Release the package if not already destroyed
403 bbtkDebugDecTab("kernel",7);
405 //===================================================================
409 //===================================================================
410 void Factory::PrintHelpListPackages(bool details, bool adaptors) const
412 bbtkDebugMessageInc("kernel",9,"Factory::PrintPackages"<<std::endl);
414 PackageMapType::const_iterator i;
415 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
417 bbtkMessage("help",1, i->first << std::endl);
419 i->second->PrintHelpListDescriptors(false,adaptors);
423 bbtkDebugDecTab("kernel",9);
425 //===================================================================
427 //===================================================================
428 /// Displays help on a package
429 void Factory::PrintHelpPackage(const std::string& name, bool adaptors) const
431 bbtkDebugMessageInc("kernel",9,"Factory::PrintHelpPackage(\""
435 PackageMapType::const_iterator i = mPackageMap.find(name);
436 if ( i != mPackageMap.end() )
438 bbtkMessage("help",1, "Package "<<i->first<<" ");
440 if (i->second->GetVersion().length()>0)
441 bbtkMessageCont("help",1,"v" <<i->second->GetVersion());
443 if (i->second->GetAuthor().length()>0)
444 bbtkMessageCont("help",1,"- "<<i->second->GetAuthor());
446 if (i->second->GetCategory().length()>0)
447 bbtkMessageCont("help",1,"- "<<i->second->GetCategory());
449 bbtkMessageCont("help",1,std::endl);
450 bbtkIncTab("help",1);
451 bbtkMessage("help",1,i->second->GetDescription()<<std::endl);
452 if (i->second->GetNumberOfDescriptors()>0)
454 bbtkMessage("help",1, "Black boxes : "<<std::endl);
455 i->second->PrintHelpListDescriptors(true,adaptors);
459 bbtkMessage("help",1, "No black boxes"<<std::endl);
461 bbtkDecTab("help",1);
465 bbtkDebugDecTab("kernel",9);
466 bbtkError("package \""<<name<<"\" unknown");
469 bbtkDebugDecTab("kernel",9);
471 //===================================================================
473 //===================================================================
474 /// Prints help on the black box of type <name>
475 /// Returns the package to which it belongs
476 void Factory::PrintHelpDescriptor(const std::string& name,
477 std::string& package,
480 bbtkDebugMessageInc("kernel",9,"Factory::PrintHelpDescriptor(\""
485 PackageMapType::const_iterator i;
486 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
488 if (i->second->ContainsDescriptor(name))
490 i->second->PrintHelpDescriptor(name,full);
491 package = i->second->GetName();
496 bbtkDebugDecTab("kernel",9);
499 bbtkError("No package of the factory contains any black box <"
503 //===================================================================
506 //===================================================================
507 /// Inserts a package in the factory
508 void Factory::InsertPackage( Package::Pointer p )
510 bbtkDebugMessageInc("kernel",9,"Factory::InsertPackage(\""<<
511 p->GetName()<<"\")"<<std::endl);
513 p->AddFactory(GetThisPointer<Factory>());
514 mPackageMap[p->GetName()] = p;
515 bbtkDebugDecTab("kernel",9);
517 //===================================================================
519 //===================================================================
520 /// Removes a package from the factory (and deletes it)
521 void Factory::RemovePackage( Package::Pointer p )
523 bbtkDebugMessageInc("kernel",9,"Factory::RemovePackage(\""<<
524 p->GetName()<<"\")"<<std::endl);
526 PackageMapType::iterator i;
527 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
529 if (i->second == p) break;
532 if (i!=mPackageMap.end())
538 bbtkError("Factory::RemovePackage(\""<<
539 p->GetName()<<"\") : package absent from factory");
542 bbtkDebugDecTab("kernel",9);
544 //===================================================================
548 std::string Factory::GetPackageNameOfaBlackBox(std::string boxType)
550 std::string result="<void bbtk package name>";
551 PackageMapType::const_iterator i;
552 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
554 if ( i->second->ifBoxExist( boxType ) == true)
563 //===================================================================
564 /// Creates an instance of a black box of type <type> with name <name>
565 BlackBox::Pointer Factory::NewBlackBox(const std::string& type,
566 const std::string& name) const
568 bbtkDebugMessageInc("kernel",7,"Factory::NewBlackBox(\""
569 <<type<<"\",\""<<name<<"\")"<<std::endl);
572 PackageMapType::const_iterator i;
573 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
575 b = i->second->NewBlackBox(type,name);
580 bbtkError("black box type \""<<type<<"\" unknown");
583 bbtkDebugDecTab("kernel",7);
586 //===================================================================
588 //===================================================================
589 /// Creates an instance of a black box of type <type> with name <name>
590 BlackBox::Pointer Factory::NewAdaptor(const DataInfo& typein,
591 const DataInfo& typeout,
592 const std::string& name) const
594 bbtkDebugMessageInc("kernel",8,"Factory::NewAdaptor("
597 <<name<<"\")"<<bbtkendl);
601 PackageMapType::const_iterator i;
602 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
604 b = i->second->NewAdaptor(typein,typeout,name);
609 bbtkError("no "<<typein<<" to "<<typeout
610 <<" adaptor available");
613 bbtkDebugDecTab("kernel",7);
616 //===================================================================
619 //===================================================================
620 /// Creates an instance of a black box of type <type> with name <name>
621 BlackBox::Pointer Factory::NewWidgetAdaptor(const DataInfo& typein,
622 const DataInfo& typeout,
623 const std::string& name) const
625 bbtkDebugMessageInc("kernel",8,"Factory::NewWidgetAdaptor(<"
628 <<name<<"\")"<<bbtkendl);
632 PackageMapType::const_iterator i;
633 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
635 b = i->second->NewWidgetAdaptor(typein,
642 bbtkError("no "<<typein<<" to "<<typeout
643 <<"> widget adaptor available");
646 bbtkDebugDecTab("kernel",7);
649 //===================================================================
651 //===================================================================
652 /// Creates an instance of a black box of type <type> with name <name>
653 bool Factory::FindAdaptor(const DataInfo& typein,
654 const DataInfo& typeout,
655 std::string& adaptor) const
657 bbtkDebugMessageInc("kernel",8,"Factory::FindAdaptor(<"
659 <<typeout<<">)"<<bbtkendl);
662 PackageMapType::const_iterator i;
663 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
665 b = i->second->FindAdaptor(typein,
673 bbtkError("no "<<typein<<" to "<<typeout
674 <<"> widget adaptor available");
678 bbtkDebugDecTab("kernel",7);
681 //===================================================================
683 //===================================================================
684 /// Creates an instance of a black box of type <type> with name <name>
685 bool Factory::FindWidgetAdaptor(const DataInfo& typein,
686 const DataInfo& typeout,
687 std::string& adaptor) const
689 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
691 <<typeout<<">)"<<bbtkendl);
694 PackageMapType::const_iterator i;
695 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
697 b = i->second->FindWidgetAdaptor(typein,
702 bbtkDebugDecTab("kernel",7);
705 //===================================================================
707 //===================================================================
708 /// Creates an instance of a black box of type <type> with name <name>
709 bool Factory::FindWidgetAdaptor2(const DataInfo& typein,
710 const DataInfo& typeout,
712 std::string& adaptor) const
714 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
716 <<typeout<<">)"<<bbtkendl);
719 adaptor = widget = "";
720 PackageMapType::const_iterator i;
721 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
723 b = i->second->FindWidgetAdaptor(typein,
730 // Look for a widget adaptor with good nature out
731 bbtkMessage("kernel",5,
732 "*** Looking for a two pieces widget adaptor for : "
733 << typein << "->"<<typeout<<std::endl);
734 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
736 Package::AdaptorMapType::const_iterator j;
737 for (j=i->second->GetAdaptorMap().begin();
738 j!=i->second->GetAdaptorMap().end();
741 if ( ( j->first.mKind ==
742 BlackBoxDescriptor::DEFAULT_GUI) &&
743 //(j->first.mTypeIn == typein) &&
744 (j->first.mTypeOut.GetNature() == typeout.GetNature() )
747 widget = j->second.lock()->GetTypeName();
748 bbtkMessage("kernel",5,
749 "===> Found first part : "<<widget
750 << " "<<j->first.mTypeIn<<"->"
751 <<j->first.mTypeOut<<std::endl);
752 DataInfo ti( j->first.mTypeOut.GetType(), "");
753 DataInfo to( typeout.GetType(), "");
754 b = FindAdaptor( ti, to, adaptor );
757 bbtkMessage("kernel",5,
758 "===> Found second part : "<<adaptor
764 bbtkMessage("kernel",5,
765 "===> No second part found"<<std::endl);
772 bbtkDebugDecTab("kernel",7);
775 //===================================================================
777 //===================================================================
778 /// Creates an instance of a connection
779 Connection::Pointer Factory::NewConnection(BlackBox::Pointer from,
780 const std::string& output,
781 BlackBox::Pointer to,
782 const std::string& input) const
784 bbtkDebugMessage("kernel",7,"Factory::NewConnection(\""
785 <<from->bbGetName()<<"\",\""<<output<<"\",\""
786 <<to->bbGetName()<<"\",\""<<input
789 return Connection::New(from,output,to,input,
790 GetThisPointer<Factory>());
792 //===================================================================
796 //===================================================================
797 Package::Pointer Factory::GetPackage(const std::string& name) const
799 bbtkDebugMessageInc("kernel",9,"Factory::GetPackage(\""<<name<<"\")"
802 PackageMapType::const_iterator i = mPackageMap.find(name);
803 if ( i != mPackageMap.end() )
805 bbtkDebugDecTab("kernel",9);
810 bbtkDebugDecTab("kernel",9);
811 bbtkError("package \""<<name<<"\" unknown");
814 bbtkDebugDecTab("kernel",9);
816 //===================================================================
819 //===================================================================
820 void Factory::Check() const
822 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
824 PackageMapType::const_iterator i;
825 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
829 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
830 <<" ... OK"<<std::endl);
832 //===================================================================
834 //===================================================================
835 void Factory::WriteDotFilePackagesList(FILE *ff)
838 bbtkDebugMessageInc("kernel",9,"Factory::WriteDotFilePackagesList()"
842 fprintf( ff , "subgraph cluster_FACTORY {\n");
843 fprintf( ff , " label = \"PACKAGES\"%s\n", ";");
844 fprintf( ff , " style=filled%s\n",";");
845 fprintf( ff , " color=lightgrey%s\n",";");
846 fprintf( ff , " rankdir=TB%s\n",";");
849 PackageMapType::const_iterator i;
850 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
852 url=GetPackage(i->first)->GetDocURL();
853 fprintf(ff," %s [shape=ellipse, URL=\"%s\"]%s\n",i->first.c_str(),url.c_str(),";" );
855 fprintf( ff , "}\n\n");
856 bbtkDebugDecTab("kernel",9);
858 //===================================================================
861 void Factory::ShowGraphTypes(const std::string& name) const
864 PackageMapType::const_iterator i;
865 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
867 if (i->second->ContainsDescriptor(name))
869 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
871 // Don't pollute the file store with "temp_dir" directories ...
872 std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
873 std::string directory = "\"" + default_doc_dir + separator + "temp_dir" +separator + "\"";
874 std::string filename2 = default_doc_dir + separator + "temp_dir" + separator + "tmp.html";
877 std::string command("start \"Titre\" /D ");
879 std::string command("gnome-open ");
881 command=command + directory +" tmp.html";
883 ff=fopen(filename2.c_str(),"w");
885 fprintf(ff,"<html><head><title>TMP</title> <script type=\"text/javascript\"> <!--\n");
886 fprintf(ff," window.location=\"%s#%s\";\n" , i->second->GetDocURL().c_str(),name.c_str() );
887 fprintf(ff,"//--></script></head><body></body></html>\n");
890 //fprintf(ff, "<a href=\"%s#%s\">Link</a>\n", i->second->GetDocURL().c_str(),name.c_str() );
892 system( command.c_str() );
897 bbtkDebugDecTab("kernel",9);
900 bbtkError("No package of the factory contains any black box <"
908 void Factory::CreateHtmlIndex(IndexEntryType type,
909 const std::string& filename)
911 bbtkDebugMessageInc("kernel",9,"Factory::CreateHtmlIndex(\""
912 <<filename<<"\")"<<bbtkendl);
916 typedef std::map<std::string,
917 std::vector<BlackBoxDescriptor::Pointer> > IndexType;
919 // Builds the index map
920 PackageMapType::const_iterator i;
921 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
923 Package::Pointer pack = i->second;
924 if (pack->GetName()=="user") continue;
925 Package::DescriptorMapType::const_iterator j;
926 for (j = pack->GetDescriptorMap().begin();
927 j!= pack->GetDescriptorMap().end();
932 if ( type==Adaptors )
934 if (j->second->GetKind() == BlackBoxDescriptor::STANDARD )
938 if (j->second->GetKind() != BlackBoxDescriptor::STANDARD )
941 std::vector<std::string> keys;
945 k += pack->GetName();
947 title = "Boxes by package";
949 else if ((type==Initials) || (type==Adaptors))
951 std::string init(" ");
952 init[0] = std::toupper(j->second->GetTypeName()[0]);
953 keys.push_back(init);
954 title = "Alphabetical list";
956 else if (type==Categories)
958 // Split the category string
959 std::string delimiters = ";,";
960 Utilities::SplitString(j->second->GetCategory(),
963 keys.push_back(" NONE");
964 title = "Boxes by category";
967 std::vector<std::string>::const_iterator k;
968 for (k=keys.begin(); k!=keys.end(); ++k )
970 IndexType::iterator p;
972 if (p != index.end())
974 p->second.push_back(j->second);
978 std::vector<BlackBoxDescriptor::Pointer> v;
979 v.push_back(j->second);
986 //---------------------
989 s.open(filename.c_str());
992 bbtkError("Factory::CreateHtmlIndex : could not open file '"
996 //----------------------
998 s << "<html lang=\"en\">\n";
1000 s << "<title>"<<title<<"</title>\n";
1001 s << "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n";
1002 s << "<meta name=\"description\" content=\""<<title<<"\">\n";
1003 s << "<meta name=\"generator\" content=\"\">\n";
1004 s << "<link title=\"Top\" rel=\"top\" href=\"#Top\">\n";
1005 //<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
1006 s << "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><style type=\"text/css\"><!--\n";
1007 s << "pre.display { font-family:inherit }\n";
1008 s << "pre.format { font-family:inherit }\n";
1009 s << "pre.smalldisplay { font-family:inherit; font-size:smaller }\n";
1010 s << "pre.smallformat { font-family:inherit; font-size:smaller }\n";
1011 s << "pre.smallexample { font-size:smaller }\n";
1012 s << "pre.smalllisp { font-size:smaller }\n";
1013 s << "span.sc { font-variant:small-caps }\n";
1014 s << "span.roman { font-family:serif; font-weight:normal; } \n";
1015 s << "span.sansserif { font-family:sans-serif; font-weight:normal; }\n";
1016 s << "--></style>\n";
1018 //----------------------
1020 //----------------------
1023 s << "<a name=\"Top\"></a>\n";
1024 s << "<h1 class=\"settitle\">"<<title<<"</h1>\n";
1026 IndexType::iterator ii;
1027 for (ii=index.begin();ii!=index.end();++ii)
1029 s << "<a href=\"#"<<ii->first<<"\">"<<ii->first<<"</a> ";
1032 for (ii=index.begin();ii!=index.end();++ii)
1035 s << "<p><a href=\"#Top\">Top</a>";
1038 s << "<a name=\""<<ii->first<<"\"></a>\n";
1039 s << "<p><a href=\""<<ii->first<<"/index.html\">"
1040 << ii->first<<"</a>\n";
1042 s << " - \n";
1044 s << "<a name=\"doxygen\"></a>\n";
1048 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1049 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1051 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1052 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1056 s << "<a name=\""<<ii->first<<"\"></a>\n";
1057 s << "<p><b>"<<ii->first<<"</b>\n";
1061 s << "<p><TABLE cellspacing=0 cellpadding=3>\n";
1063 std::vector<BlackBoxDescriptor::Pointer>::iterator di;
1064 for (di=ii->second.begin();di!=ii->second.end();++di)
1066 std::string pack = (*di)->GetPackage()->GetName();
1067 std::string name = (*di)->GetTypeName();
1068 Utilities::html_format(name);
1069 std::string descr = (*di)->GetDescription();
1070 Utilities::html_format(descr);
1072 s << "<TD style='vertical-align: top;'>";
1073 s << " <a href=\""<<pack
1074 <<"/index.html#"<<name<<"\">"
1075 <<pack<<"::"<<name<<"</a>";
1077 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1084 //----------------------
1089 ptm = gmtime ( &rawtime );
1092 s << "Automatically generated by <b>bbtk</b> on "
1093 << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900
1094 << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n";
1095 s << "</body></html>\n";
1097 //----------------------
1100 bbtkDebugDecTab("kernel",9);
1103 //==========================================================================
1104 std::string Factory::GetObjectName() const
1106 return std::string("Factory");
1108 //==========================================================================
1110 //==========================================================================
1111 std::string Factory::GetObjectInfo() const
1113 std::stringstream i;
1116 //==========================================================================
1118 //==========================================================================
1119 size_t Factory::GetObjectSize() const
1121 size_t s = Superclass::GetObjectSize();
1122 s += Factory::GetObjectInternalSize();
1125 //==========================================================================
1126 //==========================================================================
1127 size_t Factory::GetObjectInternalSize() const
1129 size_t s = sizeof(Factory);
1132 //==========================================================================
1133 //==========================================================================
1134 size_t Factory::GetObjectRecursiveSize() const
1136 size_t s = Superclass::GetObjectRecursiveSize();
1137 s += Factory::GetObjectInternalSize();
1139 PackageMapType::const_iterator i;
1140 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
1142 s += i->second->GetObjectRecursiveSize();
1146 //==========================================================================