📄 variant.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: variant.cpp,v $ * PRODUCTION Revision 1000.2 2004/06/01 19:42:08 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.14 * PRODUCTION * =========================================================================== *//* $Id: variant.cpp,v 1000.2 2004/06/01 19:42:08 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 <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <corelib/ncbimtx.hpp>#include <serial/variant.hpp>#include <serial/objectinfo.hpp>#include <serial/objectiter.hpp>#include <serial/objistr.hpp>#include <serial/objostr.hpp>#include <serial/objcopy.hpp>#include <serial/delaybuf.hpp>#include <serial/choiceptr.hpp>#include <serial/ptrinfo.hpp>#include <serial/serialimpl.hpp>BEGIN_NCBI_SCOPEclass CVariantInfoFunctions{public: static TConstObjectPtr GetConstInlineVariant(const CVariantInfo* variantInfo, TConstObjectPtr choicePtr); static TConstObjectPtr GetConstPointerVariant(const CVariantInfo* variantInfo, TConstObjectPtr choicePtr); static TConstObjectPtr GetConstDelayedVariant(const CVariantInfo* variantInfo, TConstObjectPtr choicePtr); static TConstObjectPtr GetConstSubclassVariant(const CVariantInfo* variantInfo, TConstObjectPtr choicePtr); static TObjectPtr GetInlineVariant(const CVariantInfo* variantInfo, TObjectPtr choicePtr); static TObjectPtr GetPointerVariant(const CVariantInfo* variantInfo, TObjectPtr choicePtr); static TObjectPtr GetDelayedVariant(const CVariantInfo* variantInfo, TObjectPtr choicePtr); static TObjectPtr GetSubclassVariant(const CVariantInfo* variantInfo, TObjectPtr choicePtr); static void ReadInlineVariant(CObjectIStream& in, const CVariantInfo* variantInfo, TObjectPtr choicePtr); static void ReadPointerVariant(CObjectIStream& in, const CVariantInfo* variantInfo, TObjectPtr choicePtr); static void ReadObjectPointerVariant(CObjectIStream& in, const CVariantInfo* variantInfo, TObjectPtr choicePtr); static void ReadDelayedVariant(CObjectIStream& in, const CVariantInfo* variantInfo, TObjectPtr choicePtr); static void ReadSubclassVariant(CObjectIStream& in, const CVariantInfo* variantInfo, TObjectPtr choicePtr); static void ReadHookedVariant(CObjectIStream& in, const CVariantInfo* variantInfo, TObjectPtr choicePtr); static void WriteInlineVariant(CObjectOStream& out, const CVariantInfo* variantInfo, TConstObjectPtr choicePtr); static void WritePointerVariant(CObjectOStream& out, const CVariantInfo* variantInfo, TConstObjectPtr choicePtr); static void WriteObjectPointerVariant(CObjectOStream& out, const CVariantInfo* variantInfo, TConstObjectPtr choicePtr); static void WriteSubclassVariant(CObjectOStream& out, const CVariantInfo* variantInfo, TConstObjectPtr choicePtr); static void WriteDelayedVariant(CObjectOStream& out, const CVariantInfo* variantInfo, TConstObjectPtr choicePtr); static void WriteHookedVariant(CObjectOStream& out, const CVariantInfo* variantInfo, TConstObjectPtr choicePtr); static void SkipNonObjectVariant(CObjectIStream& in, const CVariantInfo* variantInfo); static void SkipObjectPointerVariant(CObjectIStream& in, const CVariantInfo* variantInfo); static void SkipHookedVariant(CObjectIStream& in, const CVariantInfo* variantInfo); static void CopyNonObjectVariant(CObjectStreamCopier& copier, const CVariantInfo* variantInfo); static void CopyObjectPointerVariant(CObjectStreamCopier& copier, const CVariantInfo* variantInfo); static void CopyHookedVariant(CObjectStreamCopier& copier, const CVariantInfo* variantInfo);};typedef CVariantInfoFunctions TFunc;CVariantInfo::CVariantInfo(const CChoiceTypeInfo* choiceType, const CMemberId& id, TPointerOffsetType offset, const CTypeRef& type) : CParent(id, offset, type), m_ChoiceType(choiceType), m_VariantType(eInlineVariant), m_DelayOffset(eNoOffset), m_GetConstFunction(&TFunc::GetConstInlineVariant), m_GetFunction(&TFunc::GetInlineVariant), m_ReadHookData(&TFunc::ReadInlineVariant, &TFunc::ReadHookedVariant), m_WriteHookData(&TFunc::WriteInlineVariant, &TFunc::WriteHookedVariant), m_SkipHookData(&TFunc::SkipNonObjectVariant, &TFunc::SkipHookedVariant), m_CopyHookData(&TFunc::CopyNonObjectVariant, &TFunc::CopyHookedVariant){}CVariantInfo::CVariantInfo(const CChoiceTypeInfo* choiceType, const CMemberId& id, TPointerOffsetType offset, TTypeInfo type) : CParent(id, offset, type), m_ChoiceType(choiceType), m_VariantType(eInlineVariant), m_DelayOffset(eNoOffset), m_GetConstFunction(&TFunc::GetConstInlineVariant), m_GetFunction(&TFunc::GetInlineVariant), m_ReadHookData(&TFunc::ReadInlineVariant, &TFunc::ReadHookedVariant), m_WriteHookData(&TFunc::WriteInlineVariant, &TFunc::WriteHookedVariant), m_SkipHookData(&TFunc::SkipNonObjectVariant, &TFunc::SkipHookedVariant), m_CopyHookData(&TFunc::CopyNonObjectVariant, &TFunc::CopyHookedVariant){}CVariantInfo::CVariantInfo(const CChoiceTypeInfo* choiceType, const char* id, TPointerOffsetType offset, const CTypeRef& type) : CParent(id, offset, type), m_ChoiceType(choiceType), m_VariantType(eInlineVariant), m_DelayOffset(eNoOffset), m_GetConstFunction(&TFunc::GetConstInlineVariant), m_GetFunction(&TFunc::GetInlineVariant), m_ReadHookData(&TFunc::ReadInlineVariant, &TFunc::ReadHookedVariant), m_WriteHookData(&TFunc::WriteInlineVariant, &TFunc::WriteHookedVariant), m_SkipHookData(&TFunc::SkipNonObjectVariant, &TFunc::SkipHookedVariant), m_CopyHookData(&TFunc::CopyNonObjectVariant, &TFunc::CopyHookedVariant){}CVariantInfo::CVariantInfo(const CChoiceTypeInfo* choiceType, const char* id, TPointerOffsetType offset, TTypeInfo type) : CParent(id, offset, type), m_ChoiceType(choiceType), m_VariantType(eInlineVariant), m_DelayOffset(eNoOffset), m_GetConstFunction(&TFunc::GetConstInlineVariant), m_GetFunction(&TFunc::GetInlineVariant), m_ReadHookData(&TFunc::ReadInlineVariant, &TFunc::ReadHookedVariant), m_WriteHookData(&TFunc::WriteInlineVariant, &TFunc::WriteHookedVariant), m_SkipHookData(&TFunc::SkipNonObjectVariant, &TFunc::SkipHookedVariant), m_CopyHookData(&TFunc::CopyNonObjectVariant, &TFunc::CopyHookedVariant){}CVariantInfo* CVariantInfo::SetPointer(void){ if ( !IsInline() ) { NCBI_THROW(CSerialException,eIllegalCall, "SetPointer() is not first call"); } m_VariantType = eNonObjectPointerVariant; UpdateFunctions(); return this;}CVariantInfo* CVariantInfo::SetObjectPointer(void){ if ( !IsInline() ) { NCBI_THROW(CSerialException,eIllegalCall, "SetObjectPointer() is not first call"); } m_VariantType = eObjectPointerVariant; UpdateFunctions(); return this;}CVariantInfo* CVariantInfo::SetSubClass(void){ if ( !IsInline() ) { NCBI_THROW(CSerialException,eIllegalCall, "SetSubClass() is not first call"); } if ( CanBeDelayed() ) { NCBI_THROW(CSerialException,eIllegalCall, "sub class cannot be delayed"); } m_VariantType = eSubClassVariant; UpdateFunctions(); return this;}CVariantInfo* CVariantInfo::SetDelayBuffer(CDelayBuffer* buffer){ if ( IsSubClass() ) { NCBI_THROW(CSerialException,eIllegalCall, "sub class cannot be delayed"); } m_DelayOffset = TPointerOffsetType(buffer); UpdateFunctions(); return this;}void CVariantInfo::UpdateFunctions(void){ // determine function pointers TVariantGetConst getConstFunc; TVariantGet getFunc; TVariantReadFunction readFunc; TVariantWriteFunction writeFunc; TVariantSkipFunction skipFunc; TVariantCopyFunction copyFunc; // read/write/get if ( CanBeDelayed() ) { _ASSERT(!IsSubClass()); getConstFunc = &TFunc::GetConstDelayedVariant; getFunc = &TFunc::GetDelayedVariant; readFunc = &TFunc::ReadDelayedVariant; writeFunc = &TFunc::WriteDelayedVariant; } else if ( IsInline() ) { getConstFunc = &TFunc::GetConstInlineVariant; getFunc = &TFunc::GetInlineVariant; readFunc = &TFunc::ReadInlineVariant; writeFunc = &TFunc::WriteInlineVariant; } else if ( IsObjectPointer() ) { getConstFunc = &TFunc::GetConstPointerVariant; getFunc = &TFunc::GetPointerVariant; readFunc = &TFunc::ReadObjectPointerVariant; writeFunc = &TFunc::WriteObjectPointerVariant; } else if ( IsNonObjectPointer() ) { getConstFunc = &TFunc::GetConstPointerVariant; getFunc = &TFunc::GetPointerVariant; readFunc = &TFunc::ReadPointerVariant; writeFunc = &TFunc::WritePointerVariant; } else { // subclass getConstFunc = &TFunc::GetConstSubclassVariant; getFunc = &TFunc::GetSubclassVariant; readFunc = &TFunc::ReadSubclassVariant; writeFunc = &TFunc::WriteSubclassVariant; } // copy/skip if ( IsObject() ) { copyFunc = &TFunc::CopyObjectPointerVariant; skipFunc = &TFunc::SkipObjectPointerVariant; } else { copyFunc = &TFunc::CopyNonObjectVariant; skipFunc = &TFunc::SkipNonObjectVariant; } // update function pointers m_GetConstFunction = getConstFunc; m_GetFunction = getFunc; m_ReadHookData.SetDefaultFunction(readFunc); m_WriteHookData.SetDefaultFunction(writeFunc); m_SkipHookData.SetDefaultFunction(skipFunc); m_CopyHookData.SetDefaultFunction(copyFunc);}void CVariantInfo::UpdateDelayedBuffer(CObjectIStream& in, TObjectPtr choicePtr) const{ _ASSERT(CanBeDelayed()); _ASSERT(GetDelayBuffer(choicePtr).GetIndex() == GetIndex()); TObjectPtr variantPtr = GetItemPtr(choicePtr); TTypeInfo variantType = GetTypeInfo(); if ( IsPointer() ) { // create object itself variantPtr = CTypeConverter<TObjectPtr>::Get(variantPtr) = variantType->Create(); if ( IsObjectPointer() ) { _TRACE("Should check for real pointer type (CRef...)"); CTypeConverter<CObject>::Get(variantPtr).AddReference(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -