void CObjectOStream::WritePointer(TConstObjectPtr objectPtr, TTypeInfo declaredTypeInfo) { _TRACE("WritePointer("<<NStr::PtrToString(objectPtr)<<", " <<declaredTypeInfo->GetName()<<")"); if ( objectPtr == 0 ) { _TRACE("WritePointer: "<<NStr::PtrToString(objectPtr)<<": null"); WriteNullPointer(); return; } TTypeInfo realTypeInfo = declaredTypeInfo->GetRealTypeInfo(objectPtr); if ( m_Objects ) { const CWriteObjectInfo* info = m_Objects->RegisterObject(objectPtr, realTypeInfo); if ( info ) { // old object WriteObjectReference(info->GetIndex()); return; } } if ( declaredTypeInfo == realTypeInfo ) { _TRACE("WritePointer: "<<NStr::PtrToString(objectPtr)<<": new"); WriteThis(objectPtr, realTypeInfo); } else { _TRACE("WritePointer: "<<NStr::PtrToString(objectPtr)<< ": new "<<realTypeInfo->GetName()); WriteOther(objectPtr, realTypeInfo); } }
void CObjectOStreamAsn::WriteFileHeader(TTypeInfo type) { if ( true || m_Output.ZeroIndentLevel() ) { WriteId(type->GetName()); m_Output.PutString(" ::= "); } }
void CObjectOStream::WriteExternalObject(TConstObjectPtr objectPtr, TTypeInfo typeInfo) { _TRACE("CObjectOStream::WriteExternalObject(" << NStr::PtrToString(objectPtr) << ", " << typeInfo->GetName() << ')'); RegisterObject(objectPtr, typeInfo); WriteObject(objectPtr, typeInfo); }
void CChoicePointerTypeInfo::SetPointerType(TTypeInfo base) { m_NullPointerIndex = kEmptyChoice; if ( base->GetTypeFamily() != eTypeFamilyPointer ) NCBI_THROW(CSerialException,eInvalidData, "invalid argument: must be CPointerTypeInfo"); const CPointerTypeInfo* ptrType = CTypeConverter<CPointerTypeInfo>::SafeCast(base); m_PointerTypeInfo = ptrType; if ( ptrType->GetPointedType()->GetTypeFamily() != eTypeFamilyClass ) NCBI_THROW(CSerialException,eInvalidData, "invalid argument: data must be CClassTypeInfo"); const CClassTypeInfo* classType = CTypeConverter<CClassTypeInfo>::SafeCast(ptrType->GetPointedType()); /* Do we really need it to be CObject??? if ( !classType->IsCObject() ) NCBI_THROW(CSerialException,eInvalidData, "invalid argument:: choice ptr type must be CObject"); */ const CClassTypeInfo::TSubClasses* subclasses = classType->SubClasses(); if ( !subclasses ) return; TTypeInfo nullTypeInfo = CNullTypeInfo::GetTypeInfo(); for ( CClassTypeInfo::TSubClasses::const_iterator i = subclasses->begin(); i != subclasses->end(); ++i ) { TTypeInfo variantType = i->second.Get(); if ( !variantType ) { // null variantType = nullTypeInfo; } AddVariant(i->first, 0, variantType)->SetSubClass(); TMemberIndex index = GetVariants().LastIndex(); if ( variantType == nullTypeInfo ) { if ( m_NullPointerIndex == kEmptyChoice ) m_NullPointerIndex = index; else { ERR_POST_X(1, "double null"); } } else { const type_info* id = &CTypeConverter<CClassTypeInfo>::SafeCast(variantType)->GetId(); if ( !m_VariantsByType.insert(TVariantsByType::value_type(id, index)).second ) { NCBI_THROW(CSerialException,eInvalidData, "conflict subclasses: "+variantType->GetName()); } } } }
void CObjectOStreamXml::x_WriteClassNamespace(TTypeInfo type) { if (type->GetName().find(':') != string::npos) { return; } OpenTagEndBack(); if (m_UseSchemaLoc) { m_Output.PutEol(); m_Output.PutString(" "); } m_Output.PutString(" xmlns"); if (!m_CurrNsPrefix.empty()) { m_Output.PutChar(':'); m_Output.PutString(m_CurrNsPrefix); } m_Output.PutString("=\""); string ns_name( m_NsPrefixToName[m_CurrNsPrefix]); if (ns_name.empty()) { ns_name = GetDefaultSchemaNamespace(); } m_Output.PutString(ns_name + "\""); if (m_UseSchemaLoc) { m_Output.PutEol(); string xs_name("http://www.w3.org/2001/XMLSchema-instance"); string xs_prefix("xs"); if (m_NsNameToPrefix.find(xs_name) == m_NsNameToPrefix.end()) { for (char a='a'; m_NsPrefixToName.find(xs_prefix) != m_NsPrefixToName.end(); ++a) { xs_prefix += a; } m_NsPrefixToName[xs_prefix] = xs_name; m_NsNameToPrefix[xs_name] = xs_prefix; m_Output.PutString(" xmlns:"); m_Output.PutString(xs_prefix + "=\""); m_Output.PutString(xs_name + "\""); m_Output.PutEol(); m_Output.PutString(" "); m_Output.PutString(xs_prefix); m_Output.PutString(":schemaLocation=\""); m_Output.PutString(ns_name + " "); m_Output.PutString(GetDTDFilePrefix() + GetModuleName(type)); m_Output.PutString(".xsd\""); m_Output.PutEol(); } } OpenTagEnd(); }
void CObjectOStreamXml::WriteFileHeader(TTypeInfo type) { if (m_UseXmlDecl) { m_Output.PutString("<?xml version=\"1.0"); switch (m_Encoding) { default: break; case eEncoding_UTF8: m_Output.PutString("\" encoding=\"UTF-8"); break; case eEncoding_ISO8859_1: m_Output.PutString("\" encoding=\"ISO-8859-1"); break; case eEncoding_Windows_1252: m_Output.PutString("\" encoding=\"Windows-1252"); break; } m_Output.PutString("\"?>"); } if (!m_UseSchemaRef && m_UseDTDRef) { if (m_UseXmlDecl) { m_Output.PutEol(); } m_Output.PutString("<!DOCTYPE "); m_Output.PutString(type->GetName()); if (m_UsePublicId) { m_Output.PutString(" PUBLIC \""); if (m_PublicId.empty()) { m_Output.PutString("-//NCBI//"); m_Output.PutString(GetPublicModuleName(type)); m_Output.PutString("/EN"); } else { m_Output.PutString(m_PublicId); } m_Output.PutString("\""); } else { m_Output.PutString(" SYSTEM"); } m_Output.PutString(" \""); m_Output.PutString(GetDTDFilePrefix() + GetModuleName(type)); m_Output.PutString(".dtd\">"); } else if (!m_UseXmlDecl) { m_SkipIndent = true; } m_LastTagAction = eTagClose; }