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

📄 stltypes.hpp

📁 ncbi源码
💻 HPP
📖 第 1 页 / 共 3 页
字号:
/* * =========================================================================== * PRODUCTION $Log: stltypes.hpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 19:39:10  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.69 * PRODUCTION * =========================================================================== */#ifndef STLTYPES__HPP#define STLTYPES__HPP/*  $Id: stltypes.hpp,v 1000.2 2004/06/01 19:39:10 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 !!!*/#include <corelib/ncbistd.hpp>#include <corelib/ncbiobj.hpp>#include <corelib/ncbiutil.hpp>#include <set>#include <map>#include <list>#include <vector>#include <memory>#include <serial/serialutil.hpp>#include <serial/stltypesimpl.hpp>#include <serial/ptrinfo.hpp>#include <serial/objistr.hpp>/** @addtogroup TypeInfoCPP * * @{ */BEGIN_NCBI_SCOPEtemplate<typename Data>class CStlClassInfo_auto_ptr{public:    typedef Data TDataType;    typedef auto_ptr<TDataType> TObjectType;    static TTypeInfo GetTypeInfo(TTypeInfo dataType)        {            return CStlClassInfoUtil::Get_auto_ptr(dataType, &CreateTypeInfo);        }    static CTypeInfo* CreateTypeInfo(TTypeInfo dataType)        {            CPointerTypeInfo* typeInfo =                new CPointerTypeInfo(sizeof(TObjectType), dataType);            typeInfo->SetFunctions(&GetData, &SetData);            return typeInfo;        }protected:    static TObjectPtr GetData(const CPointerTypeInfo* /*objectType*/,                              TObjectPtr objectPtr)        {            return CTypeConverter<TObjectType>::Get(objectPtr).get();        }    static void SetData(const CPointerTypeInfo* /*objectType*/,                        TObjectPtr objectPtr,                        TObjectPtr dataPtr)        {            CTypeConverter<TObjectType>::Get(objectPtr).                reset(&CTypeConverter<TDataType>::Get(dataPtr));        }};template<typename Data>class CRefTypeInfo{public:    typedef Data TDataType;    typedef CRef<TDataType> TObjectType;    static TTypeInfo GetTypeInfo(TTypeInfo dataType)        {            return CStlClassInfoUtil::Get_CRef(dataType, &CreateTypeInfo);        }    static CTypeInfo* CreateTypeInfo(TTypeInfo dataType)        {            CPointerTypeInfo* typeInfo =                new CPointerTypeInfo(sizeof(TObjectType), dataType);            typeInfo->SetFunctions(&GetData, &SetData);            return typeInfo;        }protected:    static TObjectPtr GetData(const CPointerTypeInfo* /*objectType*/,                              TObjectPtr objectPtr)        {            return CTypeConverter<TObjectType>::Get(objectPtr).GetPointer();        }    static void SetData(const CPointerTypeInfo* /*objectType*/,                        TObjectPtr objectPtr,                        TObjectPtr dataPtr)        {            CTypeConverter<TObjectType>::Get(objectPtr).                Reset(&CTypeConverter<TDataType>::Get(dataPtr));        }};template<typename Data>class CConstRefTypeInfo{public:    typedef Data TDataType;    typedef CConstRef<TDataType> TObjectType;    static TTypeInfo GetTypeInfo(TTypeInfo dataType)        {            return CStlClassInfoUtil::Get_CConstRef(dataType, &CreateTypeInfo);        }    static CTypeInfo* CreateTypeInfo(TTypeInfo dataType)        {            CPointerTypeInfo* typeInfo =                new CPointerTypeInfo(sizeof(TObjectType), dataType);            typeInfo->SetFunctions(&GetData, &SetData);            return typeInfo;        }protected:    static TObjectPtr GetData(const CPointerTypeInfo* /*objectType*/,                                   TObjectPtr objectPtr)        {            // Bleh.  Need to return a void* rather than a const Data*            return const_cast<TDataType*>                (CTypeConverter<TObjectType>::Get(objectPtr).GetPointer());        }    static void SetData(const CPointerTypeInfo* /*objectType*/,                        TObjectPtr objectPtr,                        TObjectPtr dataPtr)        {            CTypeConverter<TObjectType>::Get(objectPtr).                Reset(&CTypeConverter<TDataType>::Get(dataPtr));        }};template<typename Data>class CAutoPtrTypeInfo{public:    typedef Data TDataType;    typedef AutoPtr<TDataType> TObjectType;    static TTypeInfo GetTypeInfo(TTypeInfo dataType)        {            return CStlClassInfoUtil::Get_AutoPtr(dataType, &CreateTypeInfo);        }    static CTypeInfo* CreateTypeInfo(TTypeInfo dataType)        {            CPointerTypeInfo* typeInfo =                new CPointerTypeInfo(sizeof(TObjectType), dataType);            typeInfo->SetFunctions(&GetData, &SetData);            return typeInfo;        }protected:    static TObjectPtr GetData(const CPointerTypeInfo* /*objectType*/,                              TObjectPtr objectPtr)        {            return CTypeConverter<TObjectType>::Get(objectPtr).get();        }    static void SetData(const CPointerTypeInfo* /*objectType*/,                        TObjectPtr objectPtr,                        TObjectPtr dataPtr)        {            CTypeConverter<TObjectType>::Get(objectPtr).                reset(&CTypeConverter<TDataType>::Get(dataPtr));        }};template<class Container>class CStlClassInfoFunctions{public:    typedef Container TObjectType;    typedef typename TObjectType::value_type TElementType;    static TObjectType& Get(TObjectPtr objectPtr)        {            return CTypeConverter<TObjectType>::Get(objectPtr);        }    static const TObjectType& Get(TConstObjectPtr objectPtr)        {            return CTypeConverter<TObjectType>::Get(objectPtr);        }    static TObjectPtr CreateContainer(TTypeInfo /*objectType*/)        {            return new TObjectType();        }    static bool IsDefault(TConstObjectPtr objectPtr)        {            return Get(objectPtr).empty();        }    static void SetDefault(TObjectPtr objectPtr)        {            Get(objectPtr).clear();        }    static void AddElement(const CContainerTypeInfo* containerType,                           TObjectPtr containerPtr, TConstObjectPtr elementPtr,                           ESerialRecursionMode how = eRecursive)        {            TObjectType& container = Get(containerPtr);#if defined(_RWSTD_VER) && !defined(_RWSTD_STRICT_ANSI)            container.allocation_size(container.size());#endif            //container.push_back(CTypeConverter<TElementType>::Get(elementPtr));            TElementType elm;            containerType->GetElementType()->Assign                (&elm, &CTypeConverter<TElementType>::Get(elementPtr), how);            container.push_back(elm);        }    static void AddElementIn(const CContainerTypeInfo* containerType,                             TObjectPtr containerPtr, CObjectIStream& in)        {            TObjectType& container = Get(containerPtr);#if defined(_RWSTD_VER) && !defined(_RWSTD_STRICT_ANSI)            container.allocation_size(container.size());#endif            container.push_back(TElementType());            containerType->GetElementType()->ReadData(in, &container.back());            if (in.GetDiscardCurrObject()) {                container.pop_back();                in.SetDiscardCurrObject(false);            }        }    static void SetMemFunctions(CStlOneArgTemplate* info)        {            info->SetMemFunctions(&CreateContainer, &IsDefault, &SetDefault);        }    static void SetAddElementFunctions(CStlOneArgTemplate* info)        {            info->SetAddElementFunctions(&AddElement, &AddElementIn);        }};template<class Container>class CStlClassInfoFunctions_set : public CStlClassInfoFunctions<Container>{    typedef CStlClassInfoFunctions<Container> CParent;public:    typedef typename CParent::TObjectType TObjectType;    typedef typename TObjectType::value_type TElementType;    static void InsertElement(TObjectPtr containerPtr,                              const TElementType& element)        {            TObjectType& container = CParent::Get(containerPtr);#if defined(_RWSTD_VER) && !defined(_RWSTD_STRICT_ANSI)            container.allocation_size(container.size());#endif            if ( !container.insert(element).second )                CStlClassInfoUtil::ThrowDuplicateElementError();        }    static void AddElement(const CContainerTypeInfo* /*containerType*/,                           TObjectPtr containerPtr, TConstObjectPtr elementPtr,                           ESerialRecursionMode how = eRecursive)        {            InsertElement(containerPtr,                          CTypeConverter<TElementType>::Get(elementPtr));        }    static void AddElementIn(const CContainerTypeInfo* containerType,                             TObjectPtr containerPtr, CObjectIStream& in)        {            TElementType data;            containerType->GetElementType()->ReadData(in, &data);            InsertElement(containerPtr, data);        }    static void SetAddElementFunctions(CStlOneArgTemplate* info)        {            info->SetAddElementFunctions(&AddElement, &AddElementIn);        }};template<class Container>class CStlClassInfoFunctions_multiset :    public CStlClassInfoFunctions<Container>{    typedef CStlClassInfoFunctions<Container> CParent;public:    typedef typename CParent::TObjectType TObjectType;    typedef typename TObjectType::value_type TElementType;    static void InsertElement(TObjectPtr containerPtr,                              const TElementType& element)        {            TObjectType& container = CParent::Get(containerPtr);#if defined(_RWSTD_VER) && !defined(_RWSTD_STRICT_ANSI)            container.allocation_size(container.size());#endif            container.insert(element);        }    static void AddElement(const CContainerTypeInfo* /*containerType*/,                           TObjectPtr containerPtr, TConstObjectPtr elementPtr,                           ESerialRecursionMode how = eRecursive)        {            InsertElement(containerPtr,                          CTypeConverter<TElementType>::Get(elementPtr));        }

⌨️ 快捷键说明

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