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

📄 objectio.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
void CIStreamClassMemberIterator::ReadClassMember(const CObjectInfo& member){    CheckState();    GetStream().ReadSeparateObject(member);}void CIStreamClassMemberIterator::SkipClassMember(const CObjectTypeInfo& member){    CheckState();    GetStream().SkipObject(member.GetTypeInfo());}void CIStreamClassMemberIterator::SkipClassMember(void){    CheckState();    GetStream().SkipObject(GetMemberInfo()->GetTypeInfo());}/////////////////////////////////////////////////////////////////////////////// read/write class memberCOStreamClassMember::COStreamClassMember(CObjectOStream& out,                                         const CObjectTypeInfoMI& member)    : CParent(out){    const CMemberInfo* memberInfo = member.GetMemberInfo();    out.PushFrame(CObjectStackFrame::eFrameClassMember, memberInfo->GetId());    out.BeginClassMember(memberInfo->GetId());}COStreamClassMember::~COStreamClassMember(void){    if ( Good() ) {        try {            GetStream().EndClassMember();            GetStream().PopFrame();        }        catch (...) {            GetStream().SetFailFlags(CObjectIStream::fIllegalCall,                "class member write error");        }    }}// read/write containerinlinevoid CIStreamContainerIterator::BeginElement(void){    _ASSERT(m_State == eElementEnd);    if ( GetStream().BeginContainerElement(m_ElementTypeInfo) )        m_State = eElementBegin;    else        m_State = eNoMoreElements;}inlinevoid CIStreamContainerIterator::IllegalCall(const char* message) const{    GetStream().ThrowError(CObjectIStream::fIllegalCall, message);    // GetStream().SetFailFlags(CObjectIStream::fIllegalCall, message);}inlinevoid CIStreamContainerIterator::BadState(void) const{    IllegalCall("bad CIStreamContainerIterator state");}CIStreamContainerIterator::CIStreamContainerIterator(CObjectIStream& in,                                     const CObjectTypeInfo& containerType)    : CParent(in), m_ContainerType(containerType), m_State(eElementEnd){    const CContainerTypeInfo* containerTypeInfo;    if (m_ContainerType.GetTypeFamily() == eTypeFamilyClass) {        const CClassTypeInfo* classType =            CTypeConverter<CClassTypeInfo>::SafeCast(m_ContainerType.GetTypeInfo());        const CItemInfo* itemInfo =            classType->GetItems().GetItemInfo(classType->GetItems().FirstIndex());        _ASSERT(itemInfo->GetTypeInfo()->GetTypeFamily() == eTypeFamilyContainer);        containerTypeInfo =            CTypeConverter<CContainerTypeInfo>::SafeCast(itemInfo->GetTypeInfo());        in.PushFrame(CObjectStackFrame::eFrameNamed, m_ContainerType.GetTypeInfo());        in.BeginNamedType(m_ContainerType.GetTypeInfo());    } else {        containerTypeInfo = GetContainerType().GetContainerTypeInfo();    }    in.PushFrame(CObjectStackFrame::eFrameArray, containerTypeInfo);    in.BeginContainer(containerTypeInfo);        TTypeInfo elementTypeInfo = m_ElementTypeInfo =        containerTypeInfo->GetElementType();    in.PushFrame(CObjectStackFrame::eFrameArrayElement, elementTypeInfo);    BeginElement();    if ( m_State == eNoMoreElements ) {        in.PopFrame();        in.EndContainer();        in.PopFrame();        if (m_ContainerType.GetTypeFamily() == eTypeFamilyClass) {            in.EndNamedType();            in.PopFrame();        }    }}CIStreamContainerIterator::~CIStreamContainerIterator(void){    if ( Good() ) {        switch ( m_State ) {        case eNoMoreElements:            // normal state            return;        case eElementBegin:        case eElementEnd:            // not read element(s)            m_State = eError;            GetStream().SetFailFlags(CObjectIStream::fIllegalCall,                "not all elements read");            break;        default:            // error -> do nothing            return;        }    }}inlinevoid CIStreamContainerIterator::CheckState(EState state){    bool ok = (m_State == state);    if ( !ok ) {        m_State = eError;        BadState();    }}void CIStreamContainerIterator::NextElement(void){    CheckState(eElementBegin);    GetStream().EndContainerElement();    m_State = eElementEnd;    BeginElement();    if ( m_State == eNoMoreElements ) {        GetStream().PopFrame();        GetStream().EndContainer();        GetStream().PopFrame();        if (m_ContainerType.GetTypeFamily() == eTypeFamilyClass) {            GetStream().EndNamedType();            GetStream().PopFrame();        }    }}inlinevoid CIStreamContainerIterator::BeginElementData(void){    CheckState(eElementBegin);}inlinevoid CIStreamContainerIterator::BeginElementData(const CObjectTypeInfo& ){    //if ( elementType.GetTypeInfo() != GetElementTypeInfo() )    //    IllegalCall("wrong element type");    BeginElementData();}void CIStreamContainerIterator::ReadElement(const CObjectInfo& element){    BeginElementData(element);    GetStream().ReadSeparateObject(element);    NextElement();    if (m_State != eNoMoreElements) {        m_State = eElementEnd;    }}void CIStreamContainerIterator::SkipElement(const CObjectTypeInfo& elementType){    BeginElementData(elementType);    GetStream().SkipObject(elementType.GetTypeInfo());    NextElement();    if (m_State != eNoMoreElements) {        m_State = eElementEnd;    }}void CIStreamContainerIterator::SkipElement(void){    BeginElementData();    GetStream().SkipObject(m_ElementTypeInfo);    NextElement();    if (m_State != eNoMoreElements) {        m_State = eElementEnd;    }}CIStreamContainerIterator& CIStreamContainerIterator::operator++(void){    if (m_State == eElementBegin) {        SkipElement();    }    if (m_State != eNoMoreElements) {        CheckState(eElementEnd);        m_State = eElementBegin;    }    else {        m_State = eFinished;    }    return *this;}COStreamContainer::COStreamContainer(CObjectOStream& out,                                     const CObjectTypeInfo& containerType)    : CParent(out), m_ContainerType(containerType){    const CContainerTypeInfo* containerTypeInfo;    if (m_ContainerType.GetTypeFamily() == eTypeFamilyClass) {        const CClassTypeInfo* classType =            CTypeConverter<CClassTypeInfo>::SafeCast(m_ContainerType.GetTypeInfo());        const CItemInfo* itemInfo =            classType->GetItems().GetItemInfo(classType->GetItems().FirstIndex());        _ASSERT(itemInfo->GetTypeInfo()->GetTypeFamily() == eTypeFamilyContainer);        containerTypeInfo =            CTypeConverter<CContainerTypeInfo>::SafeCast(itemInfo->GetTypeInfo());        out.PushFrame(CObjectStackFrame::eFrameNamed, m_ContainerType.GetTypeInfo());        out.BeginNamedType(m_ContainerType.GetTypeInfo());    } else {        containerTypeInfo = GetContainerType().GetContainerTypeInfo();    }    out.PushFrame(CObjectStackFrame::eFrameArray, containerTypeInfo);    out.BeginContainer(containerTypeInfo);    TTypeInfo elementTypeInfo = m_ElementTypeInfo =        containerTypeInfo->GetElementType();    out.PushFrame(CObjectStackFrame::eFrameArrayElement, elementTypeInfo);}COStreamContainer::~COStreamContainer(void){    if ( Good() ) {        try {            GetStream().PopFrame();            GetStream().EndContainer();            GetStream().PopFrame();            if (m_ContainerType.GetTypeFamily() == eTypeFamilyClass) {                GetStream().EndNamedType();                GetStream().PopFrame();            }        }        catch (...) {            GetStream().SetFailFlags(CObjectOStream::fIllegalCall,                "container write error");        }    }}void COStreamContainer::WriteElement(const CConstObjectInfo& element){    GetStream().BeginContainerElement(m_ElementTypeInfo);    GetStream().WriteSeparateObject(element);    GetStream().EndContainerElement();}END_NCBI_SCOPE

⌨️ 快捷键说明

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