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
00460
00461
00462
00463
00464
00465 (s) << "<TR><TD style='vertical-align: top;'><B><PRE> "<<name<<" </PRE></B></TD>"
00466 << "<TD style='vertical-align: top;'><I><PRE> "<<descr<<" </PRE></I></TD>"
00467 << "<TD style='vertical-align: top;'>"<<type<<"</TD></TR>\n";
00468
00469 }
00470
00471
00472
00473
00474
00475
00476
00477 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<col
00478 <<"\">Outputs</TD></TR>\n";
00479
00480 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
00481 GetOutputDescriptorMap();
00482
00483 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
00484
00485 for ( o = omap.begin(); o != omap.end(); ++o )
00486 {
00487 std::string name(o->second->GetName());
00488 Utilities::html_format(name);
00489
00490 std::string type("<");
00491 type += o->second->GetTypeName();
00492 type += ">";
00493 Utilities::html_format(type);
00494
00495 std::string descr(o->second->GetDescription());
00496
00497
00498
00499
00500
00501
00502
00503 (s) << "<TR><TD style='vertical-align: top;'><B><PRE> "<<name<<" </PRE></B></TD>"
00504 << "<TD style='vertical-align: top;'><I><PRE> "<<descr<<" </PRE></I></TD>"
00505 << "<TD style='vertical-align: top;'>"<<type<<"</TD></TR>\n";
00506
00507 }
00508 (s) << "</TABLE>\n";
00509
00510
00511
00512
00513
00514 }
00515
00516
00517
00518
00519 void ComplexBlackBoxDescriptor::GetHelp(bool full) const
00520 {
00521 if (full) bbtkMessage("help",1,"Complex Black Box <"<<
00522 GetPackage()->GetName()<<"::"
00523 <<GetTypeName()<<">"<<std::endl);
00524 bbtkMessage("help",1," " << GetDescription() <<std::endl);
00525 bbtkMessage("help",1," By : " << GetAuthor() <<std::endl);
00526 bbtkMessage("help",1," Category(s) : " << GetCategory() <<std::endl);
00527 if (mInput.size())
00528 bbtkMessage("help",1," * Inputs : "<<std::endl);
00529 else
00530 bbtkMessage("help",1," * No inputs"<<std::endl);
00531 InputDescriptorMapType::const_iterator i;
00532 unsigned int namelmax = 0;
00533 unsigned int typelmax = 0;
00534 unsigned int natlmax = 0;
00535 for ( i = mInput.begin(); i != mInput.end(); ++i )
00536 {
00537 if (i->second->GetName().size()>namelmax)
00538 namelmax = i->second->GetName().size();
00539 if (i->second->GetTypeName().size()>typelmax)
00540 typelmax = i->second->GetTypeName().size();
00541 if (i->second->GetNature().size()>natlmax)
00542 natlmax = i->second->GetNature().size();
00543 }
00544 OutputDescriptorMapType::const_iterator o;
00545 if (full)
00546 {
00547 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
00548 {
00549 if (o->second->GetName().size()>namelmax)
00550 namelmax = o->second->GetName().size();
00551 if (o->second->GetTypeName().size()>typelmax)
00552 typelmax = o->second->GetTypeName().size();
00553 if (o->second->GetNature().size()>natlmax)
00554 natlmax = o->second->GetNature().size();
00555 }
00556 }
00557
00558
00559 for ( i = mInput.begin(); i != mInput.end(); ++i )
00560 {
00561 std::string name(i->second->GetName());
00562 name += "'";
00563 name.append(1+namelmax-name.size(),' ');
00564 std::string type(i->second->GetTypeName());
00565 type += ">";
00566 type.append(1+typelmax-type.size(),' ');
00567 std::string nature(i->second->GetNature());
00568 nature += "]";
00569 nature.append(1+natlmax-nature.size(),' ');
00570 bbtkMessage("help",1,
00571 " '"<<name
00572 <<" <"<<type
00573 <<" ["<<nature
00574 <<" : "<<i->second->GetDescription()<<std::endl);
00575 }
00576 if (full)
00577 {
00578 if (mOutput.size())
00579 bbtkMessage("help",1," * Outputs : "<<std::endl);
00580 else
00581 bbtkMessage("help",1," * No outputs"<<std::endl);
00582 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
00583 {
00584 std::string name(o->second->GetName());
00585 name += "'";
00586 name.append(1+namelmax-name.size(),' ');
00587 std::string type(o->second->GetTypeName());
00588 type += ">";
00589 type.append(1+typelmax-type.size(),' ');
00590 std::string nature(o->second->GetNature());
00591 nature += "]";
00592 nature.append(1+natlmax-nature.size(),' ');
00593 bbtkMessage("help",1,
00594 " '"<<name
00595 <<" <"<<type
00596 <<" ["<<nature
00597 <<" : "<<o->second->GetDescription()<<std::endl);
00598 }
00599 }
00600 if (full)
00601 {
00602 const ComplexBlackBox::BlackBoxMapType& B = mPrototype->bbGetBlackBoxMap();
00603
00604 if (B.size())
00605 bbtkMessage("help",1," * Boxes : "<<std::endl);
00606 else
00607 bbtkMessage("help",1," * No boxes"<<std::endl);
00608
00609 ComplexBlackBox::BlackBoxMapType::const_iterator b;
00610 for ( b = B.begin(); b != B.end(); ++b )
00611 {
00612 bbtkMessage("help",1," '"<<b->second->bbGetName()<<
00613 "' <"
00614 << b->second->bbGetDescriptor()->GetPackage()->GetName()
00615 <<"::"
00616 <<b->second->bbGetTypeName()<<">"<<std::endl);
00617 }
00618 }
00619
00620 }
00621
00622
00623
00624 std::string ComplexBlackBoxDescriptor::GetObjectName() const
00625 {
00626 return std::string("ComplexBlackBoxDescriptor '")+GetFullTypeName()
00627 +std::string("'");
00628 }
00629
00630
00631 std::string ComplexBlackBoxDescriptor::GetObjectInfo() const
00632 {
00633 std::string i;
00634 return i;
00635 }
00636
00637
00638 size_t ComplexBlackBoxDescriptor::GetObjectSize() const
00639 {
00640 size_t s = Superclass::GetObjectSize();
00641 s += ComplexBlackBoxDescriptor::GetObjectInternalSize();
00642 return s;
00643 }
00644
00645
00646 size_t ComplexBlackBoxDescriptor::GetObjectInternalSize() const
00647 {
00648 size_t s = sizeof(ComplexBlackBoxDescriptor);
00649 return s;
00650 }
00651
00652
00653 size_t ComplexBlackBoxDescriptor::GetObjectRecursiveSize() const
00654 {
00655 size_t s = Superclass::GetObjectRecursiveSize();
00656 s += ComplexBlackBoxDescriptor::GetObjectInternalSize();
00657 s += mPrototype->GetObjectRecursiveSize();
00658 return s;
00659 }
00660
00661
00662 }