void CContainerTypeInfo::Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how) const { if (how == eShallowChildless) { SetDefault(dst); // clear destination container return; } CIterator idst; CConstIterator isrc; bool old_element = InitIterator(idst,dst); if ( InitIterator(isrc, src) ) { TTypeInfo elementType = GetElementType(); do { TConstObjectPtr elementPtr = GetElementPtr(isrc); if (old_element) { elementType->Assign(GetElementPtr(idst), elementPtr, how); old_element = NextElement(idst); } else { AddElement(dst, elementPtr, how); } } while ( NextElement(isrc) ); } if (old_element) { EraseAllElements(idst); } }
TTypeInfo CPointerTypeInfo::GetRealDataTypeInfo(TConstObjectPtr object) const { TTypeInfo dataTypeInfo = GetPointedType(); if ( object ) dataTypeInfo = dataTypeInfo->GetRealTypeInfo(object); return dataTypeInfo; }
CTypeInfo* CPointerTypeInfo::SetTag( CAsnBinaryDefs::TLongTag tag, CAsnBinaryDefs::ETagClass tagclass,CAsnBinaryDefs::ETagType tagtype) { CParent::SetTag(tag, tagclass, tagtype); if (tagtype == CAsnBinaryDefs::eImplicit) { const CPointerTypeInfo *ptrtype = this; while (ptrtype) { TTypeInfo ptype = ptrtype->GetPointedType(); ptrtype = dynamic_cast<const CPointerTypeInfo*>(ptype); if (ptrtype) { if (ptrtype->GetTagType() == CAsnBinaryDefs::eImplicit || !ptrtype->HasTag()) { continue; } m_TagConstructed = CAsnBinaryDefs::eConstructed; } else { m_TagConstructed = ptype->GetTagConstructed(); } break; } } else { m_TagConstructed = CAsnBinaryDefs::eConstructed; } return this; }
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 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); } }
const CItemInfo* CItemsInfo::FindNextMandatory(const CItemInfo* info) { if (!info->GetId().HasNotag()) { const CMemberInfo* mem = dynamic_cast<const CMemberInfo*>(info); if (mem && mem->Optional()) { return 0; } return info; } const CItemInfo* found = 0; TTypeInfo type = FindRealTypeInfo(info->GetTypeInfo()); ETypeFamily family = type->GetTypeFamily(); if (family == eTypeFamilyClass || family == eTypeFamilyChoice) { const CClassTypeInfoBase* classType = dynamic_cast<const CClassTypeInfoBase*>(type); _ASSERT(classType); const CItemsInfo& items = classType->GetItems(); TMemberIndex i; const CItemInfo* found_first = 0; for (i = items.FirstIndex(); i <= items.LastIndex(); ++i) { const CItemInfo* item = classType->GetItems().GetItemInfo(i); ETypeFamily item_family = item->GetTypeInfo()->GetTypeFamily(); if (item_family == eTypeFamilyPointer) { const CPointerTypeInfo* ptr = dynamic_cast<const CPointerTypeInfo*>(item->GetTypeInfo()); if (ptr) { item_family = ptr->GetPointedType()->GetTypeFamily(); } } if (item_family == eTypeFamilyContainer) { if (item->NonEmpty()) { found = FindNextMandatory( item ); } } else { found = FindNextMandatory( item ); } if (family == eTypeFamilyClass) { if (found) { return found; } } else { if (!found) { // this is optional choice variant return 0; } if (!found_first) { found_first = found; } } } return found_first; } return found; }
void CObjectOStreamXml::x_EndTypeNamespace(void) { if (m_UseSchemaRef) { if (TopFrame().HasTypeInfo()) { TTypeInfo type = TopFrame().GetTypeInfo(); if (type->HasNamespaceName()) { x_EndNamespace(type->GetNamespaceName()); } } } }
bool CTypesIteratorBase<Parent>::CanEnter(const CConstObjectInfo& object) { if ( !CParent::CanEnter(object) ) return false; TTypeInfo type = object.GetTypeInfo(); ITERATE ( TTypeList, i, GetTypeList() ) { if ( type->MayContainType(*i) ) return true; } return false; }
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 CAliasTypeInfo::Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how) const { #if 1 GetPointedType()->Assign(dst, src, how); #else TConstObjectPtr data = GetObjectPointer(src); TTypeInfo type = GetRealDataTypeInfo(data); TObjectPtr object = GetObjectPointer(dst); type->Assign(object, data, how); #endif }
bool CObjectOStreamXml::x_ProcessTypeNamespace(TTypeInfo type) { if (m_UseSchemaRef) { string nsName; if (type->HasNamespaceName()) { nsName = type->GetNamespaceName(); } else if (m_NsPrefixes.empty()) { nsName = GetDefaultSchemaNamespace(); } return x_BeginNamespace(nsName,type->GetNamespacePrefix()); } return false; }
bool CTypesIteratorBase<Parent>::CanSelect(const CConstObjectInfo& object) { if ( !CParent::CanSelect(object) ) return false; m_MatchType = 0; TTypeInfo type = object.GetTypeInfo(); ITERATE ( TTypeList, i, GetTypeList() ) { if ( type->IsType(*i) ) { m_MatchType = *i; return true; } } return false; }
void CObjectOStreamAsn::WriteFileHeader(TTypeInfo type) { if ( true || m_Output.ZeroIndentLevel() ) { WriteId(type->GetName()); m_Output.PutString(" ::= "); } }
static TObjectPtr CreateAnyTypeClass(TTypeInfo objectType, CObjectMemoryPool* /*memoryPool*/) { size_t size = objectType->GetSize(); TObjectPtr obj = new char[size]; memset(obj, 0, size); return obj; }
void CPointerTypeInfo::Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how) const { TConstObjectPtr data = GetObjectPointer(src); if ( how != eRecursive ) { SetObjectPointer(dst, how == eShallow ? (const_cast<void*>(data)) : 0); } else if ( data == 0) { SetObjectPointer(dst, 0); } else { TTypeInfo type = GetRealDataTypeInfo(data); TObjectPtr object = type->Create(); type->Assign(object, data, how); SetObjectPointer(dst, object); } }
void CObjectOStream::WriteExternalObject(TConstObjectPtr objectPtr, TTypeInfo typeInfo) { _TRACE("CObjectOStream::WriteExternalObject(" << NStr::PtrToString(objectPtr) << ", " << typeInfo->GetName() << ')'); RegisterObject(objectPtr, typeInfo); WriteObject(objectPtr, typeInfo); }
BEGIN_NCBI_SCOPE CChoicePointerTypeInfo::CChoicePointerTypeInfo(TTypeInfo pointerType) : CParent(pointerType->GetSize(), "", TConstObjectPtr(0), &CVoidTypeFunctions::Create, typeid(bool), &GetPtrIndex, &SetPtrIndex, &ResetPtrIndex) { SetPointerType(pointerType); }
void CTypeInfoFunctions::CopyWithHook(CObjectStreamCopier& stream, TTypeInfo objectType) { CCopyObjectHook* hook = objectType->m_CopyHookData.GetHook(stream.m_ObjectHookKey); if (!hook) { hook = objectType->m_CopyHookData.GetPathHook(stream.In()); } if ( hook ) hook->CopyObject(stream, objectType); else objectType->DefaultCopyData(stream); }
static string GetPublicModuleName(TTypeInfo type) { const string& s = type->GetModuleName(); string name; for ( string::const_iterator i = s.begin(); i != s.end(); ++i ) { char c = *i; if ( !isalnum((unsigned char) c) ) name += ' '; else name += c; } return name; }
void CTypeInfoFunctions::SkipWithHook(CObjectIStream& stream, TTypeInfo objectType) { CSkipObjectHook* hook = objectType->m_SkipHookData.GetHook(stream.m_ObjectSkipHookKey); if (!hook) { hook = objectType->m_SkipHookData.GetPathHook(stream); } if ( hook ) hook->SkipObject(stream, objectType); else objectType->DefaultSkipData(stream); }
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 CTypeInfoFunctions::ReadWithHook(CObjectIStream& stream, TTypeInfo objectType, TObjectPtr objectPtr) { CReadObjectHook* hook = objectType->m_ReadHookData.GetHook(stream.m_ObjectHookKey); if (!hook) { hook = objectType->m_ReadHookData.GetPathHook(stream); } if ( hook ) hook->ReadObject(stream, CObjectInfo(objectPtr, objectType)); else objectType->DefaultReadData(stream, objectPtr); }
void CTypeInfoFunctions::WriteWithHook(CObjectOStream& stream, TTypeInfo objectType, TConstObjectPtr objectPtr) { CWriteObjectHook* hook = objectType->m_WriteHookData.GetHook(stream.m_ObjectHookKey); if (!hook) { hook = objectType->m_WriteHookData.GetPathHook(stream); } if ( hook ) hook->WriteObject(stream, CConstObjectInfo(objectPtr, objectType)); else objectType->DefaultWriteData(stream, objectPtr); }
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; }
string CObjectOStreamXml::GetModuleName(TTypeInfo type) { string name; if( !m_DTDFileName.empty() ) { name = m_DTDFileName; } else { const string& s = type->GetModuleName(); for ( string::const_iterator i = s.begin(); i != s.end(); ++i ) { char c = *i; if ( c == '-' ) name += '_'; else name += c; } } return name; }
CAliasTypeInfo::CAliasTypeInfo(const string& name, TTypeInfo type) : CParent(name, type->GetSize(), type), m_DataOffset(0), m_FullAlias(false) { InitAliasTypeInfoFunctions(); }