00001 #include "stdafx.h"
00002
00003 #include "Dumper.h"
00004 #include "MakeVisitor.h"
00005
00006 #include "algorithm"
00007 #include <afxdlgs.h>
00008
00009 #include "globals.h"
00010 extern Globals global_vars;
00011
00012 int ind;
00013
00014 #include "SelConf.h"
00015 #include "OptionsDlg.h"
00016 #include "MakeVisitor.h"
00017
00018 const char* Dumper::m_strBonExtenderOptions = "BonExtender_Options";
00019 const char* Dumper::Yes_Str = "yes";
00020 const char* Dumper::Only_Str = "only";
00021 const char* Dumper::No_Str = "no";
00022 const char* Dumper::m_strGenVisitor = "GenerateVisitor";
00023 const char* Dumper::m_strVisitorSignature = "VisitorSignature";
00024 const char* Dumper::m_strGenInitMethod = "GenerateInitMethod";
00025 const char* Dumper::m_strGenFiniMethod = "GenerateFiniMethod";
00026 const char* Dumper::m_strGenAcceptWithTraversal = "GenerateAcceptMethodWithTraversal";
00027 const char* Dumper::m_strGenAcceptSpecialized = "GenerateAcceptMethodSpecialized";
00028 const char* Dumper::m_strSpecAcceptRetVal = "SpecializedAcceptReturnValue";
00029 const char* Dumper::m_strVCVersion6 = "VCVersion6";
00030 const char* Dumper::m_strTemplateGetter = "TemplateGetter";
00031 const char* Dumper::m_strOutputInSeparateFile = "OutputInSeparateFile";
00032 const char* Dumper::m_strTgtNamespace = "GenerateElementsIntoNamespace";
00033
00034 bool Dumper::m_bParsePrev = false;
00035 bool Dumper::m_bGenInit = false;
00036 bool Dumper::m_bGenFinalize = false;
00037 bool Dumper::m_bGenAcceptTrave = false;
00038 bool Dumper::m_bGenAcceptSpeci = false;
00039 bool Dumper::m_bGenTemplates = false;
00040 bool Dumper::m_bGenTemplVersion6 = true;
00041 bool Dumper::m_bGenRegular = true;
00042 bool Dumper::m_bGenVisitor = false;
00043 int Dumper::m_iVisitSign = 0;
00044 int Dumper::m_iSpecAcceptRetVal = 0;
00045 bool Dumper::m_bSafetyBackup = true;
00046
00047
00048
00049 Sheet * Dumper::getInstance()
00050 {
00051 if (!Sheet::m_theOnlyInstance)
00052 {
00053 Sheet::m_theOnlyInstance = new Dumper();
00054 return Sheet::m_theOnlyInstance;
00055 }
00056 return Sheet::m_theOnlyInstance;
00057 }
00058
00059
00060 Dumper::Dumper(): Sheet()
00061 {
00062 }
00063
00064
00065 Dumper::~Dumper()
00066 {
00067 }
00068
00069
00070 bool Dumper::findInFolders( FCO * fco)
00071 {
00072 std::vector<FolderRep*>::iterator it( m_folderList.begin());
00073 while( it != m_folderList.end() && !(*it)->isFCOContained( fco))
00074 ++it;
00075 return it != m_folderList.end();
00076 }
00077
00078
00079 void Dumper::inheritMoReSeCoFolAsp()
00080 {
00081
00082 ModelRep_Iterator mod_iter( m_modelList.begin());
00083 for( ; mod_iter != m_modelList.end(); ++mod_iter)
00084 (*mod_iter)->inherit();
00085
00086
00087
00088 ReferenceRep_Iterator ref_iter( m_refList.begin());
00089 for( ; ref_iter != m_refList.end(); ++ref_iter)
00090 (*ref_iter)->inherit();
00091
00092 ref_iter = m_refList.begin();
00093 for( ; ref_iter != m_refList.end(); ++ref_iter)
00094 if (!(*ref_iter)->finalize())
00095 {
00096
00097 }
00098
00099
00100 ConnectionRep_Iterator conn_iter( m_connList.begin());
00101 for( ; conn_iter != m_connList.end(); ++conn_iter)
00102 (*conn_iter)->inherit();
00103
00104
00105 SetRep_Iterator set_iter( m_setList.begin());
00106 for( ; set_iter != m_setList.end(); ++set_iter)
00107 (*set_iter)->extendMembership();
00108
00109
00110 std::vector<FolderRep*>::iterator folder_iter( m_folderList.begin());
00111 for( ; folder_iter != m_folderList.end(); ++folder_iter)
00112 (*folder_iter)->extendMembership();
00113 }
00114
00115
00116 std::string Dumper::getNamespaceName()
00117 {
00118
00119
00120 return m_validProjName + "_BON";
00121 }
00122
00123
00124 void Dumper::createMethods()
00125 {
00126
00127
00128
00129 MakeVisitor m_visitor( m_validProjName);
00130
00131
00132 {std::vector<ConnectionRep*>::const_iterator it_cn = m_connList.begin();
00133 if ( it_cn != m_connList.end())
00134 {
00135 for( ; it_cn != m_connList.end(); ++it_cn)
00136 (*it_cn)->calcLCD();
00137 for( it_cn = m_connList.begin() ; it_cn != m_connList.end(); ++it_cn)
00138 {
00139 if ( (*it_cn)->isToBeEx())
00140 {
00141 (*it_cn)->createEndGetters();
00142 (*it_cn)->prepare();
00143
00144
00145 m_visitor.addEntity( Any::CONN, ClassAndNamespace::makeIt(*it_cn));
00146 }
00147 }
00148 }}
00149
00150
00151 {
00152 std::vector<FolderRep*>::const_iterator it_b = m_folderList.begin();
00153 if ( it_b != m_folderList.end())
00154 for( ; it_b != m_folderList.end(); ++it_b)
00155 {
00156 if ( (*it_b)->isToBeEx())
00157 {
00158 (*it_b)->prepare();
00159 (*it_b)->createMethods();
00160
00161 m_visitor.addEntity( Any::FOLDER, ClassAndNamespace::makeIt(*it_b));
00162 }
00163 }
00164 }
00165
00166 {
00167 std::vector<FcoRep*>::const_iterator it_b = m_fcoRepList.begin();
00168 if ( it_b != m_fcoRepList.end())
00169 for( ; it_b != m_fcoRepList.end(); ++it_b)
00170 {
00171 if ( (*it_b)->isToBeEx())
00172 {
00173 (*it_b)->prepare();
00174
00175
00176 m_visitor.addEntity( Any::FCO_REP, ClassAndNamespace::makeIt(*it_b));
00177 }
00178 }
00179 }
00180
00181
00182 {
00183 std::vector<AtomRep*>::const_iterator it_b = m_atomList.begin();
00184 if ( it_b != m_atomList.end())
00185 for( ; it_b != m_atomList.end(); ++it_b)
00186 {
00187 if ( (*it_b)->isToBeEx())
00188 {
00189
00190 (*it_b)->prepare();
00191
00192
00193 m_visitor.addEntity( Any::ATOM, ClassAndNamespace::makeIt(*it_b));
00194 }
00195 }
00196 }
00197
00198
00199 {
00200 std::vector<SetRep*>::const_iterator it_c = m_setList.begin();
00201 if ( it_c != m_setList.end())
00202 for( ; it_c != m_setList.end(); ++it_c)
00203 {
00204 if ( (*it_c)->isToBeEx())
00205 {
00206 (*it_c)->prepare();
00207 (*it_c)->createMethods();
00208
00209
00210 m_visitor.addEntity( Any::SET, ClassAndNamespace::makeIt(*it_c));
00211 }
00212 }
00213 }
00214
00215
00216 {
00217 std::vector<ReferenceRep*>::const_iterator it_ref = m_refList.begin();
00218 if ( it_ref != m_refList.end())
00219 for( ; it_ref != m_refList.end(); ++it_ref)
00220 {
00221 if ( (*it_ref)->isToBeEx())
00222 {
00223 (*it_ref)->prepare();
00224 (*it_ref)->createMethods();
00225
00226
00227 m_visitor.addEntity( Any::REF, ClassAndNamespace::makeIt(*it_ref));
00228 }
00229 }
00230 }
00231
00232
00233 {
00234 std::vector<ModelRep*>::const_iterator it_m = m_modelList.begin();
00235 if ( it_m != m_modelList.end())
00236 for( ; it_m != m_modelList.end(); ++it_m)
00237 {
00238 if ( (*it_m)->isToBeEx())
00239 {
00240 (*it_m)->prepare();
00241 (*it_m)->createMethods();
00242
00243
00244 m_visitor.addEntity( Any::MODEL, ClassAndNamespace::makeIt(*it_m));
00245 }
00246 }
00247 }
00248
00249 if ( m_bGenVisitor)
00250 {
00251 std::ofstream visitorh( global_vars.m_visitorHeaderFileName.c_str());
00252 std::ofstream visitors( global_vars.m_visitorSourceFileName.c_str());
00253
00254 std::string mmm = m_visitor.dumpVisitorHeader();
00255 visitorh.write( mmm.c_str(), mmm.length());
00256
00257 std::string nnn = m_visitor.dumpVisitorSource();
00258 visitors.write( nnn.c_str(), nnn.length());
00259
00260 visitorh.close();
00261 visitors.close();
00262 }
00263 }
00264
00265
00266 void Dumper::dumpGlobals( std::vector<FCO*>& s)
00267 {
00268 {
00269 std::vector<FolderRep*>::const_iterator it_b = m_folderList.begin();
00270 for( ; it_b != m_folderList.end(); ++it_b)
00271 if ( (*it_b)->isToBeEx())
00272 (*it_b)->dumpGlobals();
00273 }
00274
00275 std::vector<FCO*>::iterator it = s.begin();
00276 for( ; it != s.end(); ++it)
00277 {
00278 if ( (*it)->isToBeEx())
00279 (*it)->dumpGlobals();
00280 }
00281 }
00282
00283
00284 void Dumper::dumpMain( std::vector<FCO*>& s)
00285 {
00286
00287 {
00288 std::vector<FolderRep*>::const_iterator it_b = m_folderList.begin();
00289 if ( it_b != m_folderList.end())
00290 for( ; it_b != m_folderList.end(); ++it_b)
00291 if ( (*it_b)->isToBeEx())
00292 (*it_b)->doDump();
00293 }
00294
00295 std::vector<FCO*>::iterator it = s.begin();
00296 for( ; it != s.end(); ++it)
00297 {
00298 if ( (*it)->isToBeEx())
00299 (*it)->doDump();
00300 }
00301 }
00302
00303 void Dumper::dumpGlobalMOF()
00304 {
00305 std::string res;
00306
00307 std::set<BON::Model>::iterator it = m_setOfParadigmSheets2.begin();
00308 for( ; it != m_setOfParadigmSheets2.end(); ++it)
00309 {
00310 BON::RegistryNode rn = (*it)->getRegistry();
00311 if( rn)
00312 res += Any::processMOFNode( rn, 1);
00313
00314 }
00315
00316 if( !res.empty())
00317 {
00318 DMP_H( "// Global " + Any::MOFStart_str + "\n\n");
00319 DMP_H( res);
00320 DMP_H( "// Global " + Any::MOFEnd_str + "\n\n\n");
00321 }
00322 }
00323
00324 void Dumper::initOutFiles( std::vector<FCO*>& s, std::string& resu)
00325 {
00326 if( global_vars.m_outputMethod == Globals::PERCLASS)
00327 {
00328
00329
00330 std::vector<FolderRep*>::const_iterator it_b = m_folderList.begin();
00331 for( ; it_b != m_folderList.end(); ++it_b)
00332 if ( (*it_b)->isToBeEx())
00333 {
00334 (*it_b)->makeBackup();
00335 }
00336
00337 std::vector<FCO*>::iterator it = s.begin();
00338 for( ; it != s.end(); ++it)
00339 if ( (*it)->isToBeEx())
00340 {
00341 (*it)->makeBackup();
00342 }
00343
00344 {
00345 std::vector<FolderRep*>::const_iterator it_b = m_folderList.begin();
00346 for( ; it_b != m_folderList.end(); ++it_b)
00347 if ( (*it_b)->isToBeEx())
00348 {
00349 (*it_b)->initOutH( resu);
00350 (*it_b)->initOutS();
00351 }
00352 }
00353
00354 {
00355 std::vector<FCO*>::iterator it = s.begin();
00356 for( ; it != s.end(); ++it)
00357 if ( (*it)->isToBeEx())
00358 {
00359 (*it)->initOutH( resu);
00360 (*it)->initOutS();
00361 }
00362 }
00363 }
00364 }
00365
00366 void Dumper::finiOutFiles( std::vector<FCO*>& s)
00367 {
00368 {
00369 std::vector<FolderRep*>::const_iterator it_b = m_folderList.begin();
00370 for( ; it_b != m_folderList.end(); ++it_b)
00371 if ( (*it_b)->isToBeEx())
00372 {
00373 (*it_b)->finiOutH();
00374 (*it_b)->finiOutS();
00375 }
00376 }
00377
00378 {
00379 std::vector<FCO*>::iterator it = s.begin();
00380 for( ; it != s.end(); ++it)
00381 if ( (*it)->isToBeEx())
00382 {
00383 (*it)->finiOutH();
00384 (*it)->finiOutS();
00385 }
00386 }
00387 }
00388
00389
00390 void Dumper::doDump()
00391 {
00392 AnyLexicographicSort lex;
00393 std::sort( m_folderList.begin(), m_folderList.end(), lex );
00394 std::sort( m_fcoRepList.begin(), m_fcoRepList.end(), lex );
00395 std::sort( m_atomList.begin(), m_atomList.end(), lex );
00396 std::sort( m_refList.begin(), m_refList.end(), lex );
00397 std::sort( m_connList.begin(), m_connList.end(), lex );
00398 std::sort( m_setList.begin(), m_setList.end(), lex );
00399 std::sort( m_modelList.begin(), m_modelList.end(), lex );
00400
00401
00402 std::vector<FCO*> sorted = sortBasedOnLevels();
00403
00404 selConf( sorted);
00405
00406 CWaitCursor w;
00407
00408 std::string short_name_header_file = shortFileName( global_vars.header_file_name);
00409 std::string capitalized = capitalizeString( cutExtension( short_name_header_file));
00410
00411 std::string global_user_part1, global_user_part2;
00412 Dumper::getGlobalUserParts( global_user_part1, global_user_part2);
00413
00414 std::string global_includes;
00415 initOutFiles( sorted, global_includes);
00416
00417 DMP_S("#include \"stdafx.h\"\n");
00418 DMP_S("#include \"" + short_name_header_file + "\"\n");
00419 if( Dumper::m_bGenAcceptSpeci)
00420 DMP_S("#include \"" + shortFileName( global_vars.m_visitorHeaderFileName) + "\"\n");
00421 DMP_S("\n");
00422
00423
00424
00425 DMP_H("#ifndef " + capitalized + "_H\n");
00426 DMP_H("#define " + capitalized + "_H\n\n");
00427 DMP_H("#include \"BON.h\"\n#include \"BONImpl.h\"\n#include \"Extensions.h\"\n\n");
00428
00429 if ( m_bGenTemplates)
00430 {
00431 DMP_H("//\n");
00432 DMP_H("// this dummy template parameter is needed by VC6 to deduct the return type\n");
00433 DMP_H("// VC7 users can modify this macro to a value like \"int _dummy = 0\"\n");
00434 DMP_H("// TDP standing for TEMPLATE DUMMY PAR\n");
00435
00436 if ( m_bGenTemplVersion6)
00437 {
00438 DMP_H("//#define TDP int _dummy = 0 // recommended for VC7 users\n");
00439 DMP_H("#define TDP const T & _dummyComp // recommended for VC6 users\n");
00440 }
00441 else
00442 {
00443 DMP_H("#define TDP int _dummy = 0 // recommended for VC7 users\n");
00444 DMP_H("//#define TDP const T & _dummyComp // recommended for VC6 users\n");
00445 }
00446 DMP_H("\n// sample less-than comparator (functor)\n");
00447 DMP_H("// class Lt { public: bool operator()( const BON::Object& x, const BON::Object& y) { return x->getName().compare( y->getName()) < 0; } };\n");
00448 DMP_H("// can be used as follows\n");
00449 DMP_H("// std::set< MyObj, Lt > myObjs = c->getMyObj( Lt()); // in VC6\n");
00450 DMP_H("// std::set< MyObj, Lt > myObjs = c->getMyObj(); // in VC7.1 and above\n");
00451 DMP_H("// beware: must be a partial ordering (implemented like a 'less than') having the following three properties: \n");
00452 DMP_H("// A) x < y => !(y < x), B) x < x must be false C) x < y && y < z => x < z\n");
00453
00454
00455 DMP_H("\n");
00456 }
00457
00458 DMP_H( Any::m_startUPToken + "\n" + global_user_part1 + Any::m_endUPToken + "\n\n");
00459
00460
00461
00462
00463 if( Dumper::m_bGenAcceptSpeci)
00464 DMP_H("namespace " + global_vars.m_namespace_name + " { class " + MakeVisitor::getVisitorName( m_validProjName) + "; }\n");
00465
00466 DMP_S("\nnamespace BON\n{\n\n");
00467
00468
00469
00470
00471
00472 createMethods();
00473 dumpGlobals( sorted);
00474
00475 DMP_H("\n\n");
00476
00477 if( !global_includes.empty())
00478 {
00479 DMP_H( global_includes);
00480 DMP_H( "\n");
00481 }
00482
00483 if( Dumper::m_bGenAcceptSpeci)
00484 DMP_H( "#include \"" + shortFileName( global_vars.m_visitorHeaderFileName) + "\"\n\n");
00485
00486
00487
00488
00489
00490 DMP_S("\n\n} // namespace BON\n\n");
00491
00492
00493
00494
00495 dumpGlobalMOF();
00496
00497 dumpMain( sorted);
00498
00499
00500
00501
00502 DMP_H( Any::m_startUPToken + "\n" + global_user_part2 + Any::m_endUPToken + "\n\n");
00503
00504 DMP_H("#endif // " + capitalized + "_H\n");
00505
00506
00507
00508 finiOutFiles( sorted);
00509 }
00510
00511
00512 void Dumper::showMultipleInheritance()
00513 {
00514 FcoRep_Iterator it0( m_fcoRepList.begin());
00515 for( ; it0 != m_fcoRepList.end(); ++it0 )
00516 {
00517 (*it0)->showMultipleInheritance();
00518 }
00519
00520 AtomRep_Iterator it1 = m_atomList.begin();
00521 for( ; it1 != m_atomList.end(); ++it1 )
00522 {
00523 (*it1)->showMultipleInheritance();
00524 }
00525
00526 ModelRep_Iterator it2 = m_modelList.begin();
00527 for( ; it2 != m_modelList.end(); ++it2 )
00528 {
00529 (*it2)->showMultipleInheritance();
00530 }
00531
00532 ConnectionRep_Iterator it3 = m_connList.begin();
00533 for( ; it3 != m_connList.end(); ++it3 )
00534 {
00535 (*it3)->showMultipleInheritance();
00536 }
00537
00538 SetRep_Iterator it4 = m_setList.begin();
00539 for( ; it4 != m_setList.end(); ++it4 )
00540 {
00541 (*it4)->showMultipleInheritance();
00542 }
00543
00544 ReferenceRep_Iterator it5 = m_refList.begin();
00545 for( ; it5 != m_refList.end(); ++it5 )
00546 {
00547 (*it5)->showMultipleInheritance();
00548 }
00549 }
00550
00551
00552 void Dumper::fetchConfigurationNames( std::vector< std::string>& res)
00553 {
00554 BON::RegistryNode rn = m_BON_Project_Root_Folder2->getRegistry()->getChild("BonExtender/SavedConfigurations");
00555 if ( rn)
00556 {
00557 std::set<BON::RegistryNode> ch = rn->getChildren();
00558 std::set<BON::RegistryNode>::iterator i = ch.begin();
00559 for( ; i != ch.end(); ++i)
00560 {
00561 std::string one_config( (*i)->getName());
00562
00563 if ( (*i)->getIntegerValue() == 1
00564 && std::find( res.begin(), res.end(), one_config) == res.end())
00565 res.push_back( one_config);
00566 }
00567 }
00568 }
00569
00570
00571 void Dumper::selConf( std::vector<FCO*>& s)
00572 {
00573 CWaitCursor wait;
00574 std::vector< std::string > tmp,vec;
00575 fetchConfigurationNames( tmp);
00576 if ( std::find( tmp.begin(), tmp.end(), "Default") == tmp.end())
00577 vec.push_back( "Default");
00578 vec.insert( vec.end(), tmp.begin(), tmp.end());
00579
00580 SelConf sc( vec.size());
00581 sc.addConfigs( vec);
00582
00583 int last_id;
00584 for( std::vector<FolderRep*>::const_iterator it_b = m_folderList.begin(); it_b != m_folderList.end(); ++it_b)
00585 {
00586 CString name = (*it_b)->getLStrictName().c_str();
00587 std::string regVal = (*it_b)->getMyRegistry()->getValueByPath( "/Configs/Default");
00588
00589 if( global_vars.silent_mode)
00590 (*it_b)->toBeEx( regVal != "false");
00591 else
00592 last_id = sc.addEntry( name, 'f', 0, regVal != "false", "", *it_b);
00593 }
00594
00595 for( std::vector< FCO *>::iterator it = s.begin(); it != s.end(); ++it)
00596 {
00597 CString name = (*it)->getLStrictName().c_str();
00598 const char kinds[] = "AMCSRF f";
00599 char kind = ' ';
00600 if( (int) (*it)->getMyKind() < sizeof(kinds)/sizeof(char))
00601 kind = kinds[(int) (*it)->getMyKind()];
00602 int clique = (*it)->getCliqueId( FCO::INTERFACE);
00603 std::string regVal = (*it)->getMyRegistry()->getValueByPath( "/Configs/Default");
00604 std::string rspVal = (*it)->getMyRegistry()->getValueByPath( "/Configs/Default/Resp");
00605 FCO* resp_ptr = (*it)->findRspPtr( rspVal);
00606 if( !resp_ptr)
00607 {
00608 rspVal = "";
00609 (*it)->getMyRegistry()->setValueByPath( "/Configs/Default/Resp", rspVal);
00610 }
00611
00612 if( global_vars.silent_mode)
00613 {
00614 (*it)->toBeEx( regVal != "false");
00615 (*it)->setExtedAnc( resp_ptr);
00616 }
00617 else
00618 {
00619 last_id = sc.addEntry( name, kind, clique, regVal != "false", rspVal.c_str(), *it);
00620 }
00621 }
00622
00623 if ( !global_vars.silent_mode && sc.DoModal() == IDOK)
00624 {
00625 wait.Restore();
00626 if ( sc.m_currSelConfigStr != "Default")
00627 {
00628 std::string path = "/BonExtender/SavedConfigurations/" + sc.m_currSelConfigStr;
00629 m_BON_Project_Root_Folder2->getRegistry()->setValueByPath( path, "1");
00630 }
00631 }
00632 }
00633
00634
00635 bool Dumper::build()
00636 {
00637 inheritMoReSeCoFolAsp();
00638
00639
00640 doDump();
00641
00642 return true;
00643 }
00644
00645
00646 int Dumper::backup( const std::string& file_name)
00647 {
00648 if ( existsFile( file_name.c_str()))
00649 {
00650 std::string backup = file_name + ".bak";
00651 int res = makeFileCopy( file_name.c_str(), backup.c_str());
00652 if ( res == 2)
00653 {
00654 TO("Could not read file during backup process: " + file_name);
00655 return 2;
00656 }
00657 else if ( res == 3)
00658 {
00659 TO("Cannot create backup file: " + backup);
00660 return 3;
00661 }
00662 }
00663 return 1;
00664 }
00665
00666
00667 int Dumper::selectOutputFiles( const std::string& proj_name_to_be_checked, BON::RegistryNode& optRn)
00668 {
00669 std::string proj_name = proj_name_to_be_checked;
00670 Any::convertToValidName( proj_name);
00671
00672 if( global_vars.m_namespace_name.empty())
00673 global_vars.m_namespace_name = proj_name + "_BON";
00674
00675
00676 global_vars.header_file_name = proj_name + "BonX.h";;
00677 global_vars.source_file_name = proj_name + "BonX.cpp";
00678 global_vars.m_visitorHeaderFileName = proj_name + "Visitor.h";
00679 global_vars.m_visitorSourceFileName = proj_name + "Visitor.cpp";
00680 global_vars.header_backup_name = "";
00681
00682
00683
00684 std::string _visitor = optRn->getChild( Dumper::m_strGenVisitor)->getValue();
00685 std::string _vissign = optRn->getChild( Dumper::m_strVisitorSignature)->getValue();
00686 std::string _initmtd = optRn->getChild( Dumper::m_strGenInitMethod)->getValue();
00687 std::string _finimtd = optRn->getChild( Dumper::m_strGenFiniMethod)->getValue();
00688 std::string _acceptT = optRn->getChild( Dumper::m_strGenAcceptWithTraversal)->getValue();
00689 std::string _acceptS = optRn->getChild( Dumper::m_strGenAcceptSpecialized)->getValue();
00690 std::string _acSRetV = optRn->getChild( Dumper::m_strSpecAcceptRetVal)->getValue();
00691 std::string _vcVers6 = optRn->getChild( Dumper::m_strVCVersion6)->getValue();
00692 std::string _templGt = optRn->getChild( Dumper::m_strTemplateGetter)->getValue();
00693 std::string _outSepF = optRn->getChild( Dumper::m_strOutputInSeparateFile)->getValue();
00694 std::string _tgtNmsp = optRn->getChild( Dumper::m_strTgtNamespace)->getValue();
00695
00696
00697 m_bGenVisitor = _visitor == Yes_Str;
00698 m_iVisitSign = _vissign == "1"? 1 : 0;
00699 m_bGenInit = _initmtd == Yes_Str;
00700 m_bGenFinalize = _finimtd == Yes_Str;
00701 m_bGenAcceptTrave = _acceptT == Yes_Str;
00702 m_bGenAcceptSpeci = _acceptS == Yes_Str;
00703 m_iSpecAcceptRetVal = _acSRetV == "1"? 1 : 0;
00704 m_bGenTemplVersion6 = _vcVers6 == Yes_Str;
00705 if( _templGt == Yes_Str) { m_bGenTemplates = TRUE; m_bGenRegular = TRUE; }
00706 else if( _templGt == Only_Str) { m_bGenTemplates = TRUE; m_bGenRegular = FALSE; }
00707 else { m_bGenTemplates = FALSE; m_bGenRegular = TRUE; }
00708 global_vars.m_outputMethod = _outSepF == Yes_Str ? Globals::PERCLASS : Globals::ALLTOGETHER;
00709 global_vars.m_namespace_name = _tgtNmsp.empty() ? global_vars.m_namespace_name : _tgtNmsp;
00710
00711 if( !global_vars.silent_mode)
00712 {
00713 OptionsDlg opt;
00714
00715 opt.m_headerName = global_vars.header_file_name.c_str();
00716 opt.m_sourceName = global_vars.source_file_name.c_str();
00717 opt.m_visitorHeaderName = global_vars.m_visitorHeaderFileName.c_str();
00718 opt.m_visitorSourceName = global_vars.m_visitorSourceFileName.c_str();
00719 opt.m_prevHeaderName = opt.m_headerName + ".bak";
00720
00721
00722 opt.m_bVisitor = m_bGenVisitor;
00723 opt.m_visitorSignature = m_iVisitSign;
00724 opt.m_bInit = m_bGenInit;
00725 opt.m_bFinalize = m_bGenFinalize;
00726 opt.m_bAcceptTrave = m_bGenAcceptTrave;
00727 opt.m_bAcceptSpeci = m_bGenAcceptSpeci;
00728 opt.m_specAcceptRetVal = m_iSpecAcceptRetVal;
00729 opt.m_version60 = m_bGenTemplVersion6;
00730 opt.m_whichStyle = m_bGenRegular && m_bGenTemplates ? 2 : m_bGenTemplates?1:0;
00731 opt.m_methodOfOutput = global_vars.m_outputMethod == Globals::PERCLASS ? 1 : 0;
00732 opt.m_namespaceName = global_vars.m_namespace_name.c_str();
00733
00734 if ( opt.DoModal() != IDOK) return 2;
00735
00736 m_bParsePrev = opt.m_bParse == TRUE;
00737 m_bGenVisitor = opt.m_bVisitor == TRUE;
00738 m_iVisitSign = opt.m_visitorSignature;
00739 m_bGenInit = opt.m_bInit == TRUE;
00740 m_bGenFinalize = opt.m_bFinalize == TRUE;
00741 m_bGenAcceptTrave = opt.m_bAcceptTrave == TRUE;
00742 m_bGenAcceptSpeci = opt.m_bAcceptSpeci == TRUE;
00743 m_iSpecAcceptRetVal = opt.m_specAcceptRetVal;
00744 m_bGenTemplVersion6 = opt.m_version60 == TRUE;
00745 m_bGenRegular = opt.m_whichStyle != 1;
00746 m_bGenTemplates = opt.m_whichStyle > 0;
00747
00748 global_vars.m_outputMethod = opt.m_methodOfOutput == 0 ? Globals::ALLTOGETHER: Globals::PERCLASS;
00749 global_vars.m_namespace_name = opt.m_namespaceName.IsEmpty() ? "std" : (LPCTSTR) opt.m_namespaceName;
00750
00751
00752 optRn->getChild( Dumper::m_strGenVisitor )->setValue( m_bGenVisitor ? Yes_Str : No_Str);
00753 optRn->getChild( Dumper::m_strVisitorSignature )->setValue( m_iVisitSign == 1 ? "1" : "0");
00754 optRn->getChild( Dumper::m_strGenInitMethod )->setValue( m_bGenInit ? Yes_Str : No_Str);
00755 optRn->getChild( Dumper::m_strGenFiniMethod )->setValue( m_bGenFinalize ? Yes_Str : No_Str);
00756 optRn->getChild( Dumper::m_strGenAcceptWithTraversal)->setValue( m_bGenAcceptTrave ? Yes_Str : No_Str);
00757 optRn->getChild( Dumper::m_strGenAcceptSpecialized )->setValue( m_bGenAcceptSpeci ? Yes_Str : No_Str);
00758 optRn->getChild( Dumper::m_strSpecAcceptRetVal )->setValue( m_iSpecAcceptRetVal == 1 ? "1" : "0");
00759 optRn->getChild( Dumper::m_strVCVersion6 )->setValue( m_bGenTemplVersion6 ? Yes_Str : No_Str);
00760 optRn->getChild( Dumper::m_strTemplateGetter )->setValue( m_bGenTemplates && m_bGenRegular ? Yes_Str : m_bGenTemplates ? Only_Str : No_Str);
00761 optRn->getChild( Dumper::m_strOutputInSeparateFile )->setValue( global_vars.m_outputMethod == Globals::PERCLASS ? Yes_Str : No_Str);
00762 optRn->getChild( Dumper::m_strTgtNamespace )->setValue( global_vars.m_namespace_name);
00763
00764 global_vars.output_directory_name = "";
00765 int i = opt.m_headerName.ReverseFind('\\');
00766 if ( i != -1)
00767 {
00768 global_vars.output_directory_name = opt.m_headerName.Left( i+1);
00769 }
00770
00771 global_vars.header_file_name = opt.m_headerName;
00772 global_vars.source_file_name = opt.m_sourceName;
00773 global_vars.err_file_name = global_vars.output_directory_name + proj_name + "BONExt.log";
00774
00775 if (m_bGenVisitor)
00776 {
00777 global_vars.m_visitorHeaderFileName = opt.m_visitorHeaderName;
00778 global_vars.m_visitorSourceFileName = opt.m_visitorSourceName;
00779 }
00780
00781 global_vars.header_backup_name = "";
00782 if ( m_bParsePrev)
00783 {
00784 if ( existsFile( (LPCTSTR) opt.m_prevHeaderName))
00785 global_vars.header_backup_name = opt.m_prevHeaderName;
00786 else
00787 TO( opt.m_prevHeaderName + " previously generated header file not found.");
00788 }
00789
00790 }
00791
00792 m_bSafetyBackup = true;
00793 if ( m_bSafetyBackup)
00794 {
00795 int res1( 1), res2( 1), res3( 1), res4( 1);
00796 res1 = backup( global_vars.header_file_name);
00797 res2 = backup( global_vars.source_file_name);
00798
00799 if ( m_bGenVisitor)
00800 {
00801 res3 = backup( global_vars.m_visitorHeaderFileName);
00802 res4 = backup( global_vars.m_visitorSourceFileName);
00803 }
00804 if ( res1 != 1 || res2 != 1 || res3 != 1 || res4 != 1)
00805 return 2;
00806 }
00807
00808 return 1;
00809 }
00810
00811 void Dumper::getGlobalUserParts( std::string& up1, std::string& up2)
00812 {
00813 std::ifstream old_xmp_file;
00814 std::string old_f_name;
00815 old_f_name = global_vars.header_backup_name;
00816 if ( old_f_name.empty())
00817 {
00818 up1 = "// add your include files/class definitions here\n";
00819 up2 = "// add your additional class definitions here\n";
00820 return;
00821 }
00822
00823 old_xmp_file.open( old_f_name.c_str() ,std::ios_base::in);
00824 if ( !old_xmp_file.is_open())
00825 {
00826 up1 = "// ERROR accessing file\n";
00827 up2 = "// ERROR accessing file\n";
00828 return;
00829 }
00830
00831 std::string line;
00832 while( !old_xmp_file.eof() && line.substr(0, Any::m_startUPToken.length()) != Any::m_startUPToken)
00833 {
00834 std::getline( old_xmp_file, line);
00835 }
00836 if ( !old_xmp_file.eof())
00837 {
00838 std::getline( old_xmp_file, line);
00839 while( !old_xmp_file.eof() && line.substr( 0, Any::m_endUPToken.length()) != Any::m_endUPToken)
00840 {
00841 up1 += line + "\n";
00842 std::getline( old_xmp_file, line);
00843 }
00844 if ( !old_xmp_file.eof())
00845 {
00846 }
00847 else
00848 {
00849 old_xmp_file.close();
00850 up1 = "// Ending token (" + Any::m_endUPToken + ") for first global user part not found\n";
00851 up2 = "// Error in first global user part\n";
00852 return;
00853 }
00854 }
00855 else
00856 {
00857 old_xmp_file.close();
00858 up1 = "// Starting token (" + Any::m_startUPToken + ") for first global user part not found\n";
00859 up2 = "// Error in first global user part\n";
00860 return;
00861 }
00862
00863 while( !old_xmp_file.eof() && line.substr(0, Any::m_startUPToken.length()) != Any::m_startUPToken)
00864 {
00865 std::getline( old_xmp_file, line);
00866 }
00867 if ( !old_xmp_file.eof())
00868 {
00869 std::getline( old_xmp_file, line);
00870 while( !old_xmp_file.eof() && line.substr( 0, Any::m_endUPToken.length()) != Any::m_endUPToken)
00871 {
00872 up2 += line + "\n";
00873 std::getline( old_xmp_file, line);
00874 }
00875 if ( !old_xmp_file.eof())
00876 {
00877 }
00878 else
00879 {
00880 old_xmp_file.close();
00881 up2 = "// Ending token (" + Any::m_endUPToken + ") for second global user part not found\n";
00882 return;
00883 }
00884 }
00885 else
00886 {
00887 old_xmp_file.close();
00888 up2 = "// Starting token (" + Any::m_startUPToken + ") for second global user part not found\n";
00889 return;
00890 }
00891
00892 old_xmp_file.close();
00893 return;
00894 }
00895
00896
00897 std::string Dumper::xmlFilter( const std::string& in)
00898 {
00899 std::map<char, std::string> m;
00900 m['&'] = "&";
00901 m['>'] = ">";
00902 m['<'] = "<";
00903 m['"'] = """;
00904 m['\''] = "'";
00905
00906 std::string ret;
00907 for( std::string::const_iterator i = in.begin(); i != in.end(); ++i)
00908 if ( m.find( *i) != m.end())
00909 ret += m[*i];
00910 else
00911 ret += *i;
00912
00913 return ret;
00914 }