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

📄 continfo.cpp

📁 ncbi源码
💻 CPP
字号:
/* * =========================================================================== * PRODUCTION $Log: continfo.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 19:40:02  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.12 * PRODUCTION * =========================================================================== *//*  $Id: continfo.cpp,v 1000.2 2004/06/01 19:40:02 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:*   !!! PUT YOUR DESCRIPTION HERE !!!** ---------------------------------------------------------------------------* $Log: continfo.cpp,v $* Revision 1000.2  2004/06/01 19:40:02  gouriano* PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.12** Revision 1.12  2004/05/19 17:27:52  gouriano* Reset the contents of container when assigning** Revision 1.11  2004/05/17 21:03:02  gorelenk* Added include of PCH ncbi_pch.hpp** Revision 1.10  2004/03/25 15:57:08  gouriano* Added possibility to copy and compare serial object non-recursively** Revision 1.9  2003/08/14 20:03:58  vasilche* Avoid memory reallocation when reading over preallocated object.* Simplified CContainerTypeInfo iterators interface.** Revision 1.8  2003/03/10 18:54:25  gouriano* use new structured exceptions (based on CException)** Revision 1.7  2002/10/08 18:59:38  grichenk* Check for null pointers in containers (assert in debug mode,* warning in release).** Revision 1.6  2000/10/17 18:45:33  vasilche* Added possibility to turn off object cross reference detection in* CObjectIStream and CObjectOStream.** Revision 1.5  2000/10/13 16:28:39  vasilche* Reduced header dependency.* Avoid use of templates with virtual methods.* Reduced amount of different maps used.* All this lead to smaller compiled code size (libraries and programs).** Revision 1.4  2000/09/18 20:00:21  vasilche* Separated CVariantInfo and CMemberInfo.* Implemented copy hooks.* All hooks now are stored in CTypeInfo/CMemberInfo/CVariantInfo.* Most type specific functions now are implemented via function pointers instead of virtual functions.** Revision 1.3  2000/09/13 15:10:15  vasilche* Fixed type detection in type iterators.** Revision 1.2  2000/09/01 13:16:15  vasilche* Implemented class/container/choice iterators.* Implemented CObjectStreamCopier for copying data without loading into memory.** Revision 1.1  2000/07/03 18:42:43  vasilche* Added interface to typeinfo via CObjectInfo and CConstObjectInfo.* Reduced header dependency.** ===========================================================================*/#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <corelib/ncbiutil.hpp>#include <serial/continfo.hpp>#include <serial/objistr.hpp>#include <serial/objostr.hpp>#include <serial/objcopy.hpp>#include <serial/serialutil.hpp>BEGIN_NCBI_SCOPECContainerTypeInfo::CContainerTypeInfo(size_t size,                                       TTypeInfo elementType,                                       bool randomOrder)    : CParent(eTypeFamilyContainer, size),      m_ElementType(elementType), m_RandomOrder(randomOrder){    InitContainerTypeInfoFunctions();}CContainerTypeInfo::CContainerTypeInfo(size_t size,                                       const CTypeRef& elementType,                                       bool randomOrder)    : CParent(eTypeFamilyContainer, size),      m_ElementType(elementType), m_RandomOrder(randomOrder){    InitContainerTypeInfoFunctions();}CContainerTypeInfo::CContainerTypeInfo(size_t size, const char* name,                                       TTypeInfo elementType,                                       bool randomOrder)    : CParent(eTypeFamilyContainer, size, name),      m_ElementType(elementType), m_RandomOrder(randomOrder){    InitContainerTypeInfoFunctions();}CContainerTypeInfo::CContainerTypeInfo(size_t size, const char* name,                                       const CTypeRef& elementType,                                       bool randomOrder)    : CParent(eTypeFamilyContainer, size, name),      m_ElementType(elementType), m_RandomOrder(randomOrder){    InitContainerTypeInfoFunctions();}CContainerTypeInfo::CContainerTypeInfo(size_t size, const string& name,                                       TTypeInfo elementType,                                       bool randomOrder)    : CParent(eTypeFamilyContainer, size, name),      m_ElementType(elementType), m_RandomOrder(randomOrder){    InitContainerTypeInfoFunctions();}CContainerTypeInfo::CContainerTypeInfo(size_t size, const string& name,                                       const CTypeRef& elementType,                                       bool randomOrder)    : CParent(eTypeFamilyContainer, size, name),      m_ElementType(elementType), m_RandomOrder(randomOrder){    InitContainerTypeInfoFunctions();}class CContainerTypeInfoFunctions{public:    static void Throw(const char* message)        {            NCBI_THROW(CSerialException,eFail, message);        }    static bool InitIteratorConst(CContainerTypeInfo::CConstIterator&)        {            Throw("cannot create iterator");            return false;        }    static bool InitIterator(CContainerTypeInfo::CIterator&)        {            Throw("cannot create iterator");            return false;        }    static void AddElement(const CContainerTypeInfo* /*containerType*/,                           TObjectPtr /*containerPtr*/,                           TConstObjectPtr /*elementPtr*/,                           ESerialRecursionMode)        {            Throw("illegal call");        }        static void AddElementIn(const CContainerTypeInfo* /*containerType*/,                             TObjectPtr /*containerPtr*/,                             CObjectIStream& /*in*/)        {            Throw("illegal call");        }};void CContainerTypeInfo::InitContainerTypeInfoFunctions(void){    SetReadFunction(&ReadContainer);    SetWriteFunction(&WriteContainer);    SetCopyFunction(&CopyContainer);    SetSkipFunction(&SkipContainer);    m_InitIteratorConst = &CContainerTypeInfoFunctions::InitIteratorConst;    m_InitIterator = &CContainerTypeInfoFunctions::InitIterator;    m_AddElement = &CContainerTypeInfoFunctions::AddElement;    m_AddElementIn = &CContainerTypeInfoFunctions::AddElementIn;}void CContainerTypeInfo::SetAddElementFunctions(TAddElement addElement,                                                TAddElementIn addElementIn){    m_AddElement = addElement;    m_AddElementIn = addElementIn;}void CContainerTypeInfo::SetConstIteratorFunctions(TInitIteratorConst init,                                                   TReleaseIteratorConst release,                                                   TCopyIteratorConst copy,                                                   TNextElementConst next,                                                   TGetElementPtrConst get){    m_InitIteratorConst = init;    m_ReleaseIteratorConst = release;    m_CopyIteratorConst = copy;    m_NextElementConst = next;    m_GetElementPtrConst = get;}void CContainerTypeInfo::SetIteratorFunctions(TInitIterator init,                                              TReleaseIterator release,                                              TCopyIterator copy,                                              TNextElement next,                                              TGetElementPtr get,                                              TEraseElement erase,                                              TEraseAllElements erase_all){    m_InitIterator = init;    m_ReleaseIterator = release;    m_CopyIterator = copy;    m_NextElement = next;    m_GetElementPtr = get;    m_EraseElement = erase;    m_EraseAllElements = erase_all;}bool CContainerTypeInfo::MayContainType(TTypeInfo type) const{    return GetElementType()->IsOrMayContainType(type);}void CContainerTypeInfo::Assign(TObjectPtr dst, TConstObjectPtr src,                                ESerialRecursionMode how) const{    //SetDefault(dst); // clear destination container    if (how == eShallowChildless) {        return;    }    CIterator idst;    CConstIterator isrc;    bool old_element = InitIterator(idst,dst);    if ( InitIterator(isrc, src) ) {        do {            if (GetElementType()->GetTypeFamily() == eTypeFamilyPointer) {                const CPointerTypeInfo* pointerType =                    CTypeConverter<CPointerTypeInfo>::SafeCast(GetElementType());                _ASSERT(pointerType->GetObjectPointer(GetElementPtr(isrc)));                if ( !pointerType->GetObjectPointer(GetElementPtr(isrc)) ) {                    ERR_POST(Warning << " NULL pointer found in container: skipping");                    continue;                }            }            if (old_element) {                GetElementType()->Assign(GetElementPtr(idst), GetElementPtr(isrc), how);                old_element = NextElement(idst);            } else {                AddElement(dst, GetElementPtr(isrc), how);            }        } while ( NextElement(isrc) );    }    if (old_element) {        EraseAllElements(idst);    }}bool CContainerTypeInfo::Equals(TConstObjectPtr object1, TConstObjectPtr object2,                                ESerialRecursionMode how) const{    if (how == eShallowChildless) {        return true;    }    TTypeInfo elementType = GetElementType();    CConstIterator i1, i2;    if ( InitIterator(i1, object1) ) {        if ( !InitIterator(i2, object2) )            return false;        if ( !elementType->Equals(GetElementPtr(i1),                                  GetElementPtr(i2), how) )            return false;        while ( NextElement(i1) ) {            if ( !NextElement(i2) )                return false;            if ( !elementType->Equals(GetElementPtr(i1),                                      GetElementPtr(i2), how) )                return false;        }        return !NextElement(i2);    }    else {        return !InitIterator(i2, object2);    }}void CContainerTypeInfo::ReadContainer(CObjectIStream& in,                                       TTypeInfo objectType,                                       TObjectPtr objectPtr){    const CContainerTypeInfo* containerType =        CTypeConverter<CContainerTypeInfo>::SafeCast(objectType);    in.ReadContainer(containerType, objectPtr);}void CContainerTypeInfo::WriteContainer(CObjectOStream& out,                                        TTypeInfo objectType,                                        TConstObjectPtr objectPtr){    const CContainerTypeInfo* containerType =        CTypeConverter<CContainerTypeInfo>::SafeCast(objectType);    out.WriteContainer(containerType, objectPtr);}void CContainerTypeInfo::CopyContainer(CObjectStreamCopier& copier,                                       TTypeInfo objectType){    const CContainerTypeInfo* containerType =        CTypeConverter<CContainerTypeInfo>::SafeCast(objectType);    copier.CopyContainer(containerType);}void CContainerTypeInfo::SkipContainer(CObjectIStream& in,                                       TTypeInfo objectType){    const CContainerTypeInfo* containerType =        CTypeConverter<CContainerTypeInfo>::SafeCast(objectType);    in.SkipContainer(containerType);}END_NCBI_SCOPE

⌨️ 快捷键说明

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