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

📄 choicestr.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/* * =========================================================================== * PRODUCTION $Log: choicestr.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 19:42:27  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.50 * PRODUCTION * =========================================================================== *//*  $Id: choicestr.cpp,v 1000.2 2004/06/01 19:42:27 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:*   Type info for class generation: includes, used classes, C code etc.** ---------------------------------------------------------------------------* $Log: choicestr.cpp,v $* Revision 1000.2  2004/06/01 19:42:27  gouriano* PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.50** Revision 1.50  2004/05/17 21:03:13  gorelenk* Added include of PCH ncbi_pch.hpp** Revision 1.49  2004/05/03 19:31:03  gouriano* Made generation of DOXYGEN-style comments optional** Revision 1.48  2004/04/29 20:11:40  gouriano* Generate DOXYGEN-style comments in C++ headers** Revision 1.47  2003/11/20 14:32:40  gouriano* changed generated C++ code so NULL data types have no value** Revision 1.46  2003/10/21 13:48:51  grichenk* Redesigned type aliases in serialization library.* Fixed the code (removed CRef-s, added explicit* initializers etc.)** Revision 1.45  2003/10/06 18:40:15  grichenk* Added e_MaxChoice enum** Revision 1.44  2003/05/08 16:59:08  gouriano* added comment about the meaning of typedef for each class member** Revision 1.43  2003/04/29 18:31:09  gouriano* object data member initialization verification** Revision 1.42  2003/03/11 20:06:47  kuznets* iterate -> ITERATE** Revision 1.41  2003/03/11 17:59:16  gouriano* reimplement CInvalidChoiceSelection exception** Revision 1.40  2003/03/10 21:21:10  gouriano* use CSerialException in generated code** Revision 1.39  2003/03/10 18:55:18  gouriano* use new structured exceptions (based on CException)** Revision 1.38  2003/02/12 21:39:52  gouriano* corrected code generator so primitive data types (bool,int,etc)* are returned by value, not by reference** Revision 1.37  2002/11/19 19:48:28  gouriano* added support of XML attributes of choice variants** Revision 1.36  2002/11/18 19:48:46  grichenk* Removed "const" from datatool-generated setters** Revision 1.35  2002/11/14 21:03:40  gouriano* added support of XML attribute lists** Revision 1.34  2002/10/15 13:58:04  gouriano* use "noprefix" flag** Revision 1.33  2002/08/14 17:14:25  grichenk* Fixed function name conflict on Win32: renamed* GetClassName() -> GetClassNameDT()** Revision 1.32  2002/07/25 15:02:41  grichenk* Removed non-const GetXXX() method, use SetXXX() instead** Revision 1.31  2002/05/15 20:22:04  grichenk* Added CSerialObject -- base class for all generated ASN.1 classes** Revision 1.30  2002/01/16 18:56:34  grichenk* Removed CRef<> argument from choice variant setter, updated sources to* use references instead of CRef<>s** Revision 1.29  2001/06/21 19:47:39  grichenk* Copy constructor and operator=() moved to "private" section** Revision 1.28  2001/06/13 14:40:02  grichenk* Modified class and choice info generation code to avoid warnings** Revision 1.27  2001/06/11 14:35:02  grichenk* Added support for numeric tags in ASN.1 specifications and data streams.** Revision 1.26  2001/05/17 15:07:11  lavr* Typos corrected** Revision 1.25  2000/11/29 17:42:42  vasilche* Added CComment class for storing/printing ASN.1/XML module comments.* Added srcutil.hpp file to reduce file dependency.** Revision 1.24  2000/11/07 17:26:24  vasilche* Added module names to CTypeInfo and CEnumeratedTypeValues* Added possibility to set include directory for whole module** Revision 1.23  2000/08/28 13:22:03  vasilche* Fixed reference to undefined kEmptyChoice.** Revision 1.22  2000/08/25 15:59:20  vasilche* Renamed directory tool -> datatool.** Revision 1.21  2000/07/11 20:36:28  vasilche* Removed unnecessary generation of namespace references for enum members.* Removed obsolete methods.** Revision 1.20  2000/07/03 18:42:57  vasilche* Added interface to typeinfo via CObjectInfo and CConstObjectInfo.** Revision 1.19  2000/06/27 16:34:48  vasilche* Fixed generated comments.* Fixed class names conflict. Now internal classes' names begin with "C_".** Revision 1.18  2000/06/16 16:31:37  vasilche* Changed implementation of choices and classes info to allow use of the same classes in generated and user written classes.** Revision 1.17  2000/05/03 14:38:17  vasilche* SERIAL: added support for delayed reading to generated classes.* DATATOOL: added code generation for delayed reading.** Revision 1.16  2000/04/17 19:11:07  vasilche* Fixed failed assertion.* Removed redundant namespace specifications.** Revision 1.15  2000/04/12 15:36:48  vasilche* Added -on <namespace> argument to datatool.* Removed unnecessary namespace specifications in generated files.** Revision 1.14  2000/04/07 19:26:23  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.13  2000/04/06 16:11:25  vasilche* Removed unneeded calls to Reset().** Revision 1.12  2000/04/03 18:47:29  vasilche* Added main include file for generated headers.* serialimpl.hpp is included in generated sources with GetTypeInfo methods** Revision 1.11  2000/03/29 15:52:25  vasilche* Generated files names limited to 31 symbols due to limitations of Mac.* Removed unions with only one member.** Revision 1.10  2000/03/17 16:49:54  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.9  2000/03/08 14:40:00  vasilche* Renamed NewInstance() -> New().** Revision 1.8  2000/03/07 20:04:59  vasilche* Added NewInstance method to generated classes.** Revision 1.7  2000/03/07 14:06:30  vasilche* Added generation of reference counted objects.** Revision 1.6  2000/02/17 20:05:06  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.5  2000/02/11 17:09:30  vasilche* Removed unneeded flags.** Revision 1.4  2000/02/03 21:58:30  vasilche* Fixed tipo leading to memory leak in generated files.** Revision 1.3  2000/02/03 20:16:15  vasilche* Fixed bug in type info generation for templates.** Revision 1.2  2000/02/02 14:57:06  vasilche* Added missing NCBI_NS_NCBI and NCBI_NS_STD macros to generated code.** Revision 1.1  2000/02/01 21:47:54  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.8  2000/01/10 19:46:47  vasilche* Fixed encoding/decoding of REAL type.* Fixed encoding/decoding of StringStore.* Fixed encoding/decoding of NULL type.* Fixed error reporting.* Reduced object map (only classes).** Revision 1.7  1999/12/28 18:56:00  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.6  1999/12/17 19:05:19  vasilche* Simplified generation of GetTypeInfo methods.** Revision 1.5  1999/12/01 17:36:28  vasilche* Fixed CHOICE processing.** Revision 1.4  1999/11/18 17:13:07  vasilche* Fixed generation of ENUMERATED CHOICE and VisibleString.* Added generation of initializers to zero for primitive types and pointers.** Revision 1.3  1999/11/16 15:41:17  vasilche* Added plain pointer choice.* By default we use C pointer instead of auto_ptr.* Start adding initializers.** Revision 1.2  1999/11/15 19:36:20  vasilche* Fixed warnings on GCC** ===========================================================================*/#include <ncbi_pch.hpp>#include <corelib/ncbiutil.hpp>#include <serial/datatool/exceptions.hpp>#include <serial/datatool/type.hpp>#include <serial/datatool/choicestr.hpp>#include <serial/datatool/stdstr.hpp>#include <serial/datatool/code.hpp>#include <serial/datatool/srcutil.hpp>#include <serial/serialdef.hpp>BEGIN_NCBI_SCOPE#define STATE_ENUM "E_Choice"#define STATE_MEMBER "m_choice"#define STRING_TYPE_FULL "NCBI_NS_STD::string"#define STRING_TYPE "string"#define STRING_MEMBER "m_string"#define OBJECT_TYPE_FULL "NCBI_NS_NCBI::CSerialObject"#define OBJECT_TYPE "CSerialObject"#define OBJECT_MEMBER "m_object"#define STATE_PREFIX "e_"#define STATE_NOT_SET "e_not_set"#define DELAY_MEMBER "m_delayBuffer"#define DELAY_TYPE_FULL "NCBI_NS_NCBI::CDelayBuffer"CChoiceTypeStrings::CChoiceTypeStrings(const string& externalName,                                       const string& className)    : CParent(externalName, className),      m_HaveAssignment(false){}CChoiceTypeStrings::~CChoiceTypeStrings(void){}void CChoiceTypeStrings::AddVariant(const string& name,                                    const AutoPtr<CTypeStrings>& type,                                    bool delayed, int tag,                                    bool noPrefix, bool attlist, bool noTag,                                    bool simple, const CDataType* dataType){    m_Variants.push_back(SVariantInfo(name, type, delayed, tag,                                      noPrefix,attlist,noTag,simple,dataType));}CChoiceTypeStrings::SVariantInfo::SVariantInfo(const string& name,                                               const AutoPtr<CTypeStrings>& t,                                               bool del, int tag,                                               bool noPrefx, bool attlst,                                               bool noTg,bool simpl,                                               const CDataType* dataTp)    : externalName(name), cName(Identifier(name)),      type(t), delayed(del), memberTag(tag),      noPrefix(noPrefx), attlist(attlst), noTag(noTg), simple(simpl),      dataType(dataTp){    switch ( type->GetKind() ) {    case eKindString:        memberType = eStringMember;        break;    case eKindStd:    case eKindEnum:        memberType = eSimpleMember;        break;    case eKindObject:        memberType = eObjectPointerMember;        break;    case eKindPointer:    case eKindRef:        ERR_POST("pointer as choice variant");        memberType = ePointerMember;        break;    default:        memberType = ePointerMember;        break;    }}bool CChoiceTypeStrings::x_IsNullType(TVariants::const_iterator i) const{    return (dynamic_cast<CNullTypeStrings*>(i->type.get()) != 0);}bool CChoiceTypeStrings::x_IsNullWithAttlist(TVariants::const_iterator i) const{    if (i->dataType) {        const CDataType* resolved = i->dataType->Resolve();        if (resolved && resolved != i->dataType) {            CClassTypeStrings* typeStr = resolved->GetTypeStr();            if (typeStr) {                ITERATE ( TMembers, ir, typeStr->m_Members ) {                    if (ir->simple) {                        return CClassTypeStrings::x_IsNullType(ir);                    }                }            }        }    }    return false;}void CChoiceTypeStrings::GenerateClassCode(CClassCode& code,                                           CNcbiOstream& setters,                                           const string& methodPrefix,                                           bool haveUserClass,                                           const string& classPrefix) const{    bool haveObjectPointer = false;    bool havePointers = false;    bool haveSimple = false;    bool haveString = false;    bool delayed = false;    bool haveAttlist = false;    string codeClassName = GetClassNameDT();    if ( haveUserClass )        codeClassName += "_Base";    // generate variants code    {        ITERATE ( TVariants, i, m_Variants ) {

⌨️ 快捷键说明

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