⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filecode.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
}void CFileCode::LoadLines(TGenerateMethod method, list<string>& lines) const{    CNcbiOstrstream code;    // generate code    (this->*method)(code);    // get code length    size_t count = code.pcount();    if ( count == 0 ) {        NCBI_THROW(CDatatoolException,eInvalidData,"empty generated code");    }    // get code string pointer    const char* codePtr = code.str();    code.freeze(false);    // split code by lines    while ( count > 0 ) {        // find end of next line        const char* eolPtr = (const char*)memchr(codePtr, '\n', count);        if ( !eolPtr ) {            NCBI_THROW(CDatatoolException,eInvalidData,                       "unended line in generated code");        }        // add next line to list        lines.push_back(kEmptyStr);        lines.back().assign(codePtr, eolPtr);        // skip EOL symbol ('\n')        ++eolPtr;        // update code length        count -= (eolPtr - codePtr);        // update code pointer        codePtr = eolPtr;    }}bool CFileCode::WriteUserFile(const string& path, const string& name,                              string& fileName, TGenerateMethod method) const{    // parse new code lines    list<string> newLines;    LoadLines(method, newLines);    fileName = Path(path, name);    CreateFileFolder(fileName);    if ( ModifiedByUser(fileName, newLines) ) {        // do nothing on user modified files        return false;    }    // write new contents of nonmodified file    CDelayedOfstream out(fileName);    if ( !out ) {        ERR_POST(Fatal << "Cannot create file: " << fileName);        return false;    }    CChecksum checksum;    ITERATE ( list<string>, i, newLines ) {        checksum.AddLine(*i);        out << *i << '\n';    }    out << checksum;    out.close();    if ( !out ) {        ERR_POST("Error writing file " << fileName);        return false;    }    return true;}void CFileCode::GenerateUserHPPCode(CNcbiOstream& header) const{    string hppDefine = GetUserHPPDefine();    WriteUserCopyright(header, true) <<        "\n"        "#ifndef " << hppDefine << "\n"        "#define " << hppDefine << "\n"        "\n";    header <<        "\n"        "// generated includes\n"        "#include " << Include(GetBaseHPPName()) << "\n";        CNamespace ns;    if ( !m_Classes.empty() ) {        header <<            "\n"            "// generated classes\n"            "\n";        ITERATE ( TClasses, i, m_Classes ) {            ns.Set(i->ns, header, false);            i->code->GenerateUserHPPCode(header);        }    }    ns.Reset(header);        WriteLogKeyword(header);    header <<        "\n"        "#endif // " << hppDefine << "\n";}void CFileCode::GenerateUserCPPCode(CNcbiOstream& code) const{    WriteUserCopyright(code, false) <<        "\n"        "// standard includes\n";    if (!m_PchHeader.empty()) {        code <<            "#include <" << m_PchHeader << ">\n";    }    code <<        "\n"        "// generated includes\n"        "#include " << Include(GetUserHPPName()) << "\n";    CNamespace ns;    if ( !m_Classes.empty() ) {        code <<            "\n"            "// generated classes\n"            "\n";        ITERATE ( TClasses, i, m_Classes ) {            ns.Set(i->ns, code, false);            i->code->GenerateUserCPPCode(code);        }    }    ns.Reset(code);    WriteLogKeyword(code);}bool CFileCode::AddType(const CDataType* type){    string idName = type->IdName();    if ( m_AddedClasses.find(idName) != m_AddedClasses.end() )        return false;    m_AddedClasses.insert(idName);    _TRACE("AddType: " << idName << ": " << typeid(*type).name());    m_SourceFiles.insert(type->GetSourceFileName());    AutoPtr<CTypeStrings> code = type->GenerateCode();    code->SetModuleName(type->GetModule()->GetName());    m_Classes.push_front(SClassInfo(type->Namespace(), code));    return true;}void CFileCode::GetModuleNames( map<string,string>& names) const{    CNcbiOstrstream ostr;    WriteSourceFile(ostr);    ostr.put('\0');    string src_file = string(CNcbiOstrstreamToString(ostr));    string module_name;    ITERATE ( TClasses, i, m_Classes ) {        module_name = i->code->GetModuleName();        if (names.find(module_name) == names.end()) {            names[module_name] = src_file;        }    }}END_NCBI_SCOPE/** ===========================================================================* $Log: filecode.cpp,v $* Revision 1000.1  2004/06/01 19:43:05  gouriano* PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.45** Revision 1.45  2004/05/17 21:03:14  gorelenk* Added include of PCH ncbi_pch.hpp** Revision 1.44  2004/05/17 14:50:54  gouriano* Added possibility to include precompiled header** Revision 1.43  2004/05/03 19:31:03  gouriano* Made generation of DOXYGEN-style comments optional** Revision 1.42  2004/04/29 20:11:39  gouriano* Generate DOXYGEN-style comments in C++ headers** Revision 1.41  2003/05/29 17:25:34  gouriano* added possibility of generation .cvsignore file** Revision 1.40  2003/03/11 20:06:47  kuznets* iterate -> ITERATE** Revision 1.39  2003/03/10 18:55:18  gouriano* use new structured exceptions (based on CException)** Revision 1.38  2002/12/17 16:22:48  gouriano* separated class name from the name of the file in which it will be written** Revision 1.37  2002/10/25 16:13:04  ucko* Tweak CFileCode::Include to avoid segfaulting when built with KCC* (presumably due to a compiler bug)** Revision 1.36  2002/10/22 15:06:13  gouriano* added possibillity to use quoted syntax form for generated include files** Revision 1.35  2002/10/15 13:56:15  gouriano* removed explicit reference to ASN (could be DTD now)** Revision 1.34  2002/10/01 14:20:30  gouriano* added more generation report data** Revision 1.33  2002/09/30 19:15:08  gouriano* write only the base name of the ASN file (in comments section)** Revision 1.32  2002/06/13 15:41:17  ucko* Restore generated newline following Log keyword (accidentally dropped in* the previous revision).** Revision 1.31  2002/06/11 02:46:49  vakatov* Fixed a compilation bug introduced in R1.30;  plus some code beautification.** Revision 1.30  2002/06/10 18:41:30  ucko* Move CVS logs (both internal and generated) to the end.** Revision 1.29  2001/08/31 20:05:46  ucko* Fix ICC build.** Revision 1.28  2001/08/16 13:18:03  grichenk* Corrected calls to GetStdPath() -- moved '>' outside the call** Revision 1.27  2001/08/15 20:27:14  juran* Convert native pathnames to unix-style for include directives.** Revision 1.26  2001/01/05 20:10:57  vasilche* CByteSource, CIStrBuffer, COStrBuffer, CLightString, CChecksum, CWeakMap* were moved to util.** Revision 1.25  2000/11/22 16:26:29  vasilche* Added generation/checking of checksum to user files.** Revision 1.24  2000/11/07 17:26:25  vasilche* Added module names to CTypeInfo and CEnumeratedTypeValues* Added possibility to set include directory for whole module** Revision 1.23  2000/08/25 15:59:21  vasilche* Renamed directory tool -> datatool.** Revision 1.22  2000/06/16 16:31:39  vasilche* Changed implementation of choices and classes info to allow use of the* same classes in generated and user written classes.** Revision 1.21  2000/04/28 16:58:16  vasilche* Added classes CByteSource and CByteSourceReader for generic reading.* Added delayed reading of choice variants.** Revision 1.20  2000/04/17 19:11:08  vasilche* Fixed failed assertion.* Removed redundant namespace specifications.** Revision 1.19  2000/04/12 15:36:51  vasilche* Added -on <namespace> argument to datatool.* Removed unnecessary namespace specifications in generated files.** Revision 1.18  2000/04/07 19:26:26  vasilche* Added namespace support to datatool.* By default with argument -oR datatool will generate objects in namespace* NCBI_NS_NCBI::objects (aka ncbi::objects).* Datatool's classes also moved to NCBI namespace.** Revision 1.17  2000/04/03 18:47:30  vasilche* Added main include file for generated headers.* serialimpl.hpp is included in generated sources with GetTypeInfo methods** Revision 1.16  2000/03/29 15:52:26  vasilche* Generated files names limited to 31 symbols due to limitations of Mac.* Removed unions with only one member.** Revision 1.15  2000/03/17 17:05:59  vasilche* String literal split to avoid influence of cvs.** Revision 1.14  2000/03/17 16:49:55  vasilche* Added copyright message to generated files.* All objects pointers in choices now share the only CObject pointer.* All setters/getters made public until we'll find better solution.** Revision 1.13  2000/03/07 14:06:31  vasilche* Added generation of reference counted objects.** Revision 1.12  2000/02/17 21:26:18  vasilche* Inline methods now will be at the end of *_Base.hpp files.** Revision 1.11  2000/02/17 20:05:07  vasilche* Inline methods now will be generated in *_Base.inl files.* Fixed processing of StringStore.* Renamed in choices: Selected() -> Which(), E_choice -> E_Choice.* Enumerated values now will preserve case as in ASN.1 definition.** Revision 1.10  2000/02/01 21:47:58  vasilche* Added CGeneratedChoiceTypeInfo for generated choice classes.* Removed CMemberInfo subclasses.* Added support for DEFAULT/OPTIONAL members.* Changed class generation.* Moved datatool headers to include/internal/serial/tool.** Revision 1.9  2000/01/06 16:13:17  vasilche* Fail of file generation now fatal.** Revision 1.8  1999/12/28 18:55:57  vasilche* Reduced size of compiled object files:* 1. avoid inline or implicit virtual methods (especially destructors).* 2. avoid std::string's methods usage in inline methods.* 3. avoid string literals ("xxx") in inline methods.** Revision 1.7  1999/12/21 17:18:34  vasilche* Added CDelayedFostream class which rewrites file only if contents is changed.** Revision 1.6  1999/12/20 21:00:17  vasilche* Added generation of sources in different directories.** Revision 1.5  1999/12/03 21:42:12  vasilche* Fixed conflict of enums in choices.** Revision 1.4  1999/12/01 17:36:25  vasilche* Fixed CHOICE processing.** Revision 1.3  1999/11/22 21:04:49  vasilche* Cleaned main interface headers. Now generated files should include* serial/serialimpl.hpp and user code should include serial/serial.hpp* which became might lighter.** Revision 1.2  1999/11/15 19:36:14  vasilche* Fixed warnings on GCC** ===========================================================================*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -