📄 serialbase.hpp
字号:
/* * =========================================================================== * PRODUCTION $Log: serialbase.hpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 19:39:07 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.32 * PRODUCTION * =========================================================================== */#ifndef SERIALBASE__HPP#define SERIALBASE__HPP/* $Id: serialbase.hpp,v 1000.3 2004/06/01 19:39:07 gouriano Exp $* ===========================================================================** PUBLIC DOMAIN NOTICE* National Center for Biotechnology Information** This software/database is a "United States Government Work" under the* terms of the United States Copyright Act. It was written as part of* the author's official duties as a United States Government employee and* thus cannot be copyrighted. This software/database is freely available* to the public for use. The National Library of Medicine and the U.S.* Government have not placed any restriction on its use or reproduction.** Although all reasonable efforts have been taken to ensure the accuracy* and reliability of the software and data, the NLM and the U.S.* Government do not and cannot warrant the performance or results that* may be obtained by using this software or data. The NLM and the U.S.* Government disclaim all warranties, express or implied, including* warranties of performance, merchantability or fitness for any particular* purpose.** Please cite the author in any work or product based on this material.** ===========================================================================** Author: Eugene Vasilchenko** File Description:* File to be included in all headers generated by datatool*/#include <corelib/ncbistd.hpp>#include <corelib/ncbiobj.hpp>#include <serial/exception.hpp>#include <serial/serialdef.hpp>#include <typeinfo>/** @addtogroup GenClassSupport * * @{ */BEGIN_NCBI_SCOPEclass CTypeInfo;class CClassTypeInfo;class CChoiceTypeInfo;class CEnumeratedTypeValues;// enum for choice classes generated by datatoolenum EResetVariant { eDoResetVariant, eDoNotResetVariant};typedef void (*TPostReadFunction)(const CTypeInfo* info, void* object);typedef void (*TPreWriteFunction)(const CTypeInfo* info, const void* object);NCBI_XSERIAL_EXPORTvoid SetPostRead(CClassTypeInfo* info, TPostReadFunction function);NCBI_XSERIAL_EXPORTvoid SetPostRead(CChoiceTypeInfo* info, TPostReadFunction function);NCBI_XSERIAL_EXPORTvoid SetPreWrite(CClassTypeInfo* info, TPreWriteFunction function);NCBI_XSERIAL_EXPORTvoid SetPreWrite(CChoiceTypeInfo* info, TPreWriteFunction function);template<class Class>class CClassPostReadPreWrite{public: static void PostRead(const CTypeInfo* /*info*/, void* object) { static_cast<Class*>(object)->PostRead(); } static void PreWrite(const CTypeInfo* /*info*/, const void* object) { static_cast<const Class*>(object)->PreWrite(); }};// Base class for all serializable objectsclass NCBI_XSERIAL_EXPORT CSerialObject : public CObject{public: CSerialObject(void); virtual ~CSerialObject(void); virtual const CTypeInfo* GetThisTypeInfo(void) const = 0; virtual void Assign(const CSerialObject& source, ESerialRecursionMode how = eRecursive); virtual bool Equals(const CSerialObject& object, ESerialRecursionMode how = eRecursive) const; virtual void DebugDump(CDebugDumpContext ddc, unsigned int depth) const; void ThrowUnassigned(TMemberIndex index) const; // for all GetX() methods called in the current thread static void SetVerifyDataThread(ESerialVerifyData verify); // for all GetX() methods called in the current process static void SetVerifyDataGlobal(ESerialVerifyData verify); static const char* ms_UnassignedStr; static const char ms_UnassignedByte; bool HasNamespaceName(void) const; const string& GetNamespaceName(void) const; void SetNamespaceName(const string& ns_name); bool HasNamespacePrefix(void) const; const string& GetNamespacePrefix(void) const; void SetNamespacePrefix(const string& ns_prefix);private: static ESerialVerifyData x_GetVerifyData(void); static ESerialVerifyData ms_VerifyDataDefault;};class NCBI_XSERIAL_EXPORT CSerialAttribInfoItem{public: CSerialAttribInfoItem(const string& name, const string& ns_name, const string& value); CSerialAttribInfoItem(const CSerialAttribInfoItem& other); virtual ~CSerialAttribInfoItem(void); const string& GetName(void) const; const string& GetNamespaceName(void) const; const string& GetValue(void) const;private: string m_Name; string m_NsName; string m_Value;};class NCBI_XSERIAL_EXPORT CAnyContentObject : public CSerialObject{public: CAnyContentObject(void); CAnyContentObject(const CAnyContentObject& other); virtual ~CAnyContentObject(void); virtual const CTypeInfo* GetThisTypeInfo(void) const { return GetTypeInfo(); } static const CTypeInfo* GetTypeInfo(void); void Reset(void); CAnyContentObject& operator= (const CAnyContentObject& other); bool operator== (const CAnyContentObject& other) const; void SetName(const string& name); const string& GetName(void) const; void SetValue(const string& value); const string& GetValue(void) const; void SetNamespaceName(const string& ns_name); const string& GetNamespaceName(void) const; void SetNamespacePrefix(const string& ns_prefix); const string& GetNamespacePrefix(void) const; void AddAttribute(const string& name, const string& ns_name, const string& value); const vector<CSerialAttribInfoItem>& GetAttributes(void) const;private: void x_Copy(const CAnyContentObject& other); void x_Decode(const string& value); string m_Name; string m_Value; string m_NsName; string m_NsPrefix; vector<CSerialAttribInfoItem> m_Attlist;};// Base class for user-defined serializable classes// to allow for objects assignment and comparison.// EXAMPLE:// class CSeq_entry : public CSeq_entry_Base, CSerialUserOp//class NCBI_XSERIAL_EXPORT CSerialUserOp{ friend class CClassTypeInfo; friend class CChoiceTypeInfo;protected: // will be called after copying the datatool-generated members virtual void UserOp_Assign(const CSerialUserOp& source) = 0; // will be called after comparing the datatool-generated members virtual bool UserOp_Equals(const CSerialUserOp& object) const = 0;};///////////////////////////////////////////////////////////////////////// Alias wrapper templates//template <class TPrim>class CAliasBase{public: typedef CAliasBase<TPrim> TThis; CAliasBase(void) {} explicit CAliasBase(const TPrim& value) : m_Data(value) {} const TPrim& Get(void) const { return m_Data; } TPrim& Set(void) { return m_Data; } void Set(const TPrim& value) { m_Data = value; } operator TPrim(void) const { return m_Data; } TThis& operator*(void) { return *this; } TThis* operator->(void) { return this; } bool operator<(const TPrim& value) const { return m_Data < value; } bool operator>(const TPrim& value) const { return m_Data > value; } bool operator==(const TPrim& value) const { return m_Data == value; } bool operator!=(const TPrim& value) const { return m_Data != value; } static TPointerOffsetType GetDataPtr(const TThis* alias) { return TPointerOffsetType(&alias->m_Data); }protected: TPrim m_Data;};template <class TStd>class CStdAliasBase : public CAliasBase<TStd>{ typedef CAliasBase<TStd> TParent; typedef CStdAliasBase<TStd> TThis;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -