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

📄 filecode.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* * =========================================================================== * PRODUCTION $Log: filecode.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 19:43:05  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.45 * PRODUCTION * =========================================================================== *//*  $Id: filecode.cpp,v 1000.1 2004/06/01 19:43:05 gouriano Exp $* ===========================================================================**                            PUBLIC DOMAIN NOTICE*               National Center for Biotechnology Information**  This software/database is a "United States Government Work" under the*  terms of the United States Copyright Act.  It was written as part of*  the author's official duties as a United States Government employee and*  thus cannot be copyrighted.  This software/database is freely available*  to the public for use. The National Library of Medicine and the U.S.*  Government have not placed any restriction on its use or reproduction.**  Although all reasonable efforts have been taken to ensure the accuracy*  and reliability of the software and data, the NLM and the U.S.*  Government do not and cannot warrant the performance or results that*  may be obtained by using this software or data. The NLM and the U.S.*  Government disclaim all warranties, express or implied, including*  warranties of performance, merchantability or fitness for any particular*  purpose.**  Please cite the author in any work or product based on this material.** ===========================================================================** Author: Eugene Vasilchenko** File Description:*   File generator**/#include <ncbi_pch.hpp>#include <corelib/ncbifile.hpp>#include <serial/datatool/exceptions.hpp>#include <serial/datatool/generate.hpp>#include <serial/datatool/filecode.hpp>#include <serial/datatool/type.hpp>#include <serial/datatool/typestr.hpp>#include <serial/datatool/fileutil.hpp>#include <serial/datatool/namespace.hpp>#include <serial/datatool/module.hpp>#include <serial/datatool/code.hpp>#include <util/checksum.hpp>#include <typeinfo>BEGIN_NCBI_SCOPEstring CFileCode::m_PchHeader;CFileCode::CFileCode(const CCodeGenerator* codeGenerator,                     const string& baseName)    : m_CodeGenerator(codeGenerator),m_BaseName(baseName){    m_UseQuotedForm = false;    return;}CFileCode::~CFileCode(void){    return;}const string& CFileCode::ChangeFileBaseName(void){    m_BaseName += "x";    return GetFileBaseName();}string CFileCode::GetBaseFileBaseName(void) const{    _ASSERT(BaseName(GetFileBaseName()).size() + 5 <= MAX_FILE_NAME_LENGTH);    return GetFileBaseName() + "_";}string CFileCode::GetUserFileBaseName(void) const{    return GetFileBaseName();}string CFileCode::GetBaseHPPName(void) const{    return GetBaseFileBaseName() + ".hpp";}string CFileCode::GetUserHPPName(void) const{    return GetUserFileBaseName() + ".hpp";}string CFileCode::GetBaseCPPName(void) const{    return GetBaseFileBaseName() + ".cpp";}string CFileCode::GetUserCPPName(void) const{    return GetUserFileBaseName() + ".cpp";}string CFileCode::GetDefineBase(void) const{    string s;    ITERATE ( string, i, GetFileBaseName() ) {        char c = *i;        if ( c >= 'a' && c <= 'z' )            c = c + ('A' - 'a');        else if ( (c < 'A' || c > 'Z') &&                  (c < '0' || c > '9') )            c = '_';        s += c;    }    return s;}string CFileCode::GetBaseHPPDefine(void) const{    return GetDefineBase() + "_BASE_HPP";}string CFileCode::GetUserHPPDefine(void) const{    return GetDefineBase() + "_HPP";}string CFileCode::Include(const string& s, bool addExt) const{    if ( s.empty() ) {        NCBI_THROW(CDatatoolException,eInvalidData,"Empty file name");    }    switch ( s[0] ) {    case '<':    case '"':        return s[0] + GetStdPath(s.substr(1, s.length()-2)) + s[s.length()-1];    default:    {        string result(1, m_UseQuotedForm ? '\"' : '<');        result += GetStdPath(addExt ? (s + ".hpp") : s);        result += m_UseQuotedForm ? '\"' : '>';        return result;    }    }}string CFileCode::GetMethodPrefix(void) const{    return kEmptyStr;}CFileCode::TIncludes& CFileCode::HPPIncludes(void){    return m_HPPIncludes;}CFileCode::TIncludes& CFileCode::CPPIncludes(void){    return m_CPPIncludes;}void CFileCode::AddForwardDeclaration(const string& cls, const CNamespace& ns){    m_ForwardDeclarations[cls] = ns;}const CNamespace& CFileCode::GetNamespace(void) const{    _ASSERT(m_CurrentClass != 0);    return m_CurrentClass->ns;}void CFileCode::AddHPPCode(const CNcbiOstrstream& code){    m_CurrentClass->hppCode =        CNcbiOstrstreamToString(const_cast<CNcbiOstrstream&>(code));}void CFileCode::AddINLCode(const CNcbiOstrstream& code){    m_CurrentClass->inlCode =         CNcbiOstrstreamToString(const_cast<CNcbiOstrstream&>(code));}void CFileCode::AddCPPCode(const CNcbiOstrstream& code){    m_CurrentClass->cppCode =         CNcbiOstrstreamToString(const_cast<CNcbiOstrstream&>(code));}void CFileCode::UseQuotedForm(bool use){    m_UseQuotedForm = use;}void CFileCode::CreateFileFolder(const string& fileName) const{    CDirEntry entry(fileName);    CDir  dir(entry.GetDir());    dir.CreatePath();}void CFileCode::GenerateCode(void){    if ( !m_Classes.empty() ) {        NON_CONST_ITERATE ( TClasses, i, m_Classes ) {            m_CurrentClass = &*i;            m_CurrentClass->code->GenerateCode(*this);        }        m_CurrentClass = 0;    }    m_HPPIncludes.erase(kEmptyStr);    m_CPPIncludes.erase(kEmptyStr);}CNcbiOstream& CFileCode::WriteCopyrightHeader(CNcbiOstream& out){    return out <<        "/* $""Id$\n"        " * ===========================================================================\n"        " *\n"        " *                            PUBLIC DOMAIN NOTICE\n"        " *               National Center for Biotechnology Information\n"        " *\n"        " *  This software/database is a \"United States Government Work\" under the\n"        " *  terms of the United States Copyright Act.  It was written as part of\n"        " *  the author's official duties as a United States Government employee and\n"        " *  thus cannot be copyrighted.  This software/database is freely available\n"        " *  to the public for use. The National Library of Medicine and the U.S.\n"        " *  Government have not placed any restriction on its use or reproduction.\n"        " *\n"        " *  Although all reasonable efforts have been taken to ensure the accuracy\n"        " *  and reliability of the software and data, the NLM and the U.S.\n"        " *  Government do not and cannot warrant the performance or results that\n"        " *  may be obtained by using this software or data. The NLM and the U.S.\n"        " *  Government disclaim all warranties, express or implied, including\n"        " *  warranties of performance, merchantability or fitness for any particular\n"        " *  purpose.\n"        " *\n"        " *  Please cite the author in any work or product based on this material.\n"        " *\n"        " * ===========================================================================\n"        " *\n";}CNcbiOstream& CFileCode::WriteSourceFile(CNcbiOstream& out) const{    ITERATE ( set<string>, i, m_SourceFiles ) {        if ( i != m_SourceFiles.begin() )            out << ", ";        {            CDirEntry entry(*i);            out << '\'' << entry.GetName() << '\'';        }    }    return out;}CNcbiOstream& CFileCode::WriteSpecRefs(CNcbiOstream& out) const{    string docroot = CClassCode::GetDocRootURL();    string rootdir = m_CodeGenerator->GetRootDir();    if (docroot.empty()) {        out << "/// ";        WriteSourceFile(out) << ".\n";    } else {        out << "/// <a href=\"";        ITERATE ( set<string>, i, m_SourceFiles ) {            CDirEntry entry(*i);            string link;            if (!rootdir.empty()) {                link = NStr::Replace(entry.GetPath(),rootdir,docroot);            } else {                link = Path( docroot, entry.GetPath());            }            out << GetStdPath(link) << "\">" << entry.GetName() << "</a>\n";        }        string deffile = m_CodeGenerator->GetDefFile();        if (!deffile.empty()) {            CDirEntry entry(deffile);            out                << "/// and additional tune-up parameters:\n";            string link;            if (!rootdir.empty()) {                link = NStr::Replace(entry.GetPath(),rootdir,docroot);            } else {                link = Path( docroot, entry.GetPath());            }            out << "/// <a href=\"" << GetStdPath(link) << "\">" << entry.GetName() << "</a>\n";        }    }    return out;}CNcbiOstream& CFileCode::WriteCopyright(CNcbiOstream& out, bool header) const{    if (header) {        WriteCopyrightHeader(out)            << " */\n\n"            << "/// @" << CDirEntry(GetBaseHPPName()).GetName() << "\n"            << "/// Data storage class.\n"            << "///\n"            << "/// This file was generated by application DATATOOL\n"            << "/// using the following specifications:\n";        WriteSpecRefs(out) <<            "///\n"            "/// ATTENTION:\n"            "///   Don't edit or commit this file into CVS as this file will\n"            "///   be overridden (by DATATOOL) without warning!\n";    } else {        WriteCopyrightHeader(out) <<            " * File Description:\n"            " *   This code was generated by application DATATOOL\n"            " *   using the following specifications:\n"            " *   ";        WriteSourceFile(out) << ".\n"            " *\n"

⌨️ 快捷键说明

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