1 /*=========================================================================
3 Module: $RCSfile: bbtkFactory.cxx,v $
5 Date: $Date: 2012/05/30 17:17:00 $
6 Version: $Revision: 1.52 $
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 printf("EED Factory::DoLoadPackage > %s %s %s \n",libname.c_str(), pkgname.c_str(),path.c_str());
119 mPackageMap[pkgname] = p;
126 //===================================================================
127 /// \brief Loads a package.
129 /// The name is the system-independant name of the package (the name of the instance of bbtk::Package).
130 /// Tries to open the dynamic library :
131 /// - "libbb<name>.so" for linux systems,
132 /// - "bb<name>.dll" for windows systems.
133 /// If it succeeds, then tries to load the symbols "<name>GetPackage" and "<name>DeletePackage".
134 /// "<name>GetPackage" is called to get the pointer on the bbtk::Package of the library
135 /// ("<name>DeletePackage" is not used, its presence is just checked before loading the package).
137 /// now, filename is only the last name (no longer the full name!)
138 /// it will be searched within *all* the paths given in bbtk_config.xml
142 void Factory::LoadPackage( const std::string& name )
146 // Note : in the following :
147 // name : the user supplied name
148 // - abreviated name e.g. pkg pkg.so libbpkg libbbpkg.so
149 // - relative full name e.g. ./libbbpkg.so ../../libbbpkg.so
150 // - absolute full name e.g. /home/usrname/proj/lib/libbbpkg.so
151 // same for Windows, with c:, d: ...
153 // lastname : string before the last / (if any), or user supplied name
158 bbtkDebugMessageInc("kernel",7,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
159 bbtkMessage("debug",1,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
161 std::vector<std::string> package_paths;
162 std::string libname; // full path library name
163 std::string pkgname; // e.g. libbb<pkgname>.so
168 pkgname = Utilities::ExtractPackageName(name,upath);
170 printf("EED Factory::LoadPackage A. %s\n", name.c_str());
171 printf("EED Factory::LoadPackage A. %s\n", upath.c_str());
172 printf("EED Factory::LoadPackage A. %s\n", pkgname.c_str());
174 bbtkMessage("debug",1,"Package name ["<<pkgname<<"]"<<std::endl);
175 bbtkMessage("debug",1,"Package path ["<<upath<<"]"<<std::endl);
177 // no loading package if already loaded
178 PackageMapType::iterator iUnload;
179 iUnload = mPackageMap.find(pkgname);
181 PackageMapType::iterator it;
182 std::cout << "EED Factory::LoadPackage PackageMap ";
183 for ( it=mPackageMap.begin() ; it != mPackageMap.end(); it++ )
184 std::cout << (*it).first << " ";
185 std::cout << std::endl;
187 if (iUnload != mPackageMap.end())
189 bbtkMessage("output",2,"["<< pkgname <<"] already loaded" << std::endl);
193 // =================================================
194 // The following structure was checked to work
195 // with any type of relative/absolute path.
196 // Please don't modify it without checking
197 // *all* the cases. JP
198 //==================================================
200 printf("\nEED Factory::LoadPackage B. %s\n\n", name.c_str());
201 //std::cout << "upath [" << name << "]" << std::endl;
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>());
522 printf("EED Factory::InsertPackage %s\n", p->GetName().c_str() );
524 mPackageMap[p->GetName()] = p;
526 bbtkDebugDecTab("kernel",9);
528 //===================================================================
530 //===================================================================
531 /// Removes a package from the factory (and deletes it)
532 void Factory::RemovePackage( Package::Pointer p )
534 bbtkDebugMessageInc("kernel",9,"Factory::RemovePackage(\""<<
535 p->GetName()<<"\")"<<std::endl);
537 PackageMapType::iterator i;
538 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
540 if (i->second == p) break;
543 if (i!=mPackageMap.end())
549 bbtkError("Factory::RemovePackage(\""<<
550 p->GetName()<<"\") : package absent from factory");
553 bbtkDebugDecTab("kernel",9);
555 //===================================================================
559 std::string Factory::GetPackageNameOfaBlackBox(std::string boxType)
561 std::string result="<void bbtk package name>";
562 PackageMapType::const_iterator i;
563 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
565 if ( i->second->ifBoxExist( boxType ) == true)
574 //===================================================================
575 /// Creates an instance of a black box of type <type> with name <name>
576 BlackBox::Pointer Factory::NewBlackBox(const std::string& type,
577 const std::string& name) const
579 bbtkDebugMessageInc("kernel",7,"Factory::NewBlackBox(\""
580 <<type<<"\",\""<<name<<"\")"<<std::endl);
583 PackageMapType::const_iterator i;
584 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
586 b = i->second->NewBlackBox(type,name);
591 bbtkError("black box type \""<<type<<"\" unknown");
594 bbtkDebugDecTab("kernel",7);
597 //===================================================================
599 //===================================================================
600 /// Creates an instance of a black box of type <type> with name <name>
601 BlackBox::Pointer Factory::NewAdaptor(const DataInfo& typein,
602 const DataInfo& typeout,
603 const std::string& name) const
605 bbtkDebugMessageInc("kernel",8,"Factory::NewAdaptor("
608 <<name<<"\")"<<bbtkendl);
612 PackageMapType::const_iterator i;
613 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
615 b = i->second->NewAdaptor(typein,typeout,name);
620 bbtkError("no "<<typein<<" to "<<typeout
621 <<" adaptor available");
624 bbtkDebugDecTab("kernel",7);
627 //===================================================================
630 //===================================================================
631 /// Creates an instance of a black box of type <type> with name <name>
632 BlackBox::Pointer Factory::NewWidgetAdaptor(const DataInfo& typein,
633 const DataInfo& typeout,
634 const std::string& name) const
636 bbtkDebugMessageInc("kernel",8,"Factory::NewWidgetAdaptor(<"
639 <<name<<"\")"<<bbtkendl);
643 PackageMapType::const_iterator i;
644 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
646 b = i->second->NewWidgetAdaptor(typein,
653 bbtkError("no "<<typein<<" to "<<typeout
654 <<"> widget adaptor available");
657 bbtkDebugDecTab("kernel",7);
660 //===================================================================
662 //===================================================================
663 /// Creates an instance of a black box of type <type> with name <name>
664 bool Factory::FindAdaptor(const DataInfo& typein,
665 const DataInfo& typeout,
666 std::string& adaptor) const
668 bbtkDebugMessageInc("kernel",8,"Factory::FindAdaptor(<"
670 <<typeout<<">)"<<bbtkendl);
673 PackageMapType::const_iterator i;
674 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
676 b = i->second->FindAdaptor(typein,
684 bbtkError("no "<<typein<<" to "<<typeout
685 <<"> widget adaptor available");
689 bbtkDebugDecTab("kernel",7);
692 //===================================================================
694 //===================================================================
695 /// Creates an instance of a black box of type <type> with name <name>
696 bool Factory::FindWidgetAdaptor(const DataInfo& typein,
697 const DataInfo& typeout,
698 std::string& adaptor) const
700 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
702 <<typeout<<">)"<<bbtkendl);
705 PackageMapType::const_iterator i;
706 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
708 b = i->second->FindWidgetAdaptor(typein,
713 bbtkDebugDecTab("kernel",7);
716 //===================================================================
718 //===================================================================
719 /// Creates an instance of a black box of type <type> with name <name>
720 bool Factory::FindWidgetAdaptor2(const DataInfo& typein,
721 const DataInfo& typeout,
723 std::string& adaptor) const
725 bbtkDebugMessageInc("kernel",8,"Factory::FindWidgetAdaptor(<"
727 <<typeout<<">)"<<bbtkendl);
730 adaptor = widget = "";
731 PackageMapType::const_iterator i;
732 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
734 b = i->second->FindWidgetAdaptor(typein,
741 // Look for a widget adaptor with good nature out
742 bbtkMessage("kernel",5,
743 "*** Looking for a two pieces widget adaptor for : "
744 << typein << "->"<<typeout<<std::endl);
745 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
747 Package::AdaptorMapType::const_iterator j;
748 for (j=i->second->GetAdaptorMap().begin();
749 j!=i->second->GetAdaptorMap().end();
752 if ( ( j->first.mKind ==
753 BlackBoxDescriptor::DEFAULT_GUI) &&
754 //(j->first.mTypeIn == typein) &&
755 (j->first.mTypeOut.GetNature() == typeout.GetNature() )
758 widget = j->second.lock()->GetTypeName();
759 bbtkMessage("kernel",5,
760 "===> Found first part : "<<widget
761 << " "<<j->first.mTypeIn<<"->"
762 <<j->first.mTypeOut<<std::endl);
763 DataInfo ti( j->first.mTypeOut.GetType(), "");
764 DataInfo to( typeout.GetType(), "");
765 b = FindAdaptor( ti, to, adaptor );
768 bbtkMessage("kernel",5,
769 "===> Found second part : "<<adaptor
775 bbtkMessage("kernel",5,
776 "===> No second part found"<<std::endl);
783 bbtkDebugDecTab("kernel",7);
786 //===================================================================
788 //===================================================================
789 /// Creates an instance of a connection
790 Connection::Pointer Factory::NewConnection(BlackBox::Pointer from,
791 const std::string& output,
792 BlackBox::Pointer to,
793 const std::string& input) const
795 bbtkDebugMessage("kernel",7,"Factory::NewConnection(\""
796 <<from->bbGetName()<<"\",\""<<output<<"\",\""
797 <<to->bbGetName()<<"\",\""<<input
800 return Connection::New(from,output,to,input,
801 GetThisPointer<Factory>());
803 //===================================================================
807 //===================================================================
808 Package::Pointer Factory::GetPackage(const std::string& name) const
810 bbtkDebugMessageInc("kernel",9,"Factory::GetPackage(\""<<name<<"\")"
813 PackageMapType::const_iterator i = mPackageMap.find(name);
814 if ( i != mPackageMap.end() )
816 bbtkDebugDecTab("kernel",9);
821 bbtkDebugDecTab("kernel",9);
822 bbtkError("package \""<<name<<"\" unknown");
825 bbtkDebugDecTab("kernel",9);
827 //===================================================================
830 //===================================================================
831 void Factory::Check() const
833 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
835 PackageMapType::const_iterator i;
836 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
840 bbtkMessage("debug",1,"****** Checking Factory "<<(void*)this
841 <<" ... OK"<<std::endl);
843 //===================================================================
845 //===================================================================
846 void Factory::WriteDotFilePackagesList(FILE *ff)
849 bbtkDebugMessageInc("kernel",9,"Factory::WriteDotFilePackagesList()"
853 fprintf( ff , "subgraph cluster_FACTORY {\n");
854 fprintf( ff , " label = \"PACKAGES\"%s\n", ";");
855 fprintf( ff , " style=filled%s\n",";");
856 fprintf( ff , " color=lightgrey%s\n",";");
857 fprintf( ff , " rankdir=TB%s\n",";");
860 PackageMapType::const_iterator i;
861 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
863 url=GetPackage(i->first)->GetDocURL();
864 fprintf(ff," %s [shape=ellipse, URL=\"%s\"]%s\n",i->first.c_str(),url.c_str(),";" );
866 fprintf( ff , "}\n\n");
867 bbtkDebugDecTab("kernel",9);
869 //===================================================================
872 void Factory::ShowGraphTypes(const std::string& name) const
875 PackageMapType::const_iterator i;
876 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
878 if (i->second->ContainsDescriptor(name))
880 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
882 // Don't pollute the file store with "temp_dir" directories ...
883 std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
884 std::string directory = "\"" + default_doc_dir + separator + "temp_dir" +separator + "\"";
885 std::string filename2 = default_doc_dir + separator + "temp_dir" + separator + "tmp.html";
888 std::string command("start \"Titre\" /D ");
890 std::string command("gnome-open ");
892 command=command + directory +" tmp.html";
894 ff=fopen(filename2.c_str(),"w");
896 fprintf(ff,"<html><head><title>TMP</title> <script type=\"text/javascript\"> <!--\n");
897 fprintf(ff," window.location=\"%s#%s\";\n" , i->second->GetDocURL().c_str(),name.c_str() );
898 fprintf(ff,"//--></script></head><body></body></html>\n");
901 //fprintf(ff, "<a href=\"%s#%s\">Link</a>\n", i->second->GetDocURL().c_str(),name.c_str() );
903 system( command.c_str() );
908 bbtkDebugDecTab("kernel",9);
911 bbtkError("No package of the factory contains any black box <"
919 void Factory::CreateHtmlIndex(IndexEntryType type,
920 const std::string& filename)
922 bbtkDebugMessageInc("kernel",9,"Factory::CreateHtmlIndex(\""
923 <<filename<<"\")"<<bbtkendl);
927 typedef std::map<std::string,
928 std::vector<BlackBoxDescriptor::Pointer> > IndexType;
930 // Builds the index map
931 PackageMapType::const_iterator i;
932 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
934 Package::Pointer pack = i->second;
935 if (pack->GetName()=="user") continue;
936 Package::DescriptorMapType::const_iterator j;
937 for (j = pack->GetDescriptorMap().begin();
938 j!= pack->GetDescriptorMap().end();
943 if ( type==Adaptors )
945 if (j->second->GetKind() == BlackBoxDescriptor::STANDARD )
949 if (j->second->GetKind() != BlackBoxDescriptor::STANDARD )
952 std::vector<std::string> keys;
956 k += pack->GetName();
958 title = "Boxes by package";
960 else if ((type==Initials) || (type==Adaptors))
962 std::string init(" ");
963 init[0] = std::toupper(j->second->GetTypeName()[0]);
964 keys.push_back(init);
965 title = "Alphabetical list";
967 else if (type==Categories)
969 // Split the category string
970 std::string delimiters = ";,";
971 Utilities::SplitString(j->second->GetCategory(),
974 keys.push_back(" NONE");
975 title = "Boxes by category";
978 std::vector<std::string>::const_iterator k;
979 for (k=keys.begin(); k!=keys.end(); ++k )
981 IndexType::iterator p;
983 if (p != index.end())
985 p->second.push_back(j->second);
989 std::vector<BlackBoxDescriptor::Pointer> v;
990 v.push_back(j->second);
997 //---------------------
1000 s.open(filename.c_str());
1003 bbtkError("Factory::CreateHtmlIndex : could not open file '"
1007 //----------------------
1009 s << "<html lang=\"en\">\n";
1011 s << "<title>"<<title<<"</title>\n";
1012 s << "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n";
1013 s << "<meta name=\"description\" content=\""<<title<<"\">\n";
1014 s << "<meta name=\"generator\" content=\"\">\n";
1015 s << "<link title=\"Top\" rel=\"top\" href=\"#Top\">\n";
1016 //<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
1017 s << "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><style type=\"text/css\"><!--\n";
1018 s << "pre.display { font-family:inherit }\n";
1019 s << "pre.format { font-family:inherit }\n";
1020 s << "pre.smalldisplay { font-family:inherit; font-size:smaller }\n";
1021 s << "pre.smallformat { font-family:inherit; font-size:smaller }\n";
1022 s << "pre.smallexample { font-size:smaller }\n";
1023 s << "pre.smalllisp { font-size:smaller }\n";
1024 s << "span.sc { font-variant:small-caps }\n";
1025 s << "span.roman { font-family:serif; font-weight:normal; } \n";
1026 s << "span.sansserif { font-family:sans-serif; font-weight:normal; }\n";
1027 s << "--></style>\n";
1029 //----------------------
1031 //----------------------
1034 s << "<a name=\"Top\"></a>\n";
1035 s << "<h1 class=\"settitle\">"<<title<<"</h1>\n";
1037 IndexType::iterator ii;
1038 for (ii=index.begin();ii!=index.end();++ii)
1040 s << "<a href=\"#"<<ii->first<<"\">"<<ii->first<<"</a> ";
1043 for (ii=index.begin();ii!=index.end();++ii)
1046 s << "<p><a href=\"#Top\">Top</a>";
1049 s << "<a name=\""<<ii->first<<"\"></a>\n";
1050 s << "<p><a href=\""<<ii->first<<"/index.html\">"
1051 << ii->first<<"</a>\n";
1053 s << " - \n";
1055 s << "<a name=\"doxygen\"></a>\n";
1059 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1060 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1062 std::string bin_path = bbtk::ConfigurationFile::GetInstance().Get_bin_path();
1063 s << "<a href=" << bin_path <<"/../share/bbtk/doc/doxygen/" << ii->first << "/main.html>(Doxygen documentation of the source)</a>\n";
1067 s << "<a name=\""<<ii->first<<"\"></a>\n";
1068 s << "<p><b>"<<ii->first<<"</b>\n";
1072 s << "<p><TABLE cellspacing=0 cellpadding=3>\n";
1074 std::vector<BlackBoxDescriptor::Pointer>::iterator di;
1075 for (di=ii->second.begin();di!=ii->second.end();++di)
1077 std::string pack = (*di)->GetPackage()->GetName();
1078 std::string name = (*di)->GetTypeName();
1079 Utilities::html_format(name);
1080 std::string descr = (*di)->GetDescription();
1081 Utilities::html_format(descr);
1083 s << "<TD style='vertical-align: top;'>";
1084 s << " <a href=\""<<pack
1085 <<"/index.html#"<<name<<"\">"
1086 <<pack<<"::"<<name<<"</a>";
1088 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1095 //----------------------
1100 ptm = gmtime ( &rawtime );
1103 s << "Automatically generated by <b>bbtk</b> on "
1104 << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900
1105 << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n";
1106 s << "</body></html>\n";
1108 //----------------------
1111 bbtkDebugDecTab("kernel",9);
1114 //==========================================================================
1115 std::string Factory::GetObjectName() const
1117 return std::string("Factory");
1119 //==========================================================================
1121 //==========================================================================
1122 std::string Factory::GetObjectInfo() const
1124 std::stringstream i;
1127 //==========================================================================
1129 //==========================================================================
1130 size_t Factory::GetObjectSize() const
1132 size_t s = Superclass::GetObjectSize();
1133 s += Factory::GetObjectInternalSize();
1136 //==========================================================================
1137 //==========================================================================
1138 size_t Factory::GetObjectInternalSize() const
1140 size_t s = sizeof(Factory);
1143 //==========================================================================
1144 //==========================================================================
1145 size_t Factory::GetObjectRecursiveSize() const
1147 size_t s = Superclass::GetObjectRecursiveSize();
1148 s += Factory::GetObjectInternalSize();
1150 PackageMapType::const_iterator i;
1151 for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
1153 s += i->second->GetObjectRecursiveSize();
1157 //==========================================================================