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