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

📄 type.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * =========================================================================== * PRODUCTION $Log: type.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 19:43:54  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.80 * PRODUCTION * =========================================================================== *//*  $Id: type.cpp,v 1000.2 2004/06/01 19:43:54 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:*   Base class for type description*/#include <ncbi_pch.hpp>#include <serial/datatool/type.hpp>#include <serial/autoptrinfo.hpp>#include <serial/datatool/value.hpp>#include <serial/datatool/blocktype.hpp>#include <serial/datatool/module.hpp>#include <serial/datatool/classstr.hpp>#include <serial/datatool/aliasstr.hpp>#include <serial/datatool/exceptions.hpp>#include <serial/datatool/reftype.hpp>#include <serial/datatool/unitype.hpp>#include <serial/datatool/choicetype.hpp>#include <serial/datatool/statictype.hpp>#include <serial/datatool/enumtype.hpp>#include <serial/datatool/fileutil.hpp>#include <serial/datatool/srcutil.hpp>#include <algorithm>BEGIN_NCBI_SCOPEbool CDataType::sm_EnforcedStdXml = false;set<string> CDataType::sm_SavedNames;class CAnyTypeSource : public CTypeInfoSource{public:    CAnyTypeSource(CDataType* type)        : m_Type(type)        {        }    TTypeInfo GetTypeInfo(void);private:    CDataType* m_Type;};TTypeInfo CAnyTypeSource::GetTypeInfo(void){    return m_Type->GetAnyTypeInfo();}CDataType::CDataType(void)    : m_ParentType(0), m_Module(0), m_SourceLine(0),      m_DataMember(0), m_TypeStr(0), m_Set(0), m_Choice(0), m_Checked(false),      m_Tag(eNoExplicitTag), m_IsAlias(false){}CDataType::~CDataType(){// NOTE:  This compiler bug was fixed by Jan 24 2002, test passed with://           CC: Sun WorkShop 6 update 2 C++ 5.3 Patch 111685-03 2001/10/19//        We leave the workaround here for maybe half a year (for other guys).#if defined(NCBI_COMPILER_WORKSHOP)// We have to use two #if's here because KAI C++ cannot handle #if foo == bar#  if (NCBI_COMPILER_VERSION == 530)    // BW_010::  to workaround (already reported to SUN, CASE ID 62563729)    //           internal bug of the SUN Forte 6 Update 1 and Update 2 compiler    (void) atoi("5");#  endif#endif}void CDataType::SetSourceLine(int line){    m_SourceLine = line;}void CDataType::Warning(const string& mess) const{    CNcbiDiag() << LocationString() << ": " << mess;}void CDataType::PrintASNTypeComments(CNcbiOstream& out, int indent) const{    m_Comments.PrintASN(out, indent);}void CDataType::PrintDTD(CNcbiOstream& out) const{    if (x_IsSavedName(XmlTagName())) {        return;    }    m_Comments.PrintDTD(out);    PrintDTDElement(out);    out << '\n';    x_AddSavedName(XmlTagName());    PrintDTDExtra(out);}void CDataType::PrintDTD(CNcbiOstream& out,                         const CComments& extra) const{    if (x_IsSavedName(XmlTagName())) {        return;    }    m_Comments.PrintDTD(out);    bool oneLineComment = extra.OneLine();    if ( !oneLineComment )        extra.PrintDTD(out);    PrintDTDElement(out);    if ( oneLineComment ) {        out << ' ';        extra.PrintDTD(out, CComments::eOneLine);    }    out << '\n';    x_AddSavedName(XmlTagName());    PrintDTDExtra(out);}void CDataType::PrintDTDExtra(CNcbiOstream& /*out*/) const{}// XML schema generator submitted by// Marc Dumontier, Blueprint initiative, dumontier@mshri.on.cavoid CDataType::PrintXMLSchema(CNcbiOstream& out) const{    if (m_DataMember && (m_DataMember->Attlist() || m_DataMember->Notag())) {        return;    }    if (x_IsSavedName(XmlTagName())) {        return;    }//    out <<//        "<!-- Definition of "<< XmlTagName() <<" -->\n"//        "\n";    m_Comments.PrintDTD(out);    PrintXMLSchemaElement(out);    out << '\n';    x_AddSavedName(XmlTagName());    PrintXMLSchemaExtra(out);    out << '\n';}                                                                                                                                                      void CDataType::PrintXMLSchema(CNcbiOstream& out,                         const CComments& extra) const{    if (m_DataMember && (m_DataMember->Attlist() || m_DataMember->Notag())) {        return;    }    if (x_IsSavedName(XmlTagName())) {        return;    }//    out <<//        "<!-- Definition of "<< XmlTagName() <<" -->\n"//        "\n";    m_Comments.PrintDTD(out);    bool oneLineComment = extra.OneLine();    if ( oneLineComment ) {        out << ' ';        extra.PrintDTD(out, CComments::eOneLine);        out << '\n';    } else {        extra.PrintDTD(out);    }    PrintXMLSchemaElement(out);    out << '\n';    x_AddSavedName(XmlTagName());    PrintXMLSchemaExtra(out);    out << '\n';}void CDataType::PrintXMLSchemaExtra(CNcbiOstream& /*out*/) const{}void CDataType::SetInSet(const CUniSequenceDataType* sequence){    _ASSERT(GetParentType() == sequence);    m_Set = sequence;}void CDataType::SetInChoice(const CChoiceDataType* choice){    _ASSERT(GetParentType() == choice);    m_Choice = choice;}void CDataType::AddReference(const CReferenceDataType* reference){    _ASSERT(GetParentType() == 0);    if ( !m_References )        m_References = new TReferences;    m_References->push_back(reference);}void CDataType::SetParent(const CDataType* parent, const string& memberName){    _ASSERT(parent != 0);    _ASSERT(m_ParentType == 0 && m_Module == 0 && m_MemberName.empty());    m_ParentType = parent;    m_Module = parent->GetModule();    m_MemberName = memberName;    _ASSERT(m_Module != 0);    if (m_DataMember && m_DataMember->GetDefault()) {        m_DataMember->GetDefault()->SetModule(m_Module);    }    FixTypeTree();}void CDataType::SetParent(const CDataTypeModule* module,                          const string& typeName){    _ASSERT(module != 0);    _ASSERT(m_ParentType == 0 && m_Module == 0 && m_MemberName.empty());    m_Module = module;    m_MemberName = typeName;    FixTypeTree();}void CDataType::FixTypeTree(void) const{}bool CDataType::Check(void){    if ( m_Checked )        return true;    m_Checked = true;    _ASSERT(m_Module != 0);    return CheckType();}bool CDataType::CheckType(void) const{    return true;}const string CDataType::GetVar(const string& varName) const{    const CDataType* parent = GetParentType();    if ( !parent ) {        return GetModule()->GetVar(m_MemberName, varName);    }    else {        return parent->GetVar(m_MemberName + '.' + varName);    }}void  CDataType::ForbidVar(const string& var, const string& value){    typedef multimap<string, string> TMultimap;    if (!var.empty() && !value.empty()) {        TMultimap::const_iterator it = m_ForbidVar.find(var);        for ( ; it != m_ForbidVar.end() && it->first == var; ++it) {            if (it->second == value) {                return;            }        }        m_ForbidVar.insert(TMultimap::value_type(var, value));    }}void  CDataType::AllowVar(const string& var, const string& value){    if (!var.empty() && !value.empty()) {        multimap<string,string>::iterator it = m_ForbidVar.find(var);        for ( ; it != m_ForbidVar.end() && it->first == var; ++it) {            if (it->second == value) {                m_ForbidVar.erase(it);                return;            }        }    }}const string CDataType::GetAndVerifyVar(const string& var) const{    const string tmp = GetVar(var);    if (!tmp.empty()) {        multimap<string,string>::const_iterator it = m_ForbidVar.find(var);        for ( ; it != m_ForbidVar.end() && it->first == var; ++it) {            if (it->second == tmp) {                NCBI_THROW(CDatatoolException,eForbidden,                    IdName()+": forbidden "+var+"="+tmp);            }        }    }    return tmp;}const string& CDataType::GetSourceFileName(void) const{    return GetModule()->GetSourceFileName();}string CDataType::LocationString(void) const{    return GetSourceFileName() + ':' + NStr::IntToString(GetSourceLine()) +        ": " + IdName(); }string CDataType::IdName(void) const{    const CDataType* parent = GetParentType();    if ( !parent ) {        // root type        return m_MemberName;    }    else {        // member        return parent->IdName() + '.' + m_MemberName;    }}string CDataType::XmlTagName(void) const{    if (GetEnforcedStdXml()) {        return m_MemberName;    }    const CDataType* parent = GetParentType();    if ( !parent ) {        // root type        return m_MemberName;    }    else {        // member        return parent->XmlTagName() + '_' + m_MemberName;    }}const string& CDataType::GlobalName(void) const{    if ( !GetParentType() )        return m_MemberName;    else        return NcbiEmptyString;}string CDataType::GetKeyPrefix(void) const{    const CDataType* parent = GetParentType();    if ( !parent ) {        // root type        return NcbiEmptyString;    }    else {        // member        string parentPrefix = parent->GetKeyPrefix();        if ( parentPrefix.empty() )            return m_MemberName;        else            return parentPrefix + '.' + m_MemberName;    }}bool CDataType::Skipped(void) const{    return GetVar("_class") == "-";}string CDataType::ClassName(void) const{    const string& cls = GetVar("_class");    if ( !cls.empty() )        return cls;    if ( GetParentType() ) {        // local type        return "C_"+Identifier(m_MemberName);    }    else {        // global type        return 'C'+Identifier(m_MemberName);    }}string CDataType::FileName(void) const{    if ( GetParentType() ) {        return GetParentType()->FileName();    }    if ( m_CachedFileName.empty() ) {        const string& file = GetVar("_file");        if ( !file.empty() ) {            m_CachedFileName = file;        }        else {            string dir = GetVar("_dir");            if ( dir.empty() ) {                _ASSERT(!GetParentType()); // for non internal classes                dir = GetModule()->GetFileNamePrefix();            }            m_CachedFileName =                Path(dir,                     MakeFileName(m_MemberName, 5 /* strlen("_.cpp") */ ));        }    }    return m_CachedFileName;}const CNamespace& CDataType::Namespace(void) const{    if ( !m_CachedNamespace.get() ) {        const string& ns = GetVar("_namespace");        if ( !ns.empty() ) {            m_CachedNamespace.reset(new CNamespace(ns));        }        else {            if ( GetParentType() ) {                return GetParentType()->Namespace();            }            else {                return GetModule()->GetNamespace();            }        }    }    return *m_CachedNamespace;}

⌨️ 快捷键说明

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