00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00036 #include "bbtkComplexBlackBoxDescriptor.h"
00037 #include "bbtkComplexBlackBox.h"
00038
00039 #include "bbtkMessageManager.h"
00040 #include "bbtkUtilities.h"
00041
00042 namespace bbtk
00043 {
00044
00046 ComplexBlackBoxDescriptor::Pointer
00047 ComplexBlackBoxDescriptor::New(const std::string& name)
00048 {
00049 bbtkDebugMessage("object",1,"##> ComplexBlackBoxDescriptor::New(\""<<name<<"\")"<<std::endl);
00050 ComplexBlackBoxDescriptor::Pointer p =
00051 MakePointer(new ComplexBlackBoxDescriptor(name));
00052 bbtkDebugMessage("object",1,"<## ComplexBlackBoxDescriptor::New(\""<<name<<"\")"<<std::endl);
00053 return p;
00054 }
00055
00056
00057
00059 ComplexBlackBoxDescriptor::ComplexBlackBoxDescriptor(const std::string& name)
00060 {
00061 bbtkDebugMessage("object",2,"==> ComplexBlackBoxDescriptor::ComplexBlackBoxDescriptor(\""<<name<<"\")"<<std::endl);
00062 SetTypeName(name);
00063 AddToCategory("complex box");
00064 mPrototype = ComplexBlackBox::New(name+std::string("Prototype"),
00065 MakePointer(this,true));
00066 mPrototype->SetAsPrototype();
00067 bbtkDebugMessage("object",2,"<== ComplexBlackBoxDescriptor::ComplexBlackBoxDescriptor(\""<<name<<"\")"<<std::endl);
00068 }
00069
00070
00071
00072
00073
00075 ComplexBlackBoxDescriptor::~ComplexBlackBoxDescriptor()
00076 {
00077 bbtkDebugMessage("object",2,"==> ComplexBlackBoxDescriptor::~ComplexBlackBoxDescriptor(\""<<GetTypeName()<<"\")"<<std::endl);
00078
00079 mPrototype.reset();
00080 bbtkDebugMessage("object",2,"<== ComplexBlackBoxDescriptor::~ComplexBlackBoxDescriptor(\""<<GetTypeName()<<"\")"<<std::endl);
00081 }
00082
00083
00084
00086 void ComplexBlackBoxDescriptor::Check(bool recursive) const
00087 {
00088 mPrototype->Check(recursive);
00089 }
00090
00091
00092
00094 BlackBox::Pointer
00095 ComplexBlackBoxDescriptor::NewBlackBox(const std::string& name)
00096 {
00097 bbtkDebugMessageInc("Kernel",5,
00098 "ComplexBlackBoxDescriptor::NewBlackBox(\""
00099 <<name<<"\") ["
00100 <<GetTypeName()<<"]"<<std::endl);
00101
00102 return mPrototype->bbClone(name);
00103
00104 bbtkDebugDecTab("Kernel",5);
00105 }
00106
00107
00108
00109
00111
00112
00113
00114
00115
00116
00117
00119 void ComplexBlackBoxDescriptor::Add ( const std::string& type,
00120 const std::string& name
00121 )
00122 {
00123 bbtkDebugMessageInc("Kernel",5,
00124 "ComplexBlackBoxDescriptor::Add(\""
00125 <<type<<"\",\""<<name<<"\") ["
00126 <<GetTypeName()<<"]"<<std::endl);
00127
00128
00129 if (!GetFactory())
00130 {
00131 bbtkError("ComplexBlackBoxDescriptor::Add : no factory set");
00132 }
00133
00134
00135 if ( mPrototype->bbUnsafeGetBlackBox( name ) )
00136 {
00137 bbtkError("a black box \""<<name<<"\" already exists");
00138 }
00139
00140 mPrototype->bbAddBlackBox ( GetFactory()->NewBlackBox(type,name) );
00141
00142 bbtkDebugDecTab("Kernel",5);
00143 }
00144
00145
00146
00148 void ComplexBlackBoxDescriptor::Remove( const std::string& name,
00149 bool remove_connections)
00150 {
00151 mPrototype->bbRemoveBlackBox(name,remove_connections);
00152 }
00153
00154
00155
00156
00158 void ComplexBlackBoxDescriptor::AddToExecutionList ( const std::string& box)
00159 {
00160 bbtkDebugMessageInc("Kernel",5,
00161 "ComplexBlackBoxDescriptor::AddToExecutionList(\""
00162 <<box<<"\" ["
00163 <<GetTypeName()<<"]"<<std::endl);
00164
00165 BlackBox::Pointer b = mPrototype->bbUnsafeGetBlackBox( box );
00166 if ( !b )
00167 {
00168 bbtkError("the black box \""<<box<<"\" does not exist");
00169 }
00170
00171 mPrototype->bbAddToExecutionList ( box );
00172
00173 bbtkDebugDecTab("Kernel",5);
00174 }
00175
00176
00177
00179 void ComplexBlackBoxDescriptor::Connect ( const std::string& from,
00180 const std::string& output,
00181 const std::string& to,
00182 const std::string& input
00183 )
00184 {
00185 bbtkDebugMessageInc("Kernel",5,
00186 "ComplexBlackBoxDescriptor::Connect(\""
00187 <<from<<"\",\""<<output<<"\",\""
00188 <<to<<"\",\""<<input
00189 <<"\") ["
00190 <<GetTypeName()<<"]"<<std::endl);
00191
00192 if (!GetFactory())
00193 {
00194 bbtkError("ComplexBlackBoxDescriptor::Connect : no factory set");
00195 }
00196
00197
00198
00199 BlackBox::Pointer bbfrom = mPrototype->bbGetBlackBox( from );
00200 if ( !bbfrom )
00201 {
00202 bbtkError("the black box \""<<from<<"\" does not exist");
00203 }
00204 BlackBox::Pointer bbto = mPrototype->bbGetBlackBox( to );
00205 if ( !bbto )
00206 {
00207 bbtkError("the black box \""<<to<<"\" does not exist");
00208 }
00209
00210 Connection::Pointer c
00211 = GetFactory()->NewConnection( bbfrom, output, bbto, input );
00212
00213 mPrototype->bbAddConnection(c);
00214
00215 bbtkDebugDecTab("Kernel",5);
00216 }
00217
00218
00219
00220
00222 void ComplexBlackBoxDescriptor::DefineInput ( const std::string& name,
00223 const std::string& box,
00224 const std::string& input,
00225 const std::string& help)
00226 {
00227 bbtkDebugMessageInc("Kernel",5,
00228 "ComplexBlackBoxDescriptor::DefineInput(\""
00229 <<name<<"\",\""<<box<<"\",\""
00230 <<input<<"\",\""<<help
00231 <<"\") ["
00232 <<GetTypeName()<<"]"<<std::endl);
00233
00234 BlackBox::Pointer bb = mPrototype->bbGetBlackBox( box );
00235 if ( !bb )
00236 {
00237 bbtkError("the black box \""<<box<<"\" does not exist");
00238 }
00239
00240 if (!bb->bbHasInput(input) )
00241 {
00242 bbtkError("the black box \""<<box<<"\" does not have input \""
00243 <<input<<"\"");
00244 }
00245
00246 const BlackBoxInputDescriptor* d =
00247 bb->bbGetDescriptor()->GetInputDescriptor(input);
00248 AddInputDescriptor ( new ComplexBlackBoxInputDescriptor
00249 ( typeid(ComplexBlackBoxDescriptor),
00250 name,
00251 help,
00252 d->GetNature(),
00253 box,
00254 input,
00255 d->GetTypeInfo()));
00256
00257
00258 bbtkDebugDecTab("Kernel",5);
00259 }
00260
00261
00262
00264 void ComplexBlackBoxDescriptor::DefineOutput ( const std::string& name,
00265 const std::string& box,
00266 const std::string& output,
00267 const std::string& help)
00268 {
00269 bbtkDebugMessageInc("Kernel",5,
00270 "ComplexBlackBoxDescriptor::DefineOutput(\""
00271 <<name<<"\",\""<<box<<"\",\""
00272 <<output<<"\",\""<<help
00273 <<"\") ["
00274 <<GetTypeName()<<"]"<<std::endl);
00275
00276 BlackBox::Pointer bb = mPrototype->bbGetBlackBox( box );
00277 if ( !bb )
00278 {
00279 bbtkError("the black box \""<<box<<"\" does not exist");
00280 }
00281
00282 if (!bb->bbHasOutput(output) )
00283 {
00284 bbtkError("the black box \""<<box<<"\" does not have output \""
00285 <<output<<"\"");
00286 }
00287
00288 const BlackBoxOutputDescriptor* d =
00289 bb->bbGetDescriptor()->GetOutputDescriptor(output);
00290 AddOutputDescriptor ( new ComplexBlackBoxOutputDescriptor
00291 ( typeid(ComplexBlackBoxDescriptor),
00292 name,
00293 help,
00294 d->GetNature(),
00295 box,
00296 output,
00297 d->GetTypeInfo()));
00298
00299
00300 bbtkDebugDecTab("Kernel",5);
00301 }
00302
00303
00304
00305 void ComplexBlackBoxDescriptor::PrintBlackBoxes()
00306 {
00307 mPrototype->bbPrintBlackBoxes();
00308 }
00309
00310
00311
00312
00313 void ComplexBlackBoxDescriptor::InsertHTMLGraph( std::ofstream& s ,
00314 int detail, int level,
00315 const std::string& output_dir, bool relative_link )
00316 {
00317 this->mPrototype->bbInsertHTMLGraph( s,
00318 detail, level,
00319 false,
00320 output_dir,
00321 relative_link );
00322 }
00323
00324
00325
00326 void ComplexBlackBoxDescriptor::InsertHtmlHelp ( std::ofstream& s,
00327 int detail, int level,
00328 const std::string& output_dir, bool relative_link)
00329 {
00330 bbtkDebugMessageInc("Kernel",9,
00331 "ComplexBlackBoxDescriptor::InsertHtmlHelp() ["
00332 <<GetTypeName()<<"]"<<std::endl);
00333
00334
00335
00336 std::string name = GetTypeName();
00337 Utilities::html_format(name);
00338
00339
00340
00341 (s) << "<p><hr>\n";
00342 (s) << "<a name=\""<<name<<"\"></a>\n";
00343 (s) <<
00344 "<a rel=\"top\" accesskey=\"t\" href=\"#Top\">Top</a>\n";
00345
00346
00347 (s) << "<h2 class=\"section\">"<<name<<"</h2>\n";
00348
00349
00350 std::string descr = GetDescription();
00351
00352
00353 std::string author = GetAuthor();
00354 Utilities::html_format(author);
00355
00356 std::vector<std::string> categories;
00357
00358 std::string delimiters = ";,";
00359 Utilities::SplitString(GetCategory(),
00360 delimiters,categories);
00361
00362
00363 (s) << "<p><TABLE cellspacing=0 cellpadding=3>\n";
00364 (s) << "<TR><TD style='vertical-align: top;'><b> Description </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
00365 << descr << "</TD></TR>\n";
00366
00367 (s) << "<TR><TD style='vertical-align: top;'><b> Author(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
00368 << author << "</TD></TR>\n";
00369
00370 (s) << "<TR><TD style='vertical-align: top;'><b> Category(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> ";
00371 std::vector<std::string>::iterator ci;
00372 for (ci=categories.begin(); ci!=categories.end(); ++ci)
00373 {
00374 s << "<a href=\"../index-category.html#"<< *ci <<"\">" << *ci
00375 << "</a> \n";
00376 }
00377 s << "</TD></TR>\n";
00378 std::string inc = GetScriptFileName();
00379 if (inc.size()>0)
00380 {
00381 s << "<TR><TD style='vertical-align: top;'><b> To use it </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> include ";
00382
00383
00384 s << inc << " <a href=\""<<inc<<"\">[source]</a>";
00385 s << "</TD></TR>\n";
00386
00387 }
00388
00389 const ComplexBlackBox::BlackBoxMapType& B = mPrototype->bbGetBlackBoxMap();
00390
00391 if (B.size())
00392 {
00393 (s) << "<TR><TD style='vertical-align: top;'><b> Uses </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> ";
00394
00395 std::set<BlackBoxDescriptor::Pointer> pdeps;
00396 ComplexBlackBox::BlackBoxMapType::const_iterator b;
00397 for ( b = B.begin(); b != B.end(); ++b )
00398 {
00399 BlackBoxDescriptor::Pointer d = b->second->bbGetDescriptor();
00400 if (pdeps.find(d) != pdeps.end())
00401 continue;
00402 pdeps.insert(d);
00403
00404 Package::Pointer p = d->GetPackage();
00405
00406 std::string name = b->second->bbGetTypeName();
00407
00408 std::string url;
00409 if (relative_link)
00410 url = p->GetDocRelativeURL();
00411 else
00412 url = p->GetDocURL();
00413
00414 s << "<a href=\"" <<url<<"#"<<name<<"\">"
00415 << p->GetName()<<"::"<<name<<"</a>\n";
00416 }
00417
00418 (s) << "</TD></TR>\n";
00419
00420 }
00421
00422 (s) << "</TABLE>\n";
00423
00424
00425
00426
00427 InsertHTMLGraph( s , detail,level, output_dir, relative_link);
00428
00429
00430
00431 std::string col("#CCCCFF");
00432
00433
00434 (s) << "<p><TABLE border=1 cellspacing=0 cellpadding=3>\n";
00435 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<col
00436 <<"\">Inputs</TD></TR>\n";
00437 const BlackBoxDescriptor::InputDescriptorMapType& imap =
00438 GetInputDescriptorMap();
00439
00440 InputDescriptorMapType::const_iterator in;
00441
00442 for ( in = imap.begin(); in != imap.end(); ++in )
00443 {
00444 std::string name(in->second->GetName());
00445 Utilities::html_format(name);
00446
00447 std::string type("<");
00448 type += in->second->GetTypeName();
00449 type += ">";
00450 Utilities::html_format(type);
00451
00452 std::string descr(in->second->GetDescription());
00453
00454
00455 (s) << "<TR><TD style='vertical-align: top;'><B><PRE> "<<name<<" </PRE></B></TD>"
00456 << "<TD style='vertical-align: top;'><I><PRE> "<<type<<" </PRE></I></TD>"
00457 << "<TD style='vertical-align: top;'>"<<descr<<"</TD></TR>\n";
00458
00459 }
00460
00461
00462
00463
00464
00465
00466
00467 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<col
00468 <<"\">Outputs</TD></TR>\n";
00469
00470 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
00471 GetOutputDescriptorMap();
00472
00473 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
00474
00475 for ( o = omap.begin(); o != omap.end(); ++o )
00476 {
00477 std::string name(o->second->GetName());
00478 Utilities::html_format(name);
00479
00480 std::string type("<");
00481 type += o->second->GetTypeName();
00482 type += ">";
00483 Utilities::html_format(type);
00484
00485 std::string descr(o->second->GetDescription());
00486
00487
00488 (s) << "<TR><TD style='vertical-align: top;'><B><PRE> "<<name<<" </PRE></B></TD>"
00489 << "<TD style='vertical-align: top;'><I><PRE> "<<type<<" </PRE></I></TD>"
00490 << "<TD style='vertical-align: top;'>"<<descr<<"</TD></TR>\n";
00491
00492 }
00493 (s) << "</TABLE>\n";
00494
00495
00496
00497
00498 bbtkDebugDecTab("Kernel",9);
00499 }
00500
00501
00502
00503
00504 void ComplexBlackBoxDescriptor::GetHelp(bool full) const
00505 {
00506 if (full) bbtkMessage("Help",1,"Complex Black Box <"<<
00507 GetPackage()->GetName()<<"::"
00508 <<GetTypeName()<<">"<<std::endl);
00509 bbtkMessage("Help",1," " << GetDescription() <<std::endl);
00510 bbtkMessage("Help",1," By : " << GetAuthor() <<std::endl);
00511 bbtkMessage("Help",1," Category(s) : " << GetCategory() <<std::endl);
00512 if (mInput.size())
00513 bbtkMessage("Help",1," * Inputs : "<<std::endl);
00514 else
00515 bbtkMessage("Help",1," * No inputs"<<std::endl);
00516 InputDescriptorMapType::const_iterator i;
00517 unsigned int namelmax = 0;
00518 unsigned int typelmax = 0;
00519 unsigned int natlmax = 0;
00520 for ( i = mInput.begin(); i != mInput.end(); ++i )
00521 {
00522 if (i->second->GetName().size()>namelmax)
00523 namelmax = i->second->GetName().size();
00524 if (i->second->GetTypeName().size()>typelmax)
00525 typelmax = i->second->GetTypeName().size();
00526 if (i->second->GetNature().size()>natlmax)
00527 natlmax = i->second->GetNature().size();
00528 }
00529 OutputDescriptorMapType::const_iterator o;
00530 if (full)
00531 {
00532 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
00533 {
00534 if (o->second->GetName().size()>namelmax)
00535 namelmax = o->second->GetName().size();
00536 if (o->second->GetTypeName().size()>typelmax)
00537 typelmax = o->second->GetTypeName().size();
00538 if (o->second->GetNature().size()>natlmax)
00539 natlmax = o->second->GetNature().size();
00540 }
00541 }
00542
00543
00544 for ( i = mInput.begin(); i != mInput.end(); ++i )
00545 {
00546 std::string name(i->second->GetName());
00547 name += "'";
00548 name.append(1+namelmax-name.size(),' ');
00549 std::string type(i->second->GetTypeName());
00550 type += ">";
00551 type.append(1+typelmax-type.size(),' ');
00552 std::string nature(i->second->GetNature());
00553 nature += "]";
00554 nature.append(1+natlmax-nature.size(),' ');
00555 bbtkMessage("Help",1,
00556 " '"<<name
00557 <<" <"<<type
00558 <<" ["<<nature
00559 <<" : "<<i->second->GetDescription()<<std::endl);
00560 }
00561 if (full)
00562 {
00563 if (mOutput.size())
00564 bbtkMessage("Help",1," * Outputs : "<<std::endl);
00565 else
00566 bbtkMessage("Help",1," * No outputs"<<std::endl);
00567 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
00568 {
00569 std::string name(o->second->GetName());
00570 name += "'";
00571 name.append(1+namelmax-name.size(),' ');
00572 std::string type(o->second->GetTypeName());
00573 type += ">";
00574 type.append(1+typelmax-type.size(),' ');
00575 std::string nature(o->second->GetNature());
00576 nature += "]";
00577 nature.append(1+natlmax-nature.size(),' ');
00578 bbtkMessage("Help",1,
00579 " '"<<name
00580 <<" <"<<type
00581 <<" ["<<nature
00582 <<" : "<<o->second->GetDescription()<<std::endl);
00583 }
00584 }
00585 if (full)
00586 {
00587 const ComplexBlackBox::BlackBoxMapType& B = mPrototype->bbGetBlackBoxMap();
00588
00589 if (B.size())
00590 bbtkMessage("Help",1," * Boxes : "<<std::endl);
00591 else
00592 bbtkMessage("Help",1," * No boxes"<<std::endl);
00593
00594 ComplexBlackBox::BlackBoxMapType::const_iterator b;
00595 for ( b = B.begin(); b != B.end(); ++b )
00596 {
00597 bbtkMessage("Help",1," '"<<b->second->bbGetName()<<
00598 "' <"
00599 << b->second->bbGetDescriptor()->GetPackage()->GetName()
00600 <<"::"
00601 <<b->second->bbGetTypeName()<<">"<<std::endl);
00602 }
00603 }
00604
00605 }
00606
00607
00608
00609 std::string ComplexBlackBoxDescriptor::GetObjectName() const
00610 {
00611 return std::string("ComplexBlackBoxDescriptor '")+GetFullTypeName()
00612 +std::string("'");
00613 }
00614
00615
00616 std::string ComplexBlackBoxDescriptor::GetObjectInfo() const
00617 {
00618 std::string i;
00619 return i;
00620 }
00621
00622
00623 size_t ComplexBlackBoxDescriptor::GetObjectSize() const
00624 {
00625 size_t s = Superclass::GetObjectSize();
00626 s += ComplexBlackBoxDescriptor::GetObjectInternalSize();
00627 return s;
00628 }
00629
00630
00631 size_t ComplexBlackBoxDescriptor::GetObjectInternalSize() const
00632 {
00633 size_t s = sizeof(ComplexBlackBoxDescriptor);
00634 return s;
00635 }
00636
00637
00638 size_t ComplexBlackBoxDescriptor::GetObjectRecursiveSize() const
00639 {
00640 size_t s = Superclass::GetObjectRecursiveSize();
00641 s += ComplexBlackBoxDescriptor::GetObjectInternalSize();
00642 s += mPrototype->GetObjectRecursiveSize();
00643 return s;
00644 }
00645
00646
00647 }