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

📄 stdtypes.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    static void Copy(CObjectStreamCopier& copier,                     TTypeInfo )        {            copier.CopyByteBlock();        }    static void Skip(CObjectIStream& in, TTypeInfo )        {            in.SkipByteBlock();        }};template<typename Char>class CCharVectorFunctions : public CCharVectorFunctionsBase{public:    typedef vector<Char> TObjectType;    typedef Char TChar;    static TObjectType& Get(TObjectPtr object)        {            return CTypeConverter<TObjectType>::Get(object);        }    static const TObjectType& Get(TConstObjectPtr object)        {            return CTypeConverter<TObjectType>::Get(object);        }    static char* ToChar(TChar* p)        { return reinterpret_cast<char*>(p); }    static const char* ToChar(const TChar* p)        { return reinterpret_cast<const char*>(p); }    static const TChar* ToTChar(const char* p)        { return reinterpret_cast<const TChar*>(p); }    static TObjectPtr Create(TTypeInfo )        {            return new TObjectType();        }    static bool IsDefault(TConstObjectPtr object)        {            return Get(object).empty();        }    static bool Equals(TConstObjectPtr object1, TConstObjectPtr object2,                       ESerialRecursionMode)        {            return Get(object1) == Get(object2);        }    static void SetDefault(TObjectPtr dst)        {            Get(dst).clear();        }    static void Assign(TObjectPtr dst, TConstObjectPtr src,                       ESerialRecursionMode)        {            Get(dst) = Get(src);        }    static void Read(CObjectIStream& in,                     TTypeInfo , TObjectPtr objectPtr)        {            TObjectType& o = Get(objectPtr);            CObjectIStream::ByteBlock block(in);            if ( block.KnownLength() ) {                size_t length = block.GetExpectedLength();#if 1                o.clear();                o.reserve(length);                Char buf[2048];                size_t count;                while ( (count = block.Read(ToChar(buf), sizeof(buf))) != 0 ) {                    o.insert(o.end(), buf, buf + count);                }#else                o.resize(length);                block.Read(ToChar(&o.front()), length, true);#endif            }            else {                // length is unknown -> copy via buffer                o.clear();                Char buf[4096];                size_t count;                while ( (count = block.Read(ToChar(buf), sizeof(buf))) != 0 ) {#ifdef RESERVE_VECTOR_SIZE                    size_t new_size = o.size() + count;                    if ( new_size > o.capacity() ) {                        o.reserve(RESERVE_VECTOR_SIZE(new_size));                    }#endif                    o.insert(o.end(), buf, buf + count);                }            }            block.End();        }    static void Write(CObjectOStream& out,                      TTypeInfo , TConstObjectPtr objectPtr)        {            const TObjectType& o = Get(objectPtr);            size_t length = o.size();            CObjectOStream::ByteBlock block(out, length);            if ( length > 0 )                block.Write(ToChar(&o.front()), length);            block.End();        }};template<typename Char>CCharVectorTypeInfo<Char>::CCharVectorTypeInfo(void)    : CParent(sizeof(TObjectType), ePrimitiveValueOctetString){    typedef CCharVectorFunctions<Char> TFunctions;    SetMemFunctions(&TFunctions::Create,                    &TFunctions::IsDefault, &TFunctions::SetDefault,                    &TFunctions::Equals, &TFunctions::Assign);    SetIOFunctions(&TFunctions::Read, &TFunctions::Write,                   &TFunctions::Copy, &TFunctions::Skip);}template<typename Char>void CCharVectorTypeInfo<Char>::GetValueString(TConstObjectPtr objectPtr,                                               string& value) const{    const TObjectType& obj = CCharVectorFunctions<TChar>::Get(objectPtr);    const char* buffer = CCharVectorFunctions<TChar>::ToChar(&obj.front());    value.assign(buffer, buffer + obj.size());}template<typename Char>void CCharVectorTypeInfo<Char>::SetValueString(TObjectPtr objectPtr,                                               const string& value) const{    TObjectType& obj = CCharVectorFunctions<TChar>::Get(objectPtr);    obj.clear();    const TChar* buffer = CCharVectorFunctions<TChar>::ToTChar(value.data());    obj.insert(obj.end(), buffer, buffer + value.size());}template<typename Char>void CCharVectorTypeInfo<Char>::GetValueOctetString(TConstObjectPtr objectPtr,                                                    vector<char>& value) const{    const TObjectType& obj = CCharVectorFunctions<TChar>::Get(objectPtr);    value.clear();    const char* buffer = CCharVectorFunctions<TChar>::ToChar(&obj.front());    value.insert(value.end(), buffer, buffer + obj.size());}template<typename Char>void CCharVectorTypeInfo<Char>::SetValueOctetString(TObjectPtr objectPtr,                                                    const vector<char>& value) const{    TObjectType& obj = CCharVectorFunctions<TChar>::Get(objectPtr);    obj.clear();    const TChar* buffer = CCharVectorFunctions<TChar>::ToTChar(&value.front());    obj.insert(obj.end(), buffer, buffer + value.size());}TTypeInfo CStdTypeInfo< vector<char> >::GetTypeInfo(void){    static TTypeInfo typeInfo = CreateTypeInfo();    return typeInfo;}TTypeInfo CStdTypeInfo< vector<signed char> >::GetTypeInfo(void){    static TTypeInfo typeInfo = CreateTypeInfo();    return typeInfo;}TTypeInfo CStdTypeInfo< vector<unsigned char> >::GetTypeInfo(void){    static TTypeInfo typeInfo = CreateTypeInfo();    return typeInfo;}CTypeInfo* CStdTypeInfo< vector<char> >::CreateTypeInfo(void){    return new CCharVectorTypeInfo<char>;}CTypeInfo* CStdTypeInfo< vector<signed char> >::CreateTypeInfo(void){    return new CCharVectorTypeInfo<signed char>;}CTypeInfo* CStdTypeInfo< vector<unsigned char> >::CreateTypeInfo(void){    return new CCharVectorTypeInfo<unsigned char>;}class CAnyContentFunctions : public CPrimitiveTypeFunctions<ncbi::CAnyContentObject>{public:    static TObjectPtr Create(TTypeInfo )        {            return new TObjectType();        }    static bool IsDefault(TConstObjectPtr objectPtr)        {            return Get(objectPtr) == TObjectType();        }    static void SetDefault(TObjectPtr objectPtr)        {            Get(objectPtr) = TObjectType();        }    static void Read(CObjectIStream& in, TTypeInfo , TObjectPtr objectPtr)        {            in.ReadAnyContentObject(Get(objectPtr));        }    static void Write(CObjectOStream& out, TTypeInfo ,                      TConstObjectPtr objectPtr)        {            out.WriteAnyContentObject(Get(objectPtr));        }    static void Copy(CObjectStreamCopier& copier, TTypeInfo )        {            copier.CopyAnyContentObject();        }    static void Skip(CObjectIStream& in, TTypeInfo )        {            in.SkipAnyContentObject();        }};CPrimitiveTypeInfoAnyContent::CPrimitiveTypeInfoAnyContent(void)    : CParent(sizeof(CAnyContentObject), ePrimitiveValueOther){    m_IsCObject = true;    typedef CPrimitiveTypeFunctions<ncbi::CAnyContentObject> TFunctions;    SetMemFunctions(&CAnyContentFunctions::Create,                    &CAnyContentFunctions::IsDefault,                    &CAnyContentFunctions::SetDefault,                    &TFunctions::Equals, &TFunctions::Assign);    SetIOFunctions(&CAnyContentFunctions::Read,                   &CAnyContentFunctions::Write,                   &CAnyContentFunctions::Copy,                   &CAnyContentFunctions::Skip);}TTypeInfo CStdTypeInfo<CAnyContentObject>::GetTypeInfo(void){    static TTypeInfo info = CreateTypeInfo();    return info;}CTypeInfo* CStdTypeInfo<ncbi::CAnyContentObject>::CreateTypeInfo(void){    return new CPrimitiveTypeInfoAnyContent();}END_NCBI_SCOPE/** ===========================================================================** $Log: stdtypes.cpp,v $* Revision 1000.3  2004/06/01 19:41:52  gouriano* PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.44** Revision 1.44  2004/05/17 21:03:03  gorelenk* Added include of PCH ncbi_pch.hpp** Revision 1.43  2004/04/26 16:40:59  ucko* Tweak for GCC 3.4 compatibility.** Revision 1.42  2004/03/25 15:57:08  gouriano* Added possibility to copy and compare serial object non-recursively** Revision 1.41  2004/02/04 19:03:00  ucko* Make floating-point comparison slightly looser, as I/O may introduce* insignificant discrepancies.** Revision 1.40  2004/02/02 14:42:48  vasilche* Try to avoid filling vector<char> by zeroes.** Revision 1.39  2004/01/27 17:09:12  ucko* CStringFunctions::Create: tweak to compile with default IBM VisualAge* settings.* Move CVS log to end.** Revision 1.38  2003/11/20 14:33:19  gouriano* changed generated C++ code so NULL data types have no value** Revision 1.37  2003/09/22 20:56:31  gouriano* Changed base type of AnyContent object to CSerialObject** Revision 1.36  2003/08/13 15:47:45  gouriano* implemented serialization of AnyContent objects** Revision 1.35  2003/05/22 20:10:02  gouriano* added UTF8 strings** Revision 1.34  2003/05/16 18:02:18  gouriano* revised exception error messages** Revision 1.33  2003/03/10 18:54:26  gouriano* use new structured exceptions (based on CException)** Revision 1.32  2002/10/25 14:49:27  vasilche* NCBI C Toolkit compatibility code extracted to libxcser library.* Serial streams flags names were renamed to fXxx.** Names of flags** Revision 1.31  2002/07/01 15:42:07  grichenk* Fixed 'unused variable' warnings, removed commented code.** Revision 1.30  2002/02/13 22:39:17  ucko* Support AIX.** Revision 1.29  2002/01/15 21:38:26  grichenk* Fixed NULL type initialization/reading/writing** Revision 1.28  2001/05/17 15:07:09  lavr* Typos corrected** Revision 1.27  2001/01/30 21:41:05  vasilche* Fixed dealing with unsigned enums.** Revision 1.26  2000/12/15 15:38:46  vasilche* Added support of Int8 and long double.* Enum values now have type Int4 instead of long.** Revision 1.25  2000/11/07 17:25:41  vasilche* Fixed encoding of XML:*     removed unnecessary apostrophes in OCTET STRING*     removed unnecessary content in NULL* Added module names to CTypeInfo and CEnumeratedTypeValues** Revision 1.24  2000/10/20 15:51:43  vasilche* Fixed data error processing.* Added interface for constructing container objects directly into output stream.* object.hpp, object.inl and object.cpp were split to* objectinfo.*, objecttype.*, objectiter.* and objectio.*.** Revision 1.23  2000/10/17 18:45:36  vasilche* Added possibility to turn off object cross reference detection in* CObjectIStream and CObjectOStream.** Revision 1.22  2000/10/13 20:22:56  vasilche* Fixed warnings on 64 bit compilers.* Fixed missing typename in templates.** Revision 1.21  2000/10/13 16:28:40  vasilche* Reduced header dependency.* Avoid use of templates with virtual methods.* Reduced amount of different maps used.* All this lead to smaller compiled code size (libraries and programs).** Revision 1.20  2000/09/18 20:00:25  vasilche* Separated CVariantInfo and CMemberInfo.* Implemented copy hooks.* All hooks now are stored in CTypeInfo/CMemberInfo/CVariantInfo.* Most type specific functions now are implemented via function pointers instead of virtual functions.** Revision 1.19  2000/09/01 13:16:21  vasilche* Implemented class/container/choice iterators.* Implemented CObjectStreamCopier for copying data without loading into memory.** Revision 1.18  2000/07/03 18:42:47  vasilche* Added interface to typeinfo via CObjectInfo and CConstObjectInfo.* Reduced header dependency.** Revision 1.17  2000/05/24 20:08:49  vasilche* Implemented XML dump.** Revision 1.16  2000/04/06 16:11:01  vasilche* Fixed bug with iterators in choices.* Removed unneeded calls to ReadExternalObject/WriteExternalObject.* Added output buffering to text ASN.1 data.** Revision 1.15  2000/03/14 14:42:32  vasilche* Fixed error reporting.** Revision 1.14  2000/03/07 14:06:24  vasilche* Added stream buffering to ASN.1 binary input.* Optimized class loading/storing.* Fixed bugs in processing OPTIONAL fields.* Added generation of reference counted objects.** Revision 1.13  2000/01/10 19:46:42  vasilche* Fixed encoding/decoding of REAL type.* Fixed encoding/decoding of StringStore.* Fixed encoding/decoding of NULL type.* Fixed error reporting.* Reduced object map (only classes).** Revision 1.12  2000/01/05 19:43:57  vasilche* Fixed error messages when reading from ASN.1 binary file.* Fixed storing of integers with enumerated values in ASN.1 binary file.* Added TAG support to key/value of map.* Added support of NULL variant in CHOICE.** Revision 1.11  1999/12/28 18:55:52  vasilche* Reduced size of compiled object files:* 1. avoid inline or implicit virtual methods (especially destructors).* 2. avoid std::string's methods usage in inline methods.* 3. avoid string literals ("xxx") in inline methods.** Revision 1.10  1999/12/17 19:05:04  vasilche* Simplified generation of GetTypeInfo methods.** Revision 1.9  1999/09/23 18:57:02  vasilche* Fixed bugs with overloaded methods in objistr*.hpp & objostr*.hpp** Revision 1.8  1999/09/14 18:54:20  vasilche* Fixed bugs detected by gcc & egcs.* Removed unneeded includes.** Revision 1.7  1999/07/07 21:56:35  vasilche* Fixed problem with static variables in templates on SunPro** Revision 1.6  1999/07/07 21:15:03  vasilche* Cleaned processing of string types (string, char*, const char*).** Revision 1.5  1999/07/07 19:59:08  vasilche* Reduced amount of data allocated on heap* Cleaned ASN.1 structures info** Revision 1.4  1999/06/30 16:05:05  vasilche* Added support for old ASN.1 structures.** Revision 1.3  1999/06/24 14:45:01  vasilche* Added binary ASN.1 output.** Revision 1.2  1999/06/04 20:51:49  vasilche* First compilable version of serialization.** Revision 1.1  1999/05/19 19:56:57  vasilche* Commit just in case.** ===========================================================================*/

⌨️ 快捷键说明

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