1 /*=========================================================================
3 Module: $RCSfile: bbtkFactory.cxx,v $
5 Date: $Date: 2012/10/16 06:31:04 $
6 Version: $Revision: 1.53 $
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>());
515 printf("EED Factory::InsertPackage %s\n", p->GetName().c_str() );
517 mPackageMap[p->GetName()] = p;
519 bbtkDebugDecTab("kernel",9);
521 //===================================================================
523 //===================================================================
524 /// Removes a package from the factory (and deletes it)
525 void Factory::RemovePackage( Package::Pointer p )
527 bbtkDebugMessageInc("kernel",9,"Factory::RemovePackage(\""<<
528 p->GetName()<<"\")"<<std::endl);
530 PackageMapType::iterator i;
531 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
533 if (i->second == p) break;
536 if (i!=mPackageMap.end())
542 bbtkError("Factory::RemovePackage(\""<<
543 p->GetName()<<"\") : package absent from factory");
546 bbtkDebugDecTab("kernel",9);
548 //===================================================================
552 std::string Factory::GetPackageNameOfaBlackBox(std::string boxType)
554 std::string result="<void bbtk package name>";
555 PackageMapType::const_iterator i;
556 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
558 if ( i->second->ifBoxExist( boxType ) == true)
567 //===================================================================
568 /// Creates an instance of a black box of type <type> with name <name>
569 BlackBox::Pointer Factory::NewBlackBox(const std::string& type,
570 const std::string& name) const
572 bbtkDebugMessageInc("kernel",7,"Factory::NewBlackBox(\""
573 <<type<<"\",\""<<name<<"\")"<<std::endl);
576 PackageMapType::const_iterator i;
577 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
579 b = i->second->NewBlackBox(type,name);
584 bbtkError("black box type \""<<type<<"\" unknown");
587 bbtkDebugDecTab("kernel",7);
590 //===================================================================
592 //===================================================================
593 /// Creates an instance of a black box of type <type> with name <name>
594 BlackBox::Pointer Factory::NewAdaptor(const DataInfo& typein,
595 const DataInfo& typeout,
596 const std::string& name) const
598 bbtkDebugMessageInc("kernel",8,"Factory::NewAdaptor("
601 <<name<<"\")"<<bbtkendl);
605 PackageMapType::const_iterator i;
606 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
608 b = i->second->NewAdaptor(typein,typeout,name);
613 bbtkError("no "<<typein<<" to "<<typeout
614 <<" adaptor available");
617 bbtkDebugDecTab("kernel",7);
620 //===================================================================
623 //===================================================================
624 /// Creates an instance of a black box of type <type> with name <name>
625 BlackBox::Pointer Factory::NewWidgetAdaptor(const DataInfo& typein,
626 const DataInfo& typeout,
627 const std::string& name) const
629 bbtkDebugMessageInc("kernel",8,"Factory::NewWidgetAdaptor(<"
632 <<name<<"\")"<<bbtkendl);
636 PackageMapType::const_iterator i;
637 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
639 b = i->second->NewWidgetAdaptor(typein,
646 bbtkError("no "<<typein<<" to "<<typeout
647 <<"> widget adaptor available");
650 bbtkDebugDecTab("kernel",7);
653 //===================================================================
655 //===================================================================
656 /// Creates an instance of a black box of type <type> with name <name>
657 bool Factory::FindAdaptor(const DataInfo& typein,
658 const DataInfo& typeout,
659 std::string& adaptor) const
661 bbtkDebugMessageInc("kernel",8,"Factory::FindAdaptor(<"
663 <<typeout<<">)"<<bbtkendl);
666 PackageMapType::const_iterator i;
667 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
669 b = i->second->FindAdaptor(typein,
677 bbtkError("no "<<typein<<" to "<<typeout
678 <<"> widget adaptor available");
682 bbtkDebugDecTab("kernel",7);
685 //===================================================================
687 //===================================================================
688 /// Creates an instance of a black box of type <type> with name <name>
689 bool Factory::FindWidgetAdaptor(const DataInfo& typein,
690 const DataInfo& typeout,
691 std::string& adaptor) const
693 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
695 <<typeout<<">)"<<bbtkendl);
698 PackageMapType::const_iterator i;
699 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
701 b = i->second->FindWidgetAdaptor(typein,
706 bbtkDebugDecTab("kernel",7);
709 //===================================================================
711 //===================================================================
712 /// Creates an instance of a black box of type <type> with name <name>
713 bool Factory::FindWidgetAdaptor2(const DataInfo& typein,
714 const DataInfo& typeout,
716 std::string& adaptor) const
718 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
720 <<typeout<<">)"<<bbtkendl);
723 adaptor = widget = "";
724 PackageMapType::const_iterator i;
725 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
727 b = i->second->FindWidgetAdaptor(typein,
734 // Look for a widget adaptor with good nature out
735 bbtkMessage("kernel",5,
736 "*** Looking for a two pieces widget adaptor for : "
737 << typein << "->"<<typeout<<std::endl);
738 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
740 Package::AdaptorMapType::const_iterator j;
741 for (j=i->second->GetAdaptorMap().begin();
742 j!=i->second->GetAdaptorMap().end();
745 if ( ( j->first.mKind ==
746 BlackBoxDescriptor::DEFAULT_GUI) &&
747 //(j->first.mTypeIn == typein) &&
748 (j->first.mTypeOut.GetNature() == typeout.GetNature() )
751 widget = j->second.lock()->GetTypeName();
752 bbtkMessage("kernel",5,
753 "===> Found first part : "<<widget
754 << " "<<j->first.mTypeIn<<"->"
755 <<j->first.mTypeOut<<std::endl);
756 DataInfo ti( j->first.mTypeOut.GetType(), "");
757 DataInfo to( typeout.GetType(), "");
758 b = FindAdaptor( ti, to, adaptor );
761 bbtkMessage("kernel",5,
762 "===> Found second part : "<<adaptor
768 bbtkMessage("kernel",5,
769 "===> No second part found"<<std::endl);
776 bbtkDebugDecTab("kernel",7);
779 //===================================================================
781 //===================================================================
782 /// Creates an instance of a connection
783 Connection::Pointer Factory::NewConnection(BlackBox::Pointer from,
784 const std::string& output,
785 BlackBox::Pointer to,
786 const std::string& input) const
788 bbtkDebugMessage("kernel",7,"Factory::NewConnection(\""
789 <<from->bbGetName()<<"\",\""<<output<<"\",\""
790 <<to->bbGetName()<<"\",\""<<input
793 return Connection::New(from,output,to,input,
794 GetThisPointer<Factory>());
796 //===================================================================
800 //===================================================================
801 Package::Pointer Factory::GetPackage(const std::string& name) const
803 bbtkDebugMessageInc("kernel",9,"Factory::GetPackage(\""<<name<<"\")"
806 PackageMapType::const_iterator i = mPackageMap.find(name);
807 if ( i != mPackageMap.end() )
809 bbtkDebugDecTab("kernel",9);
814 bbtkDebugDecTab("kernel",9);
815 bbtkError("package \""<<name<<"\" unknown");
818 bbtkDebugDecTab("kernel",9);
820 //===================================================================
823 //===================================================================
824 void Factory::Check() const
826 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
828 PackageMapType::const_iterator i;
829 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
833 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
834 <<" ... OK"<<std::endl);
836 //===================================================================
838 //===================================================================
839 void Factory::WriteDotFilePackagesList(FILE *ff)
842 bbtkDebugMessageInc("kernel",9,"Factory::WriteDotFilePackagesList()"
846 fprintf( ff , "subgraph cluster_FACTORY {\n");
847 fprintf( ff , " label = \"PACKAGES\"%s\n", ";");
848 fprintf( ff , " style=filled%s\n",";");
849 fprintf( ff , " color=lightgrey%s\n",";");
850 fprintf( ff , " rankdir=TB%s\n",";");
853 PackageMapType::const_iterator i;
854 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
856 url=GetPackage(i->first)->GetDocURL();
857 fprintf(ff," %s [shape=ellipse, URL=\"%s\"]%s\n",i->first.c_str(),url.c_str(),";" );
859 fprintf( ff , "}\n\n");
860 bbtkDebugDecTab("kernel",9);
862 //===================================================================
865 void Factory::ShowGraphTypes(const std::string& name) const
868 PackageMapType::const_iterator i;
869 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
871 if (i->second->ContainsDescriptor(name))
873 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
875 // Don't pollute the file store with "temp_dir" directories ...
876 std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
877 std::string directory = "\"" + default_doc_dir + separator + "temp_dir" +separator + "\"";
878 std::string filename2 = default_doc_dir + separator + "temp_dir" + separator + "tmp.html";
881 std::string command("start \"Titre\" /D ");
883 std::string command("gnome-open ");
885 command=command + directory +" tmp.html";
887 ff=fopen(filename2.c_str(),"w");
889 fprintf(ff,"<html><head><title>TMP</title> <script type=\"text/javascript\"> <!--\n");
890 fprintf(ff," window.location=\"%s#%s\";\n" , i->second->GetDocURL().c_str(),name.c_str() );
891 fprintf(ff,"//--></script></head><body></body></html>\n");
894 //fprintf(ff, "<a href=\"%s#%s\">Link</a>\n", i->second->GetDocURL().c_str(),name.c_str() );
896 system( command.c_str() );
901 bbtkDebugDecTab("kernel",9);
904 bbtkError("No package of the factory contains any black box <"
912 void Factory::CreateHtmlIndex(IndexEntryType type,
913 const std::string& filename)
915 bbtkDebugMessageInc("kernel",9,"Factory::CreateHtmlIndex(\""
916 <<filename<<"\")"<<bbtkendl);
920 typedef std::map<std::string,
921 std::vector<BlackBoxDescriptor::Pointer> > IndexType;
923 // Builds the index map
924 PackageMapType::const_iterator i;
925 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
927 Package::Pointer pack = i->second;
928 if (pack->GetName()=="user") continue;
929 Package::DescriptorMapType::const_iterator j;
930 for (j = pack->GetDescriptorMap().begin();
931 j!= pack->GetDescriptorMap().end();
936 if ( type==Adaptors )
938 if (j->second->GetKind() == BlackBoxDescriptor::STANDARD )
942 if (j->second->GetKind() != BlackBoxDescriptor::STANDARD )
945 std::vector<std::string> keys;
949 k += pack->GetName();
951 title = "Boxes by package";
953 else if ((type==Initials) || (type==Adaptors))
955 std::string init(" ");
956 init[0] = std::toupper(j->second->GetTypeName()[0]);
957 keys.push_back(init);
958 title = "Alphabetical list";
960 else if (type==Categories)
962 // Split the category string
963 std::string delimiters = ";,";
964 Utilities::SplitString(j->second->GetCategory(),
967 keys.push_back(" NONE");
968 title = "Boxes by category";
971 std::vector<std::string>::const_iterator k;
972 for (k=keys.begin(); k!=keys.end(); ++k )
974 IndexType::iterator p;
976 if (p != index.end())
978 p->second.push_back(j->second);
982 std::vector<BlackBoxDescriptor::Pointer> v;
983 v.push_back(j->second);
990 //---------------------
993 s.open(filename.c_str());
996 bbtkError("Factory::CreateHtmlIndex : could not open file '"
1000 //----------------------
1002 s << "<html lang=\"en\">\n";
1004 s << "<title>"<<title<<"</title>\n";
1005 s << "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n";
1006 s << "<meta name=\"description\" content=\""<<title<<"\">\n";
1007 s << "<meta name=\"generator\" content=\"\">\n";
1008 s << "<link title=\"Top\" rel=\"top\" href=\"#Top\">\n";
1009 //<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
1010 s << "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><style type=\"text/css\"><!--\n";
1011 s << "pre.display { font-family:inherit }\n";
1012 s << "pre.format { font-family:inherit }\n";
1013 s << "pre.smalldisplay { font-family:inherit; font-size:smaller }\n";
1014 s << "pre.smallformat { font-family:inherit; font-size:smaller }\n";
1015 s << "pre.smallexample { font-size:smaller }\n";
1016 s << "pre.smalllisp { font-size:smaller }\n";
1017 s << "span.sc { font-variant:small-caps }\n";
1018 s << "span.roman { font-family:serif; font-weight:normal; } \n";
1019 s << "span.sansserif { font-family:sans-serif; font-weight:normal; }\n";
1020 s << "--></style>\n";
1022 //----------------------
1024 //----------------------
1027 s << "<a name=\"Top\"></a>\n";
1028 s << "<h1 class=\"settitle\">"<<title<<"</h1>\n";
1030 IndexType::iterator ii;
1031 for (ii=index.begin();ii!=index.end();++ii)
1033 s << "<a href=\"#"<<ii->first<<"\">"<<ii->first<<"</a> ";
1036 for (ii=index.begin();ii!=index.end();++ii)
1039 s << "<p><a href=\"#Top\">Top</a>";
1042 s << "<a name=\""<<ii->first<<"\"></a>\n";
1043 s << "<p><a href=\""<<ii->first<<"/index.html\">"
1044 << ii->first<<"</a>\n";
1046 s << " - \n";
1048 s << "<a name=\"doxygen\"></a>\n";
1052 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1053 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1055 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1056 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1060 s << "<a name=\""<<ii->first<<"\"></a>\n";
1061 s << "<p><b>"<<ii->first<<"</b>\n";
1065 s << "<p><TABLE cellspacing=0 cellpadding=3>\n";
1067 std::vector<BlackBoxDescriptor::Pointer>::iterator di;
1068 for (di=ii->second.begin();di!=ii->second.end();++di)
1070 std::string pack = (*di)->GetPackage()->GetName();
1071 std::string name = (*di)->GetTypeName();
1072 Utilities::html_format(name);
1073 std::string descr = (*di)->GetDescription();
1074 Utilities::html_format(descr);
1076 s << "<TD style='vertical-align: top;'>";
1077 s << " <a href=\""<<pack
1078 <<"/index.html#"<<name<<"\">"
1079 <<pack<<"::"<<name<<"</a>";
1081 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1088 //----------------------
1093 ptm = gmtime ( &rawtime );
1096 s << "Automatically generated by <b>bbtk</b> on "
1097 << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900
1098 << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n";
1099 s << "</body></html>\n";
1101 //----------------------
1104 bbtkDebugDecTab("kernel",9);
1107 //==========================================================================
1108 std::string Factory::GetObjectName() const
1110 return std::string("Factory");
1112 //==========================================================================
1114 //==========================================================================
1115 std::string Factory::GetObjectInfo() const
1117 std::stringstream i;
1120 //==========================================================================
1122 //==========================================================================
1123 size_t Factory::GetObjectSize() const
1125 size_t s = Superclass::GetObjectSize();
1126 s += Factory::GetObjectInternalSize();
1129 //==========================================================================
1130 //==========================================================================
1131 size_t Factory::GetObjectInternalSize() const
1133 size_t s = sizeof(Factory);
1136 //==========================================================================
1137 //==========================================================================
1138 size_t Factory::GetObjectRecursiveSize() const
1140 size_t s = Superclass::GetObjectRecursiveSize();
1141 s += Factory::GetObjectInternalSize();
1143 PackageMapType::const_iterator i;
1144 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
1146 s += i->second->GetObjectRecursiveSize();
1150 //==========================================================================