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 "bbtkBlackBoxDescriptor.h"
00037 #include "bbtkMessageManager.h"
00038 #include "bbtkPackage.h"
00039 #include "bbtkUtilities.h"
00040 #include "bbtkAtomicBlackBoxDescriptor.h"
00041 #include "bbtkWxBlackBox.h"
00042
00043 namespace bbtk
00044 {
00045
00046 typedef Package::Pointer PackagePointer;
00047
00048
00049
00050
00052 BlackBoxDescriptor::BlackBoxDescriptor()
00053 : mTypeName("Unknown"),
00054 mDescription(""),
00055 mAuthor(""),
00056 mCategory(""),
00057 mKind(STANDARD),
00058 mPackage()
00059 {
00060 bbtkDebugMessage("object",4,
00061 "==> BlackBoxDescriptor::BlackBoxDescriptor()"<<std::endl);
00062 bbtkDebugMessage("object",4,
00063 "<== BlackBoxDescriptor::BlackBoxDescriptor()"<<std::endl);
00064 }
00065
00066
00067
00069 BlackBoxDescriptor::BlackBoxDescriptor(const BlackBoxDescriptor&)
00070 {
00071 }
00072
00074 BlackBoxDescriptor::~BlackBoxDescriptor()
00075 {
00076 bbtkDebugMessage("object",4,
00077 "==> BlackBoxDescriptor::~BlackBoxDescriptor() ["
00078 <<mTypeName<<"]"<<std::endl);
00079
00080
00081 InputDescriptorMapType::iterator i;
00082 for (i=mInput.begin(); i!=mInput.end(); ++i) delete i->second;
00083 OutputDescriptorMapType::iterator o;
00084 for (o=mOutput.begin(); o!=mOutput.end(); ++o) delete o->second;
00085
00086 bbtkDebugMessage("object",4,
00087 "<== BlackBoxDescriptor::~BlackBoxDescriptor() ["
00088 <<mTypeName<<"]"<<std::endl);
00089 }
00090
00091
00092
00093
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00139 void BlackBoxDescriptor::Check(bool) const
00140 {
00141
00142 }
00143
00144
00145
00147 void BlackBoxDescriptor::AddToDescription( const std::string& s, bool clear)
00148 {
00149 bbtkDebugMessage("Kernel",9,"BlackBoxDescriptor::AddToDescription(\""<<s<<
00150 "\") ["<<GetFullTypeName()<<"]"<<std::endl);
00151 if (clear) mDescription = s;
00152 else mDescription += s;
00153 }
00154
00155
00156
00158 void BlackBoxDescriptor::AddToAuthor( const std::string& s, bool clear)
00159 {
00160 bbtkDebugMessage("Kernel",9,"BlackBoxDescriptor::AddToAuthor(\""<<s<<"\") ["
00161 <<GetFullTypeName()<<"]"<<std::endl);
00162 if (clear) mAuthor = s;
00163 else mAuthor += s;
00164 }
00165
00166
00167
00169 void BlackBoxDescriptor::AddToCategory( const std::string& s, bool clear)
00170 {
00171 bbtkDebugMessage("Kernel",9,"BlackBoxDescriptor::AddToCategory(\""<<s<<"\") ["
00172 <<GetFullTypeName()<<"]"<<std::endl);
00173 if (clear) mCategory = s;
00174 else mCategory += s;
00175 mCategory += ";";
00176 }
00177
00178
00179
00180 const BlackBoxDescriptor::InputDescriptor*
00181 BlackBoxDescriptor::GetInputDescriptor(const std::string & name) const
00182 {
00183 bbtkDebugMessageInc("Kernel",9,"BlackBoxDescriptor::GetInputDescriptor('"
00184 <<name<<"') ["<<GetFullTypeName()<<"]"<<std::endl);
00185
00186 InputDescriptorMapType::const_iterator i;
00187 i = mInput.find(name);
00188 if ( i == mInput.end() )
00189 {
00190 bbtkError("input '"<<name<<"' does not exist");
00191 }
00192 bbtkDebugDecTab("Kernel",9);
00193 return i->second;
00194 }
00195
00196
00197
00198 const BlackBoxDescriptor::OutputDescriptor*
00199 BlackBoxDescriptor::GetOutputDescriptor(const std::string & name) const
00200 {
00201 bbtkDebugMessageInc("Kernel",9,"BlackBoxDescriptor::GetOutputDescriptor('"
00202 <<name<<"') ["<<GetFullTypeName()<<"]"<<std::endl);
00203
00204 OutputDescriptorMapType::const_iterator i;
00205 i = mOutput.find(name);
00206 if ( i == mOutput.end() )
00207 {
00208 bbtkError("output '"<<name<<"' does not exist");
00209 }
00210 bbtkDebugDecTab("Kernel",9);
00211 return i->second;
00212 }
00213
00214
00215
00216 void BlackBoxDescriptor::GetHelp(bool full) const
00217 {
00218 bbtkDebugMessageInc("Kernel",9,"BlackBoxDescriptor::GetHelp() ["<<GetFullTypeName()<<"]"<<std::endl);
00219
00220 bbtkMessage("Help",1,"Black Box <"<<GetFullTypeName()<<">"<<std::endl);
00221 bbtkMessage("Help",1," " <<GetDescription()<<std::endl);
00222 bbtkMessage("Help",1," By : " <<GetAuthor() <<std::endl);
00223 bbtkMessage("Help",1," Categories : " <<GetCategory() <<std::endl);
00224 if (mInput.size())
00225 bbtkMessage("Help",1," * Inputs : "<<std::endl);
00226 else
00227 bbtkMessage("Help",1," * No inputs"<<std::endl);
00228 InputDescriptorMapType::const_iterator i;
00229 unsigned int namelmax = 0;
00230 unsigned int typelmax = 0;
00231 unsigned int natlmax = 0;
00232 for ( i = mInput.begin(); i != mInput.end(); ++i )
00233 {
00234 if (i->second->GetName().size()>namelmax)
00235 namelmax = i->second->GetName().size();
00236 if (i->second->GetHumanTypeName().size()>typelmax)
00237 typelmax = i->second->GetHumanTypeName().size();
00238 if (i->second->GetNature().size()>natlmax)
00239 natlmax = i->second->GetNature().size();
00240 }
00241 OutputDescriptorMapType::const_iterator o;
00242 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
00243 {
00244 if (o->second->GetName().size()>namelmax)
00245 namelmax = o->second->GetName().size();
00246 if (o->second->GetHumanTypeName().size()>typelmax)
00247 typelmax = o->second->GetHumanTypeName().size();
00248 if (o->second->GetNature().size()>natlmax)
00249 natlmax = o->second->GetNature().size();
00250 }
00251
00252 for ( i = mInput.begin(); i != mInput.end(); ++i )
00253 {
00254 std::string name(i->second->GetName());
00255 name += "'";
00256 name.append(1+namelmax-name.size(),' ');
00257 std::string type(i->second->GetHumanTypeName());
00258 type += ">";
00259 type.append(1+typelmax-type.size(),' ');
00260 std::string nature(i->second->GetNature());
00261 nature += "]";
00262 nature.append(1+natlmax-nature.size(),' ');
00263 bbtkMessage("Help",1,
00264 " '"<<name
00265 <<" <"<<type
00266 <<" ["<<nature
00267 <<" : "<<i->second->GetDescription()<<std::endl);
00268 }
00269 if (mOutput.size())
00270 bbtkMessage("Help",1," * Outputs : "<<std::endl);
00271 else
00272 bbtkMessage("Help",1," * No outputs"<<std::endl);
00273 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
00274 {
00275 std::string name(o->second->GetName());
00276 name += "'";
00277 name.append(1+namelmax-name.size(),' ');
00278 std::string type(o->second->GetHumanTypeName());
00279 type += ">";
00280 type.append(1+typelmax-type.size(),' ');
00281 std::string nature(o->second->GetNature());
00282 nature += "]";
00283 nature.append(1+natlmax-nature.size(),' ');
00284 bbtkMessage("Help",1,
00285 " '"<<name
00286 <<" <"<<type
00287 <<" ["<<nature
00288 <<" : "<<o->second->GetDescription()<<std::endl);
00289 }
00290
00291 bbtkDebugDecTab("Kernel",9);
00292
00293
00294 }
00295
00296
00297
00299 std::string BlackBoxDescriptor::GetFullTypeName() const
00300 {
00301 if (GetPackage()!=0) return GetPackage()->GetName() + "::" + mTypeName;
00302 return "::" + mTypeName;
00303 }
00304
00305
00306
00307 void BlackBoxDescriptor::InsertHtmlHelp ( std::ofstream& s,
00308 int detail, int level,
00309 const std::string& output_dir,
00310 bool relative_link )
00311 {
00312 bbtkDebugMessageInc("Kernel",9,"BlackBoxDescriptor::InsertHtmlHelp() ["<<GetFullTypeName()<<"]"<<std::endl);
00313
00314
00315
00316 std::string name = GetTypeName();
00317 Utilities::html_format(name);
00318
00319 (s) << "<p><hr>\n";
00320 (s) << "<a name=\""<<name<<"\"></a>\n";
00321 (s) <<
00322 "<a rel=\"top\" accesskey=\"t\" href=\"#Top\">Top</a>\n";
00323
00324
00325 (s) << "<h2 class=\"section\">"<<name<<"</h2>\n";
00326
00327
00328 std::string descr = GetDescription();
00329
00330 std::string author = GetAuthor();
00331 Utilities::html_format(author);
00332
00333 std::vector<std::string> categories;
00334
00335 std::string delimiters = ";,";
00336 Utilities::SplitString(GetCategory(),
00337 delimiters,categories);
00338
00339
00340 (s) << "<p><TABLE cellspacing=0 cellpadding=3>\n";
00341 (s) << "<TR><TD style='vertical-align: top;'><b> Description </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
00342 << descr << "</TD></TR>\n";
00343 (s) << "<TR><TD style='vertical-align: top;'><b> Author(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
00344 << author << "</TD></TR>\n";
00345 (s) << "<TR><TD style='vertical-align: top;'><b> Category(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> ";
00346 std::vector<std::string>::iterator ci;
00347 for (ci=categories.begin(); ci!=categories.end(); ++ci)
00348 {
00349 s << "<a href=\"../index-category.html#"<< *ci <<"\">" << *ci
00350 << "</a> \n";
00351 }
00352 s << "</TD></TR>\n";
00353
00354 (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 "
00355 << GetPackage()->GetName() << "</TD></TR>\n";
00356 (s) << "</TABLE>\n";
00357
00358
00359
00360
00361
00362
00363
00364 std::string titlecol("#BBBBFF");
00365 std::string usercol("#FFFFFF");
00366 std::string ubbcol("#DDFFFF");
00367 std::string wxbbcol("#EEFFFF");
00368
00369
00370
00371 (s) << "<p><TABLE border=1 cellspacing=0 cellpadding=3>\n";
00372 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<titlecol
00373 <<"\">Inputs</TD></TR>\n";
00374
00375 std::vector<std::string> user_defined;
00376 std::vector<std::string> ubb_defined;
00377 std::vector<std::string> wxbb_defined;
00378
00379 const BlackBoxDescriptor::InputDescriptorMapType& imap =
00380 GetInputDescriptorMap();
00381 InputDescriptorMapType::const_iterator in;
00382 for ( in = imap.begin(); in != imap.end(); ++in )
00383 {
00384
00385 std::string col(usercol);
00386 int iotype = 0;
00387 if (in->second->GetCreatorTypeInfo() ==
00388 typeid(AtomicBlackBoxDescriptor))
00389 {
00390 col = ubbcol;
00391 iotype = 1;
00392 }
00393 else if (in->second->GetCreatorTypeInfo() ==
00394 typeid(WxBlackBoxDescriptor))
00395 {
00396 col = wxbbcol;
00397 iotype = 2;
00398 }
00399
00400 std::string name(in->second->GetName());
00401 Utilities::html_format(name);
00402
00403 std::string type("<");
00404 type += in->second->GetTypeName();
00405 type += ">";
00406 Utilities::html_format(type);
00407
00408 std::string descr(in->second->GetDescription());
00409
00410
00411 std::string out =
00412 "<TR><TD style='vertical-align: top;' bgcolor=\"" + col
00413 +"\"><B><PRE> "+name+" </PRE></B></TD>"
00414 + "<TD style='vertical-align: top;' bgcolor=\""+col
00415 +"\"><I><PRE> "+type+" </PRE></I></TD>"
00416 + "<TD style='vertical-align: top;' bgcolor=\""+col
00417 +"\">"+descr+"</TD></TR>\n";
00418
00419 if (iotype==0) user_defined.push_back(out);
00420 else if (iotype==1) ubb_defined.push_back(out);
00421 else if (iotype==2) wxbb_defined.push_back(out);
00422
00423 }
00424
00425 std::vector<std::string>::iterator hi;
00426 for (hi=user_defined.begin();hi!=user_defined.end();++hi) s << *hi;
00427 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi) s << *hi;
00428 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi) s << *hi;
00429
00430 user_defined.clear();
00431 ubb_defined.clear();
00432 wxbb_defined.clear();
00433
00434
00435
00436
00437
00438 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<titlecol
00439 <<"\">Outputs</TD></TR>\n";
00440
00441 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
00442 GetOutputDescriptorMap();
00443
00444 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
00445
00446 for ( o = omap.begin(); o != omap.end(); ++o )
00447 {
00448 std::string col(usercol);
00449 int iotype = 0;
00450 if (o->second->GetCreatorTypeInfo() ==
00451 typeid(AtomicBlackBoxDescriptor))
00452 {
00453 col = ubbcol;
00454 iotype = 1;
00455 }
00456 else if (o->second->GetCreatorTypeInfo() ==
00457 typeid(WxBlackBoxDescriptor))
00458 {
00459 col = wxbbcol;
00460 iotype = 2;
00461 }
00462
00463 std::string name(o->second->GetName());
00464 Utilities::html_format(name);
00465
00466 std::string type("<");
00467 type += o->second->GetTypeName();
00468 type += ">";
00469 Utilities::html_format(type);
00470
00471 std::string descr(o->second->GetDescription());
00472
00473
00474 std::string out =
00475 "<TR><TD style='vertical-align: top;' bgcolor=\"" + col
00476 +"\"><B><PRE> "+name+" </PRE></B></TD>"
00477 + "<TD style='vertical-align: top;' bgcolor=\""+col
00478 +"\"><I><PRE> "+type+" </PRE></I></TD>"
00479 + "<TD style='vertical-align: top;' bgcolor=\""+col
00480 +"\">"+descr+"</TD></TR>\n";
00481
00482 if (iotype==0) user_defined.push_back(out);
00483 else if (iotype==1) ubb_defined.push_back(out);
00484 else if (iotype==2) wxbb_defined.push_back(out);
00485
00486 }
00487
00488 for (hi=user_defined.begin();hi!=user_defined.end();++hi) s << *hi;
00489 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi) s << *hi;
00490 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi) s << *hi;
00491
00492 (s) << "</TABLE>\n";
00493
00494
00495
00496
00497 bbtkDebugDecTab("Kernel",9);
00498 }
00499
00500
00501 }