2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkFactory.cxx,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.55 $
34 =========================================================================*/
40 *\brief Class bbtk::Factory : can load and unload dynamic libraries containing
41 * black boxes packages and create instances of the black boxes registered
42 * in the packages loaded.
44 #include "bbtkFactory.h"
45 #include "bbtkMessageManager.h"
46 #include "bbtkConnection.h"
47 #include "bbtkConfigurationFile.h"
48 #include "bbtkUtilities.h"
49 #include "bbtkConfigurationFile.h"
51 #include <sys/stat.h> // for struct stat stFileInfo
54 #include <direct.h> // for getcwd
57 #include <cctype> // std::toupper
64 //===================================================================
66 Factory::Pointer Factory::New()
68 bbtkDebugMessage("kernel",9,"Factory::New()"<<std::endl);
69 return MakePointer(new Factory());
71 //===================================================================
73 //===================================================================
78 bbtkDebugMessage("kernel",7,"Factory()"<<std::endl);
80 //===================================================================
82 //===================================================================
86 bbtkDebugMessage("kernel",7,"==> ~Factory()"<<std::endl);
88 bbtkDebugMessage("kernel",7,"<== ~Factory()"<<std::endl);
90 //===================================================================
94 //===================================================================
97 bbtkDebugMessage("kernel",7,"==> Factory::Reset()"<<std::endl);
99 bbtkDebugMessage("kernel",7,"<== Factory::Reset()"<<std::endl);
101 //===================================================================
104 // ===================================================================
105 bool Factory::DoLoadPackage(std::string libname,
110 Package::Pointer p = Package::CreateFromDynamicLibrary(libname,
115 //===================================================================
116 bbtkMessage("output",2,p->GetName()<<" "
119 <<p->GetAuthor() << " Category(s) :"
122 bbtkMessage("output",2,p->GetDescription()<<std::endl);
123 //===================================================================
124 p->AddFactory(GetThisPointer<Factory>());
125 mPackageMap[pkgname] = p;
132 //===================================================================
133 /// \brief Loads a package.
135 /// The name is the system-independant name of the package (the name of the instance of bbtk::Package).
136 /// Tries to open the dynamic library :
137 /// - "libbb<name>.so" for linux systems,
138 /// - "bb<name>.dll" for windows systems.
139 /// If it succeeds, then tries to load the symbols "<name>GetPackage" and "<name>DeletePackage".
140 /// "<name>GetPackage" is called to get the pointer on the bbtk::Package of the library
141 /// ("<name>DeletePackage" is not used, its presence is just checked before loading the package).
143 /// now, filename is only the last name (no longer the full name!)
144 /// it will be searched within *all* the paths given in bbtk_config.xml
148 void Factory::LoadPackage( const std::string& name )
152 // Note : in the following :
153 // name : the user supplied name
154 // - abreviated name e.g. pkg pkg.so libbpkg libbbpkg.so
155 // - relative full name e.g. ./libbbpkg.so ../../libbbpkg.so
156 // - absolute full name e.g. /home/usrname/proj/lib/libbbpkg.so
157 // same for Windows, with c:, d: ...
159 // lastname : string before the last / (if any), or user supplied name
164 bbtkDebugMessageInc("kernel",7,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
165 bbtkMessage("debug",1,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
167 std::vector<std::string> package_paths;
168 std::string libname; // full path library name
169 std::string pkgname; // e.g. libbb<pkgname>.so
173 pkgname = Utilities::ExtractPackageName(name,upath);
175 bbtkMessage("debug",1,"Package name ["<<pkgname<<"]"<<std::endl);
176 bbtkMessage("debug",1,"Package path ["<<upath<<"]"<<std::endl);
178 // no loading package if already loaded
179 PackageMapType::iterator iUnload;
180 iUnload = mPackageMap.find(pkgname);
182 //EED Debuging message
183 // std::cout << "EED Factory::LoadPackage " << std::endl;
184 // PackageMapType::iterator it;
185 // for ( it=mPackageMap.begin() ; it != mPackageMap.end(); it++ )
186 // std::cout << (*it).first << " ";
187 // std::cout << std::endl;
190 if (iUnload != mPackageMap.end())
192 bbtkMessage("output",2,"["<< pkgname <<"] already loaded" << std::endl);
196 // =================================================
197 // The following structure was checked to work
198 // with any type of relative/absolute path.
199 // Please don't modify it without checking
200 // *all* the cases. JP
201 //==================================================
204 bool foundFile = false;
206 // If path provided by user will be the first scanned :
207 // push it into vector of paths
208 if (upath.length()>0) // ------------------------------------- check user supplied location
210 if (name[0] != '.' && name[0] != '/' && name[1]!= ':')
212 bbtkError("Use absolute or relative path name! ["<<name<<"] is an illegal name");
216 // std::string path = Utilities::ExpandLibName(upath, false);
218 std::string path = Utilities::ExpandLibName(name,false); // keep last item, here.
222 Utilities::ExtractPackageName(path,p2);
223 //libname = Utilities::MakeLibnameFromPath(path, pkgname);
224 libname = Utilities::MakeLibnameFromPath(p2, pkgname); // remove last item
225 // Check if library exists
226 if ( !Utilities::FileExists(libname) )
228 // The following is *NOT* a debug time message :
229 // It's a user intended message.
230 // Please don't remove it.
231 bbtkMessage("output",3," [" <<libname
232 <<"] : doesn't exist" <<std::endl);
236 ok = DoLoadPackage( libname, pkgname, path);
241 bbtkError("Path ["<<upath<<"] doesn't exist");
245 else // ----------------------------------------------------- iterate on the paths
248 std::string path = ".";
249 package_paths = ConfigurationFile::GetInstance().Get_package_paths();
250 std::vector<std::string>::iterator i;
251 for (i=package_paths.begin();i!=package_paths.end();++i)
255 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = path "<<path<<std::endl;
256 // we *really* want '.' to be the current working directory
259 char buf[2048]; // for getcwd
260 char * currentDir = getcwd(buf, 2048);
261 std::string cwd(currentDir);
262 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = currentDir "<<currentDir<<std::endl;
265 //std::cout<<"JCP bbtkFactory.cxx void Factory::LoadPackage = path "<<path<<" pkgnam="<<pkgname<<std::endl;
266 libname = Utilities::MakeLibnameFromPath(path, pkgname);
268 bbtkMessage("debug",2,"-> Trying to load [" << libname << "]" <<std::endl);
270 // Check if library exists
271 if ( !Utilities::FileExists(libname) )
273 // The following is *NOT* a debug time message :
274 // It's a user intended message.
275 // Please don't remove it.
276 bbtkMessage("output",3,
277 " [" <<libname <<"] : doesn't exist" <<std::endl);
278 continue; // try next path
282 // Try to Load the library
284 ok = DoLoadPackage( libname, pkgname, path);
287 bbtkMessage("debug",2," OK"<<std::endl);
289 break; // we stop iterating even if error : have to signal it to user
290 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
294 if( !ok ) // nothing was loaded
298 bbtkError("Could not find package ["<<pkgname<< "]");
302 #if defined(__GNUC__)
303 bbtkError("Could not load package ["<< pkgname
305 << " Opening "<<libname<<" failed"
306 << " Reason: "<< dlerror());
307 #elif defined(_WIN32)
308 bbtkError("Could not load package ["<<pkgname
309 <<"] :"<< std::endl << " Error loading " <<libname);
311 // look how to get the error message on win
313 // it is the bordel !! (the bloody fucking bordel, you mean?)
314 // look : http://msdn2.microsoft.com/en-us/library/ms680582.aspx
318 bbtkMessage("output",2,"[" << libname << "] loaded" << std::endl);
325 //===================================================================
326 /// \brief UnLoads a package.
328 /// The package must have been previously loaded by LoadPackage.
329 /// If the entry is found in the map, calls ClosePackage
330 void Factory::UnLoadPackage( const std::string& name )
332 bbtkDebugMessageInc("kernel",7,"Factory::UnLoadPackage(\""
333 <<name<<"\")"<<std::endl);
335 PackageMapType::iterator i;
336 i = mPackageMap.find(name);
337 if (i == mPackageMap.end())
339 bbtkError("cannot unload package \""<<name
340 <<"\" : package not loaded !");
343 bbtkDebugDecTab("kernel",7);
345 //===================================================================
348 //===================================================================
349 void Factory::CloseAllPackages()
351 bbtkDebugMessageInc("kernel",7,"Factory::CloseAllPackages()"<<std::endl);
353 std::vector< Package::WeakPointer > mAlive;
356 while (mPackageMap.begin() != mPackageMap.end())
358 PackageMapType::iterator i = mPackageMap.begin();
359 Package::WeakPointer p = i->second;
361 if (p.lock()) mAlive.push_back(p);
363 std::vector< Package::WeakPointer >::iterator i;
364 for (i=mAlive.begin();i!=mAlive.end();++i)
366 // If not dead : reinsert
369 bbtkDebugMessage("kernel",7,"Package "<<i->lock()->GetName()
370 <<" still alive"<<std::endl);
371 // InsertPackage(i->lock());
375 while (mPackageMap.size()>0);
377 bbtkDebugDecTab("kernel",7);
379 //===================================================================
381 //===================================================================
382 /// \brief Close the package referenced by the iterator
384 /// First removes the factory from the set of factories which use the package
385 /// If the set is empty then :
386 /// If it is a dynamically loaded package :
387 /// - Loads and calls the function "<name>DeletePackage" of the dynamic library (responsible for package desallocation)
388 /// - Closes the dynamic library
390 /// - deletes the package normally
392 /// Finally erases the package entry in the packages map
393 void Factory::ClosePackage(PackageMapType::iterator& i)
395 bbtkDebugMessageInc("kernel",7,"Factory::ClosePackage(\""
396 <<i->second->GetName()
400 // Removes this from the set of factories which use the package
401 i->second->RemoveFactory(GetThisPointer<Factory>());
402 Package::WeakPointer p = i->second;
403 // remove the entry in the map
404 mPackageMap.erase(i);
405 // Release the package if not already destroyed
410 bbtkDebugDecTab("kernel",7);
412 //===================================================================
416 //===================================================================
417 void Factory::PrintHelpListPackages(bool details, bool adaptors) const
419 bbtkDebugMessageInc("kernel",9,"Factory::PrintPackages"<<std::endl);
421 PackageMapType::const_iterator i;
422 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
424 bbtkMessage("help",1, i->first << std::endl);
426 i->second->PrintHelpListDescriptors(false,adaptors);
430 bbtkDebugDecTab("kernel",9);
432 //===================================================================
434 //===================================================================
435 /// Displays help on a package
436 void Factory::PrintHelpPackage(const std::string& name, bool adaptors) const
438 bbtkDebugMessageInc("kernel",9,"Factory::PrintHelpPackage(\""
442 PackageMapType::const_iterator i = mPackageMap.find(name);
443 if ( i != mPackageMap.end() )
445 bbtkMessage("help",1, "Package "<<i->first<<" ");
447 if (i->second->GetVersion().length()>0)
448 bbtkMessageCont("help",1,"v" <<i->second->GetVersion());
450 if (i->second->GetAuthor().length()>0)
451 bbtkMessageCont("help",1,"- "<<i->second->GetAuthor());
453 if (i->second->GetCategory().length()>0)
454 bbtkMessageCont("help",1,"- "<<i->second->GetCategory());
456 bbtkMessageCont("help",1,std::endl);
457 bbtkIncTab("help",1);
458 bbtkMessage("help",1,i->second->GetDescription()<<std::endl);
459 if (i->second->GetNumberOfDescriptors()>0)
461 bbtkMessage("help",1, "Black boxes : "<<std::endl);
462 i->second->PrintHelpListDescriptors(true,adaptors);
466 bbtkMessage("help",1, "No black boxes"<<std::endl);
468 bbtkDecTab("help",1);
472 bbtkDebugDecTab("kernel",9);
473 bbtkError("package \""<<name<<"\" unknown");
476 bbtkDebugDecTab("kernel",9);
478 //===================================================================
480 //===================================================================
481 /// Prints help on the black box of type <name>
482 /// Returns the package to which it belongs
483 void Factory::PrintHelpDescriptor(const std::string& name,
484 std::string& package,
487 bbtkDebugMessageInc("kernel",9,"Factory::PrintHelpDescriptor(\""
492 PackageMapType::const_iterator i;
493 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
495 if (i->second->ContainsDescriptor(name))
497 i->second->PrintHelpDescriptor(name,full);
498 package = i->second->GetName();
503 bbtkDebugDecTab("kernel",9);
506 bbtkError("No package of the factory contains any black box <"
510 //===================================================================
513 //===================================================================
514 /// Inserts a package in the factory
515 void Factory::InsertPackage( Package::Pointer p )
517 bbtkDebugMessageInc("kernel",9,"Factory::InsertPackage(\""<<
518 p->GetName()<<"\")"<<std::endl);
520 p->AddFactory(GetThisPointer<Factory>());
521 mPackageMap[p->GetName()] = p;
522 bbtkDebugDecTab("kernel",9);
524 //===================================================================
526 //===================================================================
527 /// Removes a package from the factory (and deletes it)
528 void Factory::RemovePackage( Package::Pointer p )
530 bbtkDebugMessageInc("kernel",9,"Factory::RemovePackage(\""<<
531 p->GetName()<<"\")"<<std::endl);
533 PackageMapType::iterator i;
534 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
536 if (i->second == p) break;
539 if (i!=mPackageMap.end())
545 bbtkError("Factory::RemovePackage(\""<<
546 p->GetName()<<"\") : package absent from factory");
549 bbtkDebugDecTab("kernel",9);
551 //===================================================================
555 std::string Factory::GetPackageNameOfaBlackBox(std::string boxType)
557 std::string result="<void bbtk package name>";
558 PackageMapType::const_iterator i;
559 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
561 if ( i->second->ifBoxExist( boxType ) == true)
570 //===================================================================
571 /// Creates an instance of a black box of type <type> with name <name>
572 BlackBox::Pointer Factory::NewBlackBox(const std::string& type,
573 const std::string& name) const
575 bbtkDebugMessageInc("kernel",7,"Factory::NewBlackBox(\""
576 <<type<<"\",\""<<name<<"\")"<<std::endl);
579 PackageMapType::const_iterator i;
580 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
582 b = i->second->NewBlackBox(type,name);
587 bbtkError("black box type \""<<type<<"\" unknown");
590 bbtkDebugDecTab("kernel",7);
593 //===================================================================
595 //===================================================================
596 /// Creates an instance of a black box of type <type> with name <name>
597 BlackBox::Pointer Factory::NewAdaptor(const DataInfo& typein,
598 const DataInfo& typeout,
599 const std::string& name) const
601 bbtkDebugMessageInc("kernel",8,"Factory::NewAdaptor("
604 <<name<<"\")"<<bbtkendl);
608 PackageMapType::const_iterator i;
609 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
611 b = i->second->NewAdaptor(typein,typeout,name);
616 bbtkError("no "<<typein<<" to "<<typeout
617 <<" adaptor available");
620 bbtkDebugDecTab("kernel",7);
623 //===================================================================
626 //===================================================================
627 /// Creates an instance of a black box of type <type> with name <name>
628 BlackBox::Pointer Factory::NewWidgetAdaptor(const DataInfo& typein,
629 const DataInfo& typeout,
630 const std::string& name) const
632 bbtkDebugMessageInc("kernel",8,"Factory::NewWidgetAdaptor(<"
635 <<name<<"\")"<<bbtkendl);
639 PackageMapType::const_iterator i;
640 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
642 b = i->second->NewWidgetAdaptor(typein,
649 bbtkError("no "<<typein<<" to "<<typeout
650 <<"> widget adaptor available");
653 bbtkDebugDecTab("kernel",7);
656 //===================================================================
658 //===================================================================
659 /// Creates an instance of a black box of type <type> with name <name>
660 bool Factory::FindAdaptor(const DataInfo& typein,
661 const DataInfo& typeout,
662 std::string& adaptor) const
664 bbtkDebugMessageInc("kernel",8,"Factory::FindAdaptor(<"
666 <<typeout<<">)"<<bbtkendl);
669 PackageMapType::const_iterator i;
670 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
672 b = i->second->FindAdaptor(typein,
680 bbtkError("no "<<typein<<" to "<<typeout
681 <<"> widget adaptor available");
685 bbtkDebugDecTab("kernel",7);
688 //===================================================================
690 //===================================================================
691 /// Creates an instance of a black box of type <type> with name <name>
692 bool Factory::FindWidgetAdaptor(const DataInfo& typein,
693 const DataInfo& typeout,
694 std::string& adaptor) const
696 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
698 <<typeout<<">)"<<bbtkendl);
701 PackageMapType::const_iterator i;
702 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
704 b = i->second->FindWidgetAdaptor(typein,
709 bbtkDebugDecTab("kernel",7);
712 //===================================================================
714 //===================================================================
715 /// Creates an instance of a black box of type <type> with name <name>
716 bool Factory::FindWidgetAdaptor2(const DataInfo& typein,
717 const DataInfo& typeout,
719 std::string& adaptor) const
721 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
723 <<typeout<<">)"<<bbtkendl);
726 adaptor = widget = "";
727 PackageMapType::const_iterator i;
728 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
730 b = i->second->FindWidgetAdaptor(typein,
737 // Look for a widget adaptor with good nature out
738 bbtkMessage("kernel",5,
739 "*** Looking for a two pieces widget adaptor for : "
740 << typein << "->"<<typeout<<std::endl);
741 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
743 Package::AdaptorMapType::const_iterator j;
744 for (j=i->second->GetAdaptorMap().begin();
745 j!=i->second->GetAdaptorMap().end();
748 if ( ( j->first.mKind ==
749 BlackBoxDescriptor::DEFAULT_GUI) &&
750 //(j->first.mTypeIn == typein) &&
751 (j->first.mTypeOut.GetNature() == typeout.GetNature() )
754 widget = j->second.lock()->GetTypeName();
755 bbtkMessage("kernel",5,
756 "===> Found first part : "<<widget
757 << " "<<j->first.mTypeIn<<"->"
758 <<j->first.mTypeOut<<std::endl);
759 DataInfo ti( j->first.mTypeOut.GetType(), "");
760 DataInfo to( typeout.GetType(), "");
761 b = FindAdaptor( ti, to, adaptor );
764 bbtkMessage("kernel",5,
765 "===> Found second part : "<<adaptor
771 bbtkMessage("kernel",5,
772 "===> No second part found"<<std::endl);
779 bbtkDebugDecTab("kernel",7);
782 //===================================================================
784 //===================================================================
785 /// Creates an instance of a connection
786 Connection::Pointer Factory::NewConnection(BlackBox::Pointer from,
787 const std::string& output,
788 BlackBox::Pointer to,
789 const std::string& input) const
791 bbtkDebugMessage("kernel",7,"Factory::NewConnection(\""
792 <<from->bbGetName()<<"\",\""<<output<<"\",\""
793 <<to->bbGetName()<<"\",\""<<input
796 return Connection::New(from,output,to,input,
797 GetThisPointer<Factory>());
799 //===================================================================
803 //===================================================================
804 Package::Pointer Factory::GetPackage(const std::string& name) const
806 bbtkDebugMessageInc("kernel",9,"Factory::GetPackage(\""<<name<<"\")"
809 PackageMapType::const_iterator i = mPackageMap.find(name);
810 if ( i != mPackageMap.end() )
812 bbtkDebugDecTab("kernel",9);
817 bbtkDebugDecTab("kernel",9);
818 bbtkError("package \""<<name<<"\" unknown");
821 bbtkDebugDecTab("kernel",9);
823 //===================================================================
826 //===================================================================
827 void Factory::Check() const
829 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
831 PackageMapType::const_iterator i;
832 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
836 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
837 <<" ... OK"<<std::endl);
839 //===================================================================
841 //===================================================================
842 void Factory::WriteDotFilePackagesList(FILE *ff)
845 bbtkDebugMessageInc("kernel",9,"Factory::WriteDotFilePackagesList()"
849 fprintf( ff , "subgraph cluster_FACTORY {\n");
850 fprintf( ff , " label = \"PACKAGES\"%s\n", ";");
851 fprintf( ff , " style=filled%s\n",";");
852 fprintf( ff , " color=lightgrey%s\n",";");
853 fprintf( ff , " rankdir=TB%s\n",";");
856 PackageMapType::const_iterator i;
857 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
859 url=GetPackage(i->first)->GetDocURL();
860 fprintf(ff," %s [shape=ellipse, URL=\"%s\"]%s\n",i->first.c_str(),url.c_str(),";" );
862 fprintf( ff , "}\n\n");
863 bbtkDebugDecTab("kernel",9);
865 //===================================================================
868 void Factory::ShowGraphTypes(const std::string& name) const
871 PackageMapType::const_iterator i;
872 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
874 if (i->second->ContainsDescriptor(name))
876 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
878 // Don't pollute the file store with "temp_dir" directories ...
879 std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
880 std::string directory = "\"" + default_doc_dir + separator + "temp_dir" +separator + "\"";
881 std::string filename2 = default_doc_dir + separator + "temp_dir" + separator + "tmp.html";
884 std::string command("start \"Titre\" /D ");
886 std::string command("gnome-open ");
888 command=command + directory +" tmp.html";
890 ff=fopen(filename2.c_str(),"w");
892 fprintf(ff,"<html><head><title>TMP</title> <script type=\"text/javascript\"> <!--\n");
893 fprintf(ff," window.location=\"%s#%s\";\n" , i->second->GetDocURL().c_str(),name.c_str() );
894 fprintf(ff,"//--></script></head><body></body></html>\n");
897 //fprintf(ff, "<a href=\"%s#%s\">Link</a>\n", i->second->GetDocURL().c_str(),name.c_str() );
899 system( command.c_str() );
904 bbtkDebugDecTab("kernel",9);
907 bbtkError("No package of the factory contains any black box <"
915 void Factory::CreateHtmlIndex(IndexEntryType type,
916 const std::string& filename)
918 bbtkDebugMessageInc("kernel",9,"Factory::CreateHtmlIndex(\""
919 <<filename<<"\")"<<bbtkendl);
923 typedef std::map<std::string,
924 std::vector<BlackBoxDescriptor::Pointer> > IndexType;
926 // Builds the index map
927 PackageMapType::const_iterator i;
928 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
930 Package::Pointer pack = i->second;
931 if (pack->GetName()=="user") continue;
932 Package::DescriptorMapType::const_iterator j;
933 for (j = pack->GetDescriptorMap().begin();
934 j!= pack->GetDescriptorMap().end();
939 if ( type==Adaptors )
941 if (j->second->GetKind() == BlackBoxDescriptor::STANDARD )
945 if (j->second->GetKind() != BlackBoxDescriptor::STANDARD )
948 std::vector<std::string> keys;
952 k += pack->GetName();
954 title = "Boxes by package";
956 else if ((type==Initials) || (type==Adaptors))
958 std::string init(" ");
959 init[0] = std::toupper(j->second->GetTypeName()[0]);
960 keys.push_back(init);
961 title = "Alphabetical list";
963 else if (type==Categories)
965 // Split the category string
966 std::string delimiters = ";,";
967 Utilities::SplitString(j->second->GetCategory(),
970 keys.push_back(" NONE");
971 title = "Boxes by category";
974 std::vector<std::string>::const_iterator k;
975 for (k=keys.begin(); k!=keys.end(); ++k )
977 IndexType::iterator p;
979 if (p != index.end())
981 p->second.push_back(j->second);
985 std::vector<BlackBoxDescriptor::Pointer> v;
986 v.push_back(j->second);
993 //---------------------
996 s.open(filename.c_str());
999 bbtkError("Factory::CreateHtmlIndex : could not open file '"
1003 //----------------------
1005 s << "<html lang=\"en\">\n";
1007 s << "<title>"<<title<<"</title>\n";
1008 s << "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n";
1009 s << "<meta name=\"description\" content=\""<<title<<"\">\n";
1010 s << "<meta name=\"generator\" content=\"\">\n";
1011 s << "<link title=\"Top\" rel=\"top\" href=\"#Top\">\n";
1012 //<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
1013 s << "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><style type=\"text/css\"><!--\n";
1014 s << "pre.display { font-family:inherit }\n";
1015 s << "pre.format { font-family:inherit }\n";
1016 s << "pre.smalldisplay { font-family:inherit; font-size:smaller }\n";
1017 s << "pre.smallformat { font-family:inherit; font-size:smaller }\n";
1018 s << "pre.smallexample { font-size:smaller }\n";
1019 s << "pre.smalllisp { font-size:smaller }\n";
1020 s << "span.sc { font-variant:small-caps }\n";
1021 s << "span.roman { font-family:serif; font-weight:normal; } \n";
1022 s << "span.sansserif { font-family:sans-serif; font-weight:normal; }\n";
1023 s << "--></style>\n";
1025 //----------------------
1027 //----------------------
1030 s << "<a name=\"Top\"></a>\n";
1031 s << "<h1 class=\"settitle\">"<<title<<"</h1>\n";
1033 IndexType::iterator ii;
1034 for (ii=index.begin();ii!=index.end();++ii)
1036 s << "<a href=\"#"<<ii->first<<"\">"<<ii->first<<"</a> ";
1039 for (ii=index.begin();ii!=index.end();++ii)
1042 s << "<p><a href=\"#Top\">Top</a>";
1045 s << "<a name=\""<<ii->first<<"\"></a>\n";
1046 s << "<p><a href=\""<<ii->first<<"/index.html\">"
1047 << ii->first<<"</a>\n";
1049 s << " - \n";
1051 s << "<a name=\"doxygen\"></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";
1058 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1059 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1063 s << "<a name=\""<<ii->first<<"\"></a>\n";
1064 s << "<p><b>"<<ii->first<<"</b>\n";
1068 s << "<p><TABLE cellspacing=0 cellpadding=3>\n";
1070 std::vector<BlackBoxDescriptor::Pointer>::iterator di;
1071 for (di=ii->second.begin();di!=ii->second.end();++di)
1073 std::string pack = (*di)->GetPackage()->GetName();
1074 std::string name = (*di)->GetTypeName();
1075 Utilities::html_format(name);
1076 std::string descr = (*di)->GetDescription();
1077 Utilities::html_format(descr);
1079 s << "<TD style='vertical-align: top;'>";
1080 s << " <a href=\""<<pack
1081 <<"/index.html#"<<name<<"\">"
1082 <<pack<<"::"<<name<<"</a>";
1084 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1091 //----------------------
1096 ptm = gmtime ( &rawtime );
1099 s << "Automatically generated by <b>bbtk</b> on "
1100 << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900
1101 << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n";
1102 s << "</body></html>\n";
1104 //----------------------
1107 bbtkDebugDecTab("kernel",9);
1110 //==========================================================================
1111 std::string Factory::GetObjectName() const
1113 return std::string("Factory");
1115 //==========================================================================
1117 //==========================================================================
1118 std::string Factory::GetObjectInfo() const
1120 std::stringstream i;
1123 //==========================================================================
1125 //==========================================================================
1126 size_t Factory::GetObjectSize() const
1128 size_t s = Superclass::GetObjectSize();
1129 s += Factory::GetObjectInternalSize();
1132 //==========================================================================
1133 //==========================================================================
1134 size_t Factory::GetObjectInternalSize() const
1136 size_t s = sizeof(Factory);
1139 //==========================================================================
1140 //==========================================================================
1141 size_t Factory::GetObjectRecursiveSize() const
1143 size_t s = Superclass::GetObjectRecursiveSize();
1144 s += Factory::GetObjectInternalSize();
1146 PackageMapType::const_iterator i;
1147 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
1149 s += i->second->GetObjectRecursiveSize();
1153 //==========================================================================