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

📄 stdtypes.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
void CPrimitiveTypeInfo::SetValueDouble(TObjectPtr /*objectPtr*/,                                        double /*value*/) const{    ThrowIncompatibleValue();}#if SIZEOF_LONG_DOUBLE != 0long double CPrimitiveTypeInfo::GetValueLDouble(TConstObjectPtr objectPtr) const{    return GetValueDouble(objectPtr);}void CPrimitiveTypeInfo::SetValueLDouble(TObjectPtr objectPtr,                                         long double value) const{    SetValueDouble(objectPtr, value);}#endifvoid CPrimitiveTypeInfo::GetValueString(TConstObjectPtr /*objectPtr*/,                                        string& /*value*/) const{    ThrowIncompatibleValue();}void CPrimitiveTypeInfo::SetValueString(TObjectPtr /*objectPtr*/,                                        const string& /*value*/) const{    ThrowIncompatibleValue();}void CPrimitiveTypeInfo::GetValueOctetString(TConstObjectPtr /*objectPtr*/,                                             vector<char>& /*value*/) const{    ThrowIncompatibleValue();}void CPrimitiveTypeInfo::SetValueOctetString(TObjectPtr /*objectPtr*/,                                             const vector<char>& /*value*/) const{    ThrowIncompatibleValue();}CPrimitiveTypeInfoBool::CPrimitiveTypeInfoBool(void)    : CParent(sizeof(TObjectType), ePrimitiveValueBool){    CPrimitiveTypeFunctions<TObjectType>::SetMemFunctions(this);    CPrimitiveTypeFunctions<TObjectType>::SetIOFunctions(this);}bool CPrimitiveTypeInfoBool::GetValueBool(TConstObjectPtr object) const{    return CPrimitiveTypeFunctions<TObjectType>::Get(object);}void CPrimitiveTypeInfoBool::SetValueBool(TObjectPtr object, bool value) const{    CPrimitiveTypeFunctions<TObjectType>::Get(object) = value;}TTypeInfo CStdTypeInfo<bool>::GetTypeInfo(void){    static TTypeInfo info = CreateTypeInfo();    return info;}CTypeInfo* CStdTypeInfo<bool>::CreateTypeInfo(void){    return new CPrimitiveTypeInfoBool();}class CNullBoolFunctions : public CPrimitiveTypeFunctions<bool>{public:    static TObjectPtr Create(TTypeInfo type)        {            NCBI_THROW(CSerialException,eIllegalCall, "Cannot create NULL object");            return 0;        }    static bool IsDefault(TConstObjectPtr)        {            return false;        }    static void SetDefault(TObjectPtr)        {        }    static bool Equals(TConstObjectPtr, TConstObjectPtr,                       ESerialRecursionMode)        {            return true;        }    static void Assign(TObjectPtr, TConstObjectPtr,                       ESerialRecursionMode)        {        }    static void Read(CObjectIStream& in, TTypeInfo ,                     TObjectPtr object)        {            in.ReadNull();        }    static void Write(CObjectOStream& out, TTypeInfo ,                      TConstObjectPtr /*object*/)        {            out.WriteNull();        }    static void Copy(CObjectStreamCopier& copier, TTypeInfo )        {            copier.In().ReadNull();            copier.Out().WriteNull();        }    static void Skip(CObjectIStream& in, TTypeInfo )        {            in.SkipNull();        }};TTypeInfo CStdTypeInfo<bool>::GetTypeInfoNullBool(void){    static TTypeInfo info = CreateTypeInfoNullBool();    return info;}CTypeInfo* CStdTypeInfo<bool>::CreateTypeInfoNullBool(void){    CPrimitiveTypeInfo* info = new CPrimitiveTypeInfoBool;    typedef CNullBoolFunctions TFunctions;    info->SetMemFunctions(&TFunctions::Create, &TFunctions::IsDefault,                          &TFunctions::SetDefault,&TFunctions::Equals,                          &TFunctions::Assign);    info->SetIOFunctions(&TFunctions::Read, &TFunctions::Write,                         &TFunctions::Copy, &TFunctions::Skip);    return info;}CPrimitiveTypeInfoChar::CPrimitiveTypeInfoChar(void)    : CParent(sizeof(TObjectType), ePrimitiveValueChar){    CPrimitiveTypeFunctions<TObjectType>::SetMemFunctions(this);    CPrimitiveTypeFunctions<TObjectType>::SetIOFunctions(this);}char CPrimitiveTypeInfoChar::GetValueChar(TConstObjectPtr object) const{    return CPrimitiveTypeFunctions<TObjectType>::Get(object);}void CPrimitiveTypeInfoChar::SetValueChar(TObjectPtr object, char value) const{    CPrimitiveTypeFunctions<TObjectType>::Get(object) = value;}void CPrimitiveTypeInfoChar::GetValueString(TConstObjectPtr object,                                            string& value) const{    value.assign(1, CPrimitiveTypeFunctions<TObjectType>::Get(object));}void CPrimitiveTypeInfoChar::SetValueString(TObjectPtr object,                                            const string& value) const{    if ( value.size() != 1 )        ThrowIncompatibleValue();    CPrimitiveTypeFunctions<TObjectType>::Get(object) = value[0];}TTypeInfo CStdTypeInfo<char>::GetTypeInfo(void){    static TTypeInfo info = CreateTypeInfo();    return info;}CTypeInfo* CStdTypeInfo<char>::CreateTypeInfo(void){    return new CPrimitiveTypeInfoChar();}template<typename T>class CPrimitiveTypeInfoIntFunctions : public CPrimitiveTypeFunctions<T>{    typedef CPrimitiveTypeFunctions<T> CParent;public:    typedef T TObjectType;        static CPrimitiveTypeInfoInt* CreateTypeInfo(void)        {            CPrimitiveTypeInfoInt* info =                new CPrimitiveTypeInfoInt(sizeof(TObjectType), IsSigned());            info->SetMemFunctions(&CParent::Create,                                  &IsDefault, &SetDefault, &Equals, &Assign);            info->SetIOFunctions(&CParent::Read, &CParent::Write,                                 &CParent::Copy, &CParent::Skip);            SetInt4Functions(info);            SetInt8Functions(info);            return info;        }    static void SetInt4Functions(CPrimitiveTypeInfoInt* info)        {            info->SetInt4Functions(&GetValueInt4, &SetValueInt4,                                  &GetValueUint4, &SetValueUint4);        }    static void SetInt8Functions(CPrimitiveTypeInfoInt* info)        {            info->SetInt8Functions(&GetValueInt8, &SetValueInt8,                                  &GetValueUint8, &SetValueUint8);        }    static bool IsDefault(TConstObjectPtr objectPtr)        {            return CParent::Get(objectPtr) == 0;        }    static void SetDefault(TObjectPtr objectPtr)        {            CParent::Get(objectPtr) = 0;        }    static bool Equals(TConstObjectPtr obj1, TConstObjectPtr obj2,                       ESerialRecursionMode)        {            return CParent::Get(obj1) == CParent::Get(obj2);        }    static void Assign(TObjectPtr dst, TConstObjectPtr src,                       ESerialRecursionMode)        {            CParent::Get(dst) = CParent::Get(src);        }    static bool IsSigned(void)        {            return TObjectType(-1) < 0;        }    static bool IsUnsigned(void)        {            return TObjectType(-1) > 0;        }    static Int4 GetValueInt4(TConstObjectPtr objectPtr)        {            TObjectType value = CParent::Get(objectPtr);            Int4 result = Int4(value);            if ( IsUnsigned() ) {                // unsigned -> signed                if ( sizeof(value) == sizeof(result) ) {                    // same size - check for sign change only                    if ( CParent::IsNegative(result) )                        ThrowIntegerOverflow();                }            }            if ( sizeof(value) > sizeof(result) ) {                if ( value != TObjectType(result) )                    ThrowIntegerOverflow();            }            return result;        }    static Uint4 GetValueUint4(TConstObjectPtr objectPtr)        {            TObjectType value = CParent::Get(objectPtr);            Uint4 result = Uint4(value);            if ( IsSigned() ) {                // signed -> unsigned                // check for negative value                if ( IsNegative(value) )                    ThrowIntegerOverflow();            }            if ( sizeof(value) > sizeof(result) ) {                if ( value != TObjectType(result) )                    ThrowIntegerOverflow();            }            return result;        }    static void SetValueInt4(TObjectPtr objectPtr, Int4 value)        {            TObjectType result = TObjectType(value);            if ( IsUnsigned() ) {                // signed -> unsigned                // check for negative value                if ( CParent::IsNegative(value) )                    ThrowIntegerOverflow();            }            if ( sizeof(value) > sizeof(result) ) {                if ( value != Int4(result) )                    ThrowIntegerOverflow();            }            CParent::Get(objectPtr) = result;        }    static void SetValueUint4(TObjectPtr objectPtr, Uint4 value)        {            TObjectType result = TObjectType(value);            if ( IsSigned() ) {                // unsigned -> signed                if ( sizeof(value) == sizeof(result) ) {                    // same size - check for sign change only                    if ( IsNegative(result) )                        ThrowIntegerOverflow();                }            }            if ( sizeof(value) > sizeof(result) ) {                if ( value != Uint4(result) )                    ThrowIntegerOverflow();            }            CParent::Get(objectPtr) = result;        }    static Int8 GetValueInt8(TConstObjectPtr objectPtr)        {            TObjectType value = CParent::Get(objectPtr);            Int8 result = Int8(value);            if ( IsUnsigned() ) {                // unsigned -> signed                if ( sizeof(value) == sizeof(result) ) {                    // same size - check for sign change only                    if ( CParent::IsNegative(result) )                        ThrowIntegerOverflow();                }            }            if ( sizeof(value) > sizeof(result) ) {                if ( value != TObjectType(result) )                    ThrowIntegerOverflow();            }            return result;        }    static Uint8 GetValueUint8(TConstObjectPtr objectPtr)        {            TObjectType value = CParent::Get(objectPtr);            Uint8 result = Uint8(value);            if ( IsSigned() ) {                // signed -> unsigned                // check for negative value                if ( IsNegative(value) )                    ThrowIntegerOverflow();            }            if ( sizeof(value) > sizeof(result) ) {                if ( value != TObjectType(result) )                    ThrowIntegerOverflow();            }            return result;        }    static void SetValueInt8(TObjectPtr objectPtr, Int8 value)        {            TObjectType result = TObjectType(value);            if ( IsUnsigned() ) {                // signed -> unsigned                // check for negative value                if ( CParent::IsNegative(value) )                    ThrowIntegerOverflow();            }            if ( sizeof(value) > sizeof(result) ) {                if ( value != Int8(result) )                    ThrowIntegerOverflow();            }            CParent::Get(objectPtr) = result;        }    static void SetValueUint8(TObjectPtr objectPtr, Uint8 value)        {            TObjectType result = TObjectType(value);            if ( IsSigned() ) {                // unsigned -> signed                if ( sizeof(value) == sizeof(result) ) {                    // same size - check for sign change only                    if ( IsNegative(result) )                        ThrowIntegerOverflow();                }            }            if ( sizeof(value) > sizeof(result) ) {                if ( value != Uint8(result) )                    ThrowIntegerOverflow();            }            CParent::Get(objectPtr) = result;        }};CPrimitiveTypeInfoInt::CPrimitiveTypeInfoInt(size_t size, bool isSigned)    : CParent(size, ePrimitiveValueInteger, isSigned){}void CPrimitiveTypeInfoInt::SetInt4Functions(TGetInt4Function getInt4,                                             TSetInt4Function setInt4,                                             TGetUint4Function getUint4,                                             TSetUint4Function setUint4){    m_GetInt4 = getInt4;    m_SetInt4 = setInt4;    m_GetUint4 = getUint4;    m_SetUint4 = setUint4;}void CPrimitiveTypeInfoInt::SetInt8Functions(TGetInt8Function getInt8,                                             TSetInt8Function setInt8,                                             TGetUint8Function getUint8,                                             TSetUint8Function setUint8){    m_GetInt8 = getInt8;    m_SetInt8 = setInt8;    m_GetUint8 = getUint8;    m_SetUint8 = setUint8;}Int4 CPrimitiveTypeInfoInt::GetValueInt4(TConstObjectPtr objectPtr) const{    return m_GetInt4(objectPtr);}Uint4 CPrimitiveTypeInfoInt::GetValueUint4(TConstObjectPtr objectPtr) const{    return m_GetUint4(objectPtr);}void CPrimitiveTypeInfoInt::SetValueInt4(TObjectPtr objectPtr,                                         Int4 value) const{    m_SetInt4(objectPtr, value);}void CPrimitiveTypeInfoInt::SetValueUint4(TObjectPtr objectPtr,                                          Uint4 value) const{    m_SetUint4(objectPtr, value);}Int8 CPrimitiveTypeInfoInt::GetValueInt8(TConstObjectPtr objectPtr) const{    return m_GetInt8(objectPtr);}Uint8 CPrimitiveTypeInfoInt::GetValueUint8(TConstObjectPtr objectPtr) const{    return m_GetUint8(objectPtr);}

⌨️ 快捷键说明

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