00001 #include "stdafx.h"
00002
00003 #include "BON.h"
00004 #include "BONImpl.h"
00005
00006 #include "Any.h"
00007 #include "CodeGen.h"
00008 #include "Method.h"
00009 #include "Dumper.h"
00010 #include "MakeVisitor.h"
00011
00012 #include "algorithm"
00013 #include "strstream"
00014
00015 #include "globals.h"
00016 extern Globals global_vars;
00017
00018 const std::string Any::m_startUPToken = "///BUP";
00019 const std::string Any::m_endUPToken = "///EUP";
00020 const std::string Any::NamespaceDispSeparatorBeg_str = "_";
00021 const std::string Any::NamespaceDispSeparatorEnd_str = "_";
00022 const std::string Any::NamespaceDelimiter_str = "::";
00023 const std::string Any::InRootFolder_str = "InRootFolder";
00024 const std::string Any::NameSelectorNode_str = "myNameIs";
00025 const std::string Any::MOFException_str = "MOFException";
00026 const std::string Any::MOFOperation_str = "MOFOperation";
00027 const std::string Any::MOFEnumeration_str = "MOFEnumeration";
00028 const std::string Any::MOFStructure_str = "MOFStructure";
00029 const std::string Any::MOFAlias_str = "MOFAlias";
00030
00031 const std::string Any::MOFStart_str = "MOF section begins";
00032 const std::string Any::MOFEnd_str = "MOF section ends";
00033
00034
00035
00036 bool AnyLexicographicSort::operator()( Any * op1, Any * op2) const
00037 {
00038 std::string s1 = op1->getName();
00039 std::string s2 = op2->getName();
00040 int k = s1.compare(s2);
00041
00042 return ( k < 0);
00043 }
00044
00045
00046
00047
00048 const std::string Any::KIND_TYPE_STR[] =
00049 {
00050 "Atom",
00051 "Model",
00052 "Connection",
00053 "Set",
00054 "Reference",
00055 "FCO",
00056 "ASPECT",
00057 "Folder",
00058 "CONSTRAINT",
00059 "CONSTRAINFUNC",
00060 "ATTRIBUTE"
00061 };
00062
00063
00064 Any::Any( BON::FCO& ptr)
00065 : m_ptr( ptr)
00066 , m_isInRootFolder( false)
00067 , m_equivs()
00068 , m_toEx( true)
00069 , m_globalHeader()
00070 , m_globalSource()
00071 {
00072 }
00073
00074
00075 Any::~Any()
00076 {
00077 m_equivs.clear();
00078 }
00079
00080 void Any::initNamespace()
00081 {
00082
00083 if( m_ptr->isInLibrary())
00084 {
00085 bool all_equivs_in_lib = true;
00086 for ( std::set< BON::FCO >::const_iterator it = m_equivs.begin()
00087 ; all_equivs_in_lib && it != m_equivs.end()
00088 ; ++it)
00089 {
00090 if ( *it == m_ptr) continue;
00091 if ((*it)->getObjectMeta().name().find("Proxy") != std::string::npos) continue;
00092 all_equivs_in_lib = (*it)->isInLibrary();
00093 }
00094
00095 if( !all_equivs_in_lib)
00096 resetNamespace();
00097 else
00098 {
00099
00100
00101 BON::RegistryNode rn = m_nmspRootFolder->getRegistry()->getChild( "Namespace");
00102
00103 if( rn) m_namespace = rn->getValue();
00104 else m_namespace = "";
00105
00106 }
00107 }
00108 else
00109 {
00110 resetNamespace();
00111 }
00112 }
00113
00114 void Any::resetNamespace()
00115 {
00116 m_namespace = Dumper::getInstance()->getNamespace();
00117 }
00118
00119
00120 void Any::initAttributes()
00121 {
00122
00123
00124
00125 m_isInRootFolder = m_ptr->getAttribute( InRootFolder_str)->getBooleanValue();
00126
00127 std::set< BON::FCO >::const_iterator it = m_equivs.begin();
00128 for ( ; !m_isInRootFolder && it != m_equivs.end(); ++it)
00129 {
00130 if ( *it == m_ptr) continue;
00131 if ((*it)->getObjectMeta().name().find("Proxy") != std::string::npos) continue;
00132 m_isInRootFolder = m_isInRootFolder || (*it)->getAttribute( InRootFolder_str)->getBooleanValue();
00133 }
00134 }
00135
00136
00137 bool Any::isInRootFolder()
00138 {
00139 return m_isInRootFolder;
00140 }
00141
00142 bool Any::isToBeEx() const
00143 {
00144 return m_toEx;
00145 }
00146
00147
00148 void Any::toBeEx( bool t)
00149 {
00150 m_toEx = t;
00151 }
00152
00153
00154 bool Any::isFCO() const
00155 {
00156 bool fco = false;
00157 fco = (getMyKind() == ATOM ||
00158 getMyKind() == MODEL ||
00159 getMyKind() == CONN ||
00160 getMyKind() == SET ||
00161 getMyKind() == REF ||
00162 getMyKind() == FCO_REP);
00163 return fco;
00164 }
00165
00166
00167 std::string Any::getName() const
00168 {
00169 if ( this->m_ptr)
00170 {
00171 return m_ptr->getName();
00172 }
00173 return "NullPtrError";
00174 }
00175
00176
00177 std::string Any::getValidName() const
00178 {
00179 if ( this->m_ptr)
00180 {
00181 std::string nm = getName();
00182 Any::convertToValidName( nm);
00183 return nm;
00184 }
00185 return "NullPtrError";
00186 }
00187
00188 std::string Any::getStrictNmspc() const
00189 {
00190 return m_namespace.empty()?"": m_namespace;
00191 }
00192
00193 std::string Any::getLStrictNmspc() const
00194 {
00195 return m_namespace.empty()?"": (m_namespace + Any::NamespaceDelimiter_str);
00196 }
00197
00198 std::string Any::getNmspc() const
00199 {
00200
00201
00202 return m_namespace.empty()?global_vars.m_namespace_name: m_namespace;
00203 }
00204
00205 std::string Any::getLNmspc() const
00206 {
00207 std::string t = getNmspc();
00208 Any::convertToValidName( t);
00209 return t + Any::NamespaceDelimiter_str;
00210 }
00211
00212 std::string Any::getValidNmspc() const
00213 {
00214
00215 std::string t = getNmspc();
00216 Any::convertToValidName( t);
00217 return t;
00218 }
00219
00220 std::string Any::getLStrictName() const
00221 {
00222 return getLStrictNmspc() + getName();
00223 }
00224
00225 std::string Any::getLName() const
00226 {
00227 return getLNmspc() + getName();
00228 }
00229
00230 std::string Any::getLValidNmspc() const
00231 {
00232 std::string t = getValidNmspc();
00233 return t.empty()?"": t + Any::NamespaceDelimiter_str;
00234 }
00235
00236 std::string Any::getLValidName() const
00237 {
00238 return getLValidNmspc() + getValidName();
00239 }
00240
00241 std::string Any::getValidNameImpl() const
00242 {
00243 return getValidName() + "Impl";
00244 }
00245
00246 std::string Any::getLValidNameImpl() const
00247 {
00248 return getLValidNmspc() + getValidNameImpl();
00249 }
00250
00251 std::string Any::getMyKindStr() const
00252 {
00253 if ( isFCO() || getMyKind() == FOLDER)
00254 return KIND_TYPE_STR[ getMyKind()];
00255
00256 throw "Error: inquireing getMyKindStr for non-fco, non-folder";
00257 }
00258
00259
00260 void Any::convertToValidName( std::string & p)
00261 {
00262 for(int i = 0; i < p.length(); ++i)
00263 if( (p[i]>='a' && p[i]<='z') ||
00264 (p[i]>='A' && p[i]<='Z') ||
00265 (p[i]>='0' && p[i]<='9') ||
00266 (p[i]=='_'))
00267 {}
00268 else
00269 p[i]= '_';
00270
00271 if (p[0]>='0' && p[0]<='9')
00272 p = '_' + p;
00273 }
00274
00275
00276 bool Any::checkIfValidName( const std::string & p)
00277 {
00278 std::strstream error_msg;
00279
00280 bool more_than_one = false;
00281 bool good = true;
00282 if (( p[0] >='a' && p[0]<='z')
00283 || ( p[0] >='A' && p[0]<='Z')
00284 || ( p[0] == '_'))
00285 {}
00286 else
00287 {
00288 good = false;
00289
00290 error_msg << "0";
00291 more_than_one = true;
00292 }
00293
00294 for(int i = 1; i < p.length(); ++i)
00295 {
00296 if( (p[i]>='a' && p[i]<='z') ||
00297 (p[i]>='A' && p[i]<='Z') ||
00298 (p[i]>='0' && p[i]<='9') ||
00299 (p[i]=='_'))
00300 {}
00301 else
00302 {
00303 good = false;
00304
00305 if (more_than_one) error_msg << ", ";
00306 error_msg << i;
00307
00308 if (!more_than_one)
00309 more_than_one = true;
00310 }
00311 }
00312 error_msg << std::ends;
00313 std::string error_str ( error_msg.str());
00314
00315
00316 return good;
00317 }
00318
00319
00320 std::string Any::getMyPrefix( int which ) const
00321 {
00322 if ( this->m_ptr)
00323 {
00324 std::string kind = m_ptr->getObjectMeta().name();
00325 std::string name = m_ptr->getPath();
00326
00327 BON::ObjectPtr p = m_ptr->getObjectI();
00328 long relid = 0;
00329 BONCOMTHROW( p->get_RelID(&relid));
00330 char t[16];
00331 sprintf( t, "%x", relid);
00332
00333 ASSERT( name.length() >= 1);
00334 std::string tmp = name.substr(1) + '-' + t + '-' + kind;
00335
00336 if( which)
00337 return tmp;
00338 return "BonExtender/" + tmp;
00339 }
00340 throw "Error: inquiring prefix for a null object\n";
00341 }
00342
00343
00344 BON::RegistryNode Any::getMyRegistry() const
00345 {
00346 if ( this->m_ptr && this->m_parentFolder)
00347 return m_parentFolder->getRegistry()->getChild( getMyPrefix());
00348
00349 throw 1;
00350 }
00351
00352 BON::RegistryNode Any::getMIRegistry() const
00353 {
00354 if ( this->m_ptr && this->m_parentFolder)
00355 return m_parentFolder->getRegistry()->getChild( getMyPrefix( 1));
00356
00357 throw 1;
00358 }
00359
00360 void Any::prepareMacros()
00361 {
00362 std::string h, s, n = getValidNmspc();
00363 std::string::size_type c = (n.length() < 15) ? 15-n.length():(
00364 (n.length() < 30) ? 30-n.length():(
00365 (n.length() < 45) ? 45-n.length():(
00366 0
00367 )));
00368
00369
00370 h = "namespace " + n + " { " + std::string( c, ' ');
00371 h += "DECLARE_BONEXTENSION( BON::" + getMyKindStr() + ", " + getValidNameImpl() + ", " + getValidName() + " ); }\n";
00372
00373
00374
00375 s = "IMPLEMENT_BONEXTENSION( " + getValidNmspc() + Any::NamespaceDelimiter_str + getValidName() + ", \"" + getLStrictNmspc() + getName() + "\" );\n";
00376
00377 m_globalSource += s;
00378 m_globalHeader += h;
00379 }
00380
00381
00382 void Any::prepareIniFin()
00383 {
00384 Method i;
00385
00386 i.m_container = this;
00387 i.m_virtual = true;
00388 i.m_returnValue = "void";
00389 i.m_signature = "initialize() { }";
00390 i.m_implementation = "";
00391 i.m_comment = "";
00392
00393
00394 if ( Dumper::m_bGenInit) m_inifinMethods.push_back( i);
00395
00396 i.m_signature = "finalize() { }";
00397
00398 if ( Dumper::m_bGenFinalize) m_inifinMethods.push_back( i);
00399
00400
00401
00402
00403
00404
00405
00406 createAcceptMethod( Dumper::m_bGenAcceptTrave, Dumper::m_bGenAcceptSpeci, Dumper::m_iSpecAcceptRetVal == 1);
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416 }
00417
00418 void Any::createAcceptMethod( bool pWithTraversalOfKids, bool pSpecialized, bool pRetValBool)
00419 {
00420 Method m = CodeGen::acceptMethod( this, pWithTraversalOfKids, pSpecialized, pRetValBool);
00421 if( pSpecialized || getMyKind() != FCO_REP)
00422 m_inifinMethods.push_back( m);
00423 }
00424
00425 std::string Any::parseMOFException( const std::string& exc_str)
00426 {
00427 if( exc_str.empty()) return "";
00428
00429 std::string ind0 = std::string( 2 - 1, '\t'), ind = std::string( 2, '\t'), more_ind = std::string( 2 + 1, '\t');
00430
00431 std::string res, ctor_signature, ctor_inilist, ctor_body, class_body, name;
00432 std::string::size_type beg = 0, nwl = exc_str.find('\n');
00433 name = exc_str.substr(0, nwl);
00434
00435 while( nwl != std::string::npos)
00436 {
00437 beg = nwl + 1;
00438 nwl = exc_str.find('\n', beg);
00439
00440 if( nwl > beg && beg < exc_str.length() - 1)
00441 {
00442 std::string par_line = exc_str.substr( beg, nwl - beg);
00443 std::string::size_type type_end = par_line.find('\t');
00444 std::string par_type, par_name;
00445 par_type = par_line.substr(0, type_end);
00446 par_name = par_line.substr( type_end + 1);
00447
00448 if( ctor_signature.empty()) ctor_signature = "\n" + more_ind + "( ";
00449 else ctor_signature += "\n" + more_ind + ", ";
00450
00451 if( ctor_body.empty()) ctor_body = "\n" + more_ind + ": ";
00452 else ctor_body += "\n" + more_ind + ", ";
00453
00454 ctor_signature += par_type + " p_" + par_name;
00455 ctor_body += par_name + "( p_" + par_name + ")";
00456 class_body += "\n" + ind + par_type + " " + par_name + ";";
00457 }
00458 }
00459
00460 if( name == exc_str)
00461 {
00462 res = ind0 + "class " + name + "{ };\n";
00463 }
00464 else
00465 {
00466 ctor_signature = "\n" + ind + "// constructor\n" + ind + name + ctor_signature + "\n" + more_ind + ")";
00467 ctor_body += "\n" + ind + "{ }";
00468 class_body = "\n" + ind + "// members\n" + class_body;
00469 res = ind0 + "class " + name + "\n" + ind0 + "{\n" + ind0 + "public:\n" + ctor_signature + ctor_body + "\n" + class_body + "\n" + ind0 + "};\n";
00470 }
00471 return res;
00472 }
00473
00474
00475 std::string Any::parseMOFOperation( const std::string& exc_str)
00476 {
00477 if( exc_str.empty()) return "";
00478
00479 std::string ind0 = std::string( 2 - 1, '\t'), ind = std::string( 2, '\t');
00480
00481 std::string res, tabulated_exc_str;
00482 for( unsigned int i = 0; i < exc_str.length(); ++i)
00483 {
00484 tabulated_exc_str += exc_str[i];
00485 if( exc_str[i] == '\n')
00486 tabulated_exc_str += ind;
00487 }
00488 res = ind0 + tabulated_exc_str;
00489 if( exc_str.length() > 0 && exc_str[ exc_str.length() - 1 ] != '\n') res += '\n';
00490 return res;
00491 }
00492
00493
00494 std::string Any::processMOFNode( const BON::RegistryNode& rn, int ind_num)
00495 {
00496 try {
00497
00498 std::map< std::string, BON::RegistryNode, StringLex> aliases, enums, exceptions, operations, structures;
00499 std::map< std::string, BON::RegistryNode, StringLex>::iterator iter;
00500 std::set<BON::RegistryNode> all_nodes = rn->getChildren();
00501 std::set<BON::RegistryNode>::const_iterator all_iter = all_nodes.begin();
00502 for( ; all_iter != all_nodes.end(); ++all_iter)
00503 {
00504 std::string nm = (*all_iter)->getName();
00505 if( Any::MOFAlias_str.compare( nm.substr( 0, Any::MOFAlias_str.length())) == 0 ) aliases[nm] = *all_iter;
00506 else if( Any::MOFEnumeration_str.compare( nm.substr( 0, Any::MOFEnumeration_str.length())) == 0) enums[nm] = *all_iter;
00507 else if( Any::MOFException_str.compare( nm.substr( 0, Any::MOFException_str.length())) == 0) exceptions[nm] = *all_iter;
00508 else if( Any::MOFOperation_str.compare( nm.substr( 0, Any::MOFOperation_str.length())) == 0) operations[nm] = *all_iter;
00509 else if( Any::MOFStructure_str.compare( nm.substr( 0, Any::MOFStructure_str.length())) == 0) structures[nm] = *all_iter;
00510 }
00511
00512 std::string mof;
00513
00514
00515 for( iter = aliases.begin(); iter != aliases.end(); ++iter)
00516 mof += parseMOFOperation( iter->second->getValue()) + "\n";
00517
00518
00519 for( iter = enums.begin(); iter != enums.end(); ++iter)
00520 mof += parseMOFOperation( iter->second->getValue()) + "\n";
00521
00522
00523 for( iter = structures.begin(); iter != structures.end(); ++iter)
00524 mof += parseMOFOperation( iter->second->getValue()) + "\n";
00525
00526
00527 for( iter = exceptions.begin(); iter != exceptions.end(); ++iter)
00528 mof += parseMOFException( iter->second->getValue()) + "\n";
00529
00530
00531 for( iter = operations.begin(); iter != operations.end(); ++iter)
00532 mof += parseMOFOperation( iter->second->getValue()) + "\n";
00533
00534 return mof;
00535 } catch( ...) {
00536 global_vars.err << MSG_ERROR << "Some error occurred during MOF parsing.\n";
00537 return "";
00538 }
00539 }
00540
00541
00542 void Any::prepareMOF()
00543 {
00544 BON::RegistryNode my_rn = m_ptr->getRegistry();
00545 if( my_rn)
00546 m_sectionMOF = Any::processMOFNode( my_rn);
00547
00548 std::set< BON::FCO >::const_iterator it = m_equivs.begin();
00549 for ( ; it != m_equivs.end(); ++it)
00550 {
00551 if( m_ptr == *it) continue;
00552
00553 BON::RegistryNode rn = (*it)->getRegistry();
00554 if( rn)
00555 m_sectionMOF += Any::processMOFNode( rn);
00556 }
00557 }
00558
00559
00560 void Any::prepare()
00561 {
00562 prepareMacros();
00563 prepareIniFin();
00564 prepareMOF();
00565 }
00566
00567
00568 void Any::dumpGlobals()
00569 {
00570 DMP_S( m_globalSource);
00571 DMP_H( m_globalHeader);
00572 }
00573
00574
00575 std::string Any::dumpOrnament( bool is_abstract)
00576 {
00577 std::string row;
00578 row = "// C L A S S " + getValidNameImpl() + "\n";
00579
00580 const std::string orn = "//*******************************************************************\n";
00581
00582 return orn + row + orn;
00583 }
00584
00585
00586 void Any::dumpPre( std::string & h_file, std::string & c_file)
00587 {
00588
00589 h_file += "namespace " + getValidNmspc() + "\n{\n";
00590
00591
00592 h_file += dumpOrnament();
00593 h_file += "class " + getValidNameImpl();
00594 h_file += dumpClassHeader() + "{\npublic:\n";
00595
00596 for( unsigned int k = 0; k < m_inifinMethods.size(); ++k)
00597 {
00598 h_file += m_inifinMethods[k].getHeader() + "\n";
00599 c_file += m_inifinMethods[k].getSource();
00600 }
00601 }
00602
00603
00604 void Any::dumpPost( std::string & h_file, std::string & c_file)
00605 {
00606 h_file += "\n" + CodeGen::indent(1) + m_startUPToken + "\n" + getUserPart() + CodeGen::indent(1) + m_endUPToken+ "\n";
00607
00608 if( !m_sectionMOF.empty())
00609 {
00610 h_file += "\n// " + Any::MOFStart_str + "\n";
00611 h_file += "public:\n" + m_sectionMOF + "\n";
00612 h_file += "// " + Any::MOFEnd_str + "\n\n";
00613 }
00614
00615
00616
00617 h_file += "}; // class\n";
00618 h_file += "} // namespace\n";
00619 h_file += "\n\n";
00620
00621 }
00622
00623
00624 std::string Any::dumpClassHeader()
00625 {
00626
00627
00628
00629 return " :\n\t public BON::" + getMyKindStr() + "Impl\n";
00630
00631 }
00632
00633
00634 std::string Any::getUserPart()
00635 {
00636 std::ifstream old_xmp_file;
00637 std::string old_f_name;
00638 old_f_name = global_vars.header_backup_name;
00639 if ( old_f_name.empty())
00640 return CodeGen::indent(1) + "// add your own members here\n";
00641
00642 old_xmp_file.open( old_f_name.c_str() ,std::ios_base::in);
00643 if ( !old_xmp_file.is_open())
00644 return CodeGen::indent(1) + "// ERROR accessing file\n";
00645
00646 std::string up, line;
00647 while( !old_xmp_file.eof() && line.find( "class " + getValidNameImpl() + " :") == std::string::npos)
00648 {
00649 std::getline( old_xmp_file, line);
00650 }
00651 if ( !old_xmp_file.eof())
00652 {
00653 while( !old_xmp_file.eof() && line.find( m_startUPToken) == std::string::npos)
00654 {
00655 std::getline( old_xmp_file, line);
00656 }
00657 if ( !old_xmp_file.eof())
00658 {
00659 std::getline( old_xmp_file, line);
00660 while( !old_xmp_file.eof() && line.find( m_endUPToken) == std::string::npos)
00661 {
00662 up += line + "\n";
00663 std::getline( old_xmp_file, line);
00664 }
00665 if ( !old_xmp_file.eof())
00666 {
00667 }
00668 else
00669 {
00670 old_xmp_file.close();
00671 return CodeGen::indent(1) + "//Class found. Ending token (" + m_endUPToken + ") not found\n";
00672 }
00673 }
00674 else
00675 {
00676 old_xmp_file.close();
00677 return CodeGen::indent(1) + "//Class found. Starting token (" + m_startUPToken + ") not found\n";
00678 }
00679 }
00680 else
00681 {
00682 old_xmp_file.close();
00683 return CodeGen::indent(1) + "//Class not found\n";
00684 }
00685 old_xmp_file.close();
00686 return up;
00687 }
00688
00689 void Any::makeBackup()
00690 {
00691 if( global_vars.m_outputMethod == Globals::PERCLASS)
00692 {
00693 std::string dirname = getValidNmspc();
00694 std::string fname = getName();
00695
00696 if( !dirname.empty())
00697 {
00698 bool success = directoryExists( dirname.c_str());
00699 if( !success) success = directoryCreate( dirname.c_str());
00700
00701 if( success) dirname += "\\";
00702 else dirname = "";
00703 }
00704
00705 std::string fn = dirname + fname;
00706 if( !makeFileMove( ( fn + ".h").c_str(), ( fn + ".h.bak").c_str()))
00707 global_vars.err << MSG_ERROR << "Could not backup " << ( fn + ".h");
00708 if( !makeFileMove( ( fn + ".cpp").c_str(), ( fn + ".cpp.bak").c_str()))
00709 global_vars.err << MSG_ERROR << "Could not backup " << ( fn + ".cpp");
00710
00711
00712 }
00713 }
00714
00715 void Any::initOutS()
00716 {
00717 if( global_vars.m_outputMethod == Globals::PERCLASS)
00718 {
00719 std::string dirname = getValidNmspc();
00720 std::string fname = getName();
00721
00722 if( !dirname.empty())
00723 {
00724 bool success = directoryExists( dirname.c_str());
00725 if( !success) success = directoryCreate( dirname.c_str());
00726
00727 if( success) dirname += "\\";
00728 else dirname = "";
00729 }
00730
00731 std::string fn_c = dirname + fname + ".cpp";
00732
00733
00734 m_sStream.open( fn_c.c_str(), std::ios_base::out | std::ios_base::app);
00735 m_sStream.seekp( 0, std::ios::end);
00736 int lenf = m_sStream.tellp();
00737 if( lenf == ( std::fstream::pos_type) 0)
00738 {
00739 m_sStream << "#include \"stdafx.h\"" << std::endl;
00740 m_sStream << "#include \"" << shortFileName( global_vars.header_file_name) << "\"" << std::endl;
00741
00742 if( Dumper::m_bGenAcceptSpeci && 0)
00743 m_sStream << "#include \"" << shortFileName( global_vars.m_visitorHeaderFileName) << "\"" << std::endl;
00744 }
00745 else
00746 {
00747
00748
00749
00750 global_vars.err << MSG_WARNING << "Methods of class \"" << fname << "\" appended to end of file: " << fn_c << " [Hint: filenames are not case-sensitive, thus might clash!]";
00751 }
00752
00753 m_sStream << std::endl;
00754 m_sStream << std::endl;
00755 }
00756 }
00757
00758 void Any::initOutH( std::string& resu)
00759 {
00760 if( global_vars.m_outputMethod == Globals::PERCLASS)
00761 {
00762 std::string dirname = getValidNmspc();
00763 std::string fname = getName();
00764 std::string cc = capitalizeString( dirname + fname);
00765
00766
00767 if( !dirname.empty())
00768 {
00769 bool success = directoryExists( dirname.c_str());
00770 if( !success) success = directoryCreate( dirname.c_str());
00771
00772 if( success) dirname += "\\";
00773 else dirname = "";
00774 }
00775
00776 std::string fn_h = dirname + fname + ".h";
00777
00778
00779 m_hStream.open( fn_h.c_str(), std::ios_base::out | std::ios_base::app);
00780 m_hStream.seekp( 0, std::ios::end);
00781 int lenf = m_hStream.tellp();
00782 if( lenf == ( std::fstream::pos_type) 0)
00783 {
00784 m_hStream << "#ifndef " << cc << "_H" << std::endl;
00785 m_hStream << "#define " << cc << "_H" << std::endl;
00786 m_hStream << std::endl;
00787 m_hStream << "#include \"" << shortFileName( global_vars.header_file_name) << "\"" << std::endl;
00788 }
00789 else
00790 {
00791
00792
00793
00794 global_vars.err << MSG_WARNING << "Declaration for class \"" << fname << "\" appended to end of file: " << fn_h << " [Hint: filenames are not case-sensitive, thus might clash!]";
00795
00796 m_hStream << "#if 1 // dummy" << std::endl;
00797 }
00798
00799 m_hStream << std::endl;
00800 m_hStream << std::endl;
00801
00802
00803 resu += "#include \"" + ( dirname.empty()?"":dirname.substr(0, dirname.length() - 1) + "/") + fname + ".h\"\n";
00804 }
00805 }
00806
00807 void Any::finiOutS()
00808 {
00809 if( global_vars.m_outputMethod == Globals::PERCLASS)
00810 {
00811 m_sStream.close();
00812 }
00813 }
00814
00815 void Any::finiOutH()
00816 {
00817 if( global_vars.m_outputMethod == Globals::PERCLASS)
00818 {
00819 m_hStream << "#endif" << std::endl;
00820 m_hStream.close();
00821 }
00822 }
00823
00824 void Any::sendOutH( const std::string& content)
00825 {
00826 if( global_vars.m_outputMethod == Globals::ALLTOGETHER)
00827 {
00828 DMP_H( content);
00829 }
00830 else if( global_vars.m_outputMethod == Globals::PERCLASS)
00831 {
00832 m_hStream << content;
00833 }
00834 else if( global_vars.m_outputMethod == Globals::PERNAMESPACE)
00835 {
00836
00837 }
00838 }
00839
00840 void Any::sendOutS( const std::string& content)
00841 {
00842 if( global_vars.m_outputMethod == Globals::ALLTOGETHER)
00843 {
00844 DMP_S( content);
00845 }
00846 else if( global_vars.m_outputMethod == Globals::PERCLASS)
00847 {
00848 m_sStream << content;
00849 }
00850 else if( global_vars.m_outputMethod == Globals::PERNAMESPACE)
00851 {
00852
00853 }
00854 }