00001 #ifndef DELAYBUF__HPP 00002 #define DELAYBUF__HPP 00003 00004 /* $Id: delaybuf.hpp 103491 2007-05-04 17:18:18Z kazimird $ 00005 * =========================================================================== 00006 * 00007 * PUBLIC DOMAIN NOTICE 00008 * National Center for Biotechnology Information 00009 * 00010 * This software/database is a "United States Government Work" under the 00011 * terms of the United States Copyright Act. It was written as part of 00012 * the author's official duties as a United States Government employee and 00013 * thus cannot be copyrighted. This software/database is freely available 00014 * to the public for use. The National Library of Medicine and the U.S. 00015 * Government have not placed any restriction on its use or reproduction. 00016 * 00017 * Although all reasonable efforts have been taken to ensure the accuracy 00018 * and reliability of the software and data, the NLM and the U.S. 00019 * Government do not and cannot warrant the performance or results that 00020 * may be obtained by using this software or data. The NLM and the U.S. 00021 * Government disclaim all warranties, express or implied, including 00022 * warranties of performance, merchantability or fitness for any particular 00023 * purpose. 00024 * 00025 * Please cite the author in any work or product based on this material. 00026 * 00027 * =========================================================================== 00028 * 00029 * Author: Eugene Vasilchenko 00030 * 00031 * File Description: 00032 * Memory buffer to hold unparsed input data 00033 */ 00034 00035 #include <corelib/ncbistd.hpp> 00036 #include <corelib/ncbiobj.hpp> 00037 #include <serial/serialdef.hpp> 00038 #include <memory> 00039 00040 00041 /** @addtogroup ObjStreamSupport 00042 * 00043 * @{ 00044 */ 00045 00046 00047 BEGIN_NCBI_SCOPE 00048 00049 class CByteSource; 00050 class CItemInfo; 00051 00052 ///////////////////////////////////////////////////////////////////////////// 00053 /// 00054 /// CDelayBuffer 00055 /// 00056 /// Memory buffer to hold unparsed input data 00057 class CDelayBuffer 00058 { 00059 public: 00060 CDelayBuffer(void) 00061 { 00062 } 00063 ~CDelayBuffer(void); 00064 00065 /// Check if there is input data in the buffer 00066 /// 00067 /// @return 00068 /// TRUE is the buffer is not empty 00069 bool Delayed(void) const 00070 { 00071 return m_Info.get() != 0; 00072 } 00073 00074 DECLARE_OPERATOR_BOOL_PTR(m_Info.get()); 00075 00076 /// Forget the stored data 00077 void Forget(void); 00078 00079 /// Parse stored data 00080 void Update(void) 00081 { 00082 if ( Delayed() ) 00083 DoUpdate(); 00084 } 00085 00086 /// Check stored data format 00087 /// 00088 /// @param format 00089 /// Data format 00090 /// @return 00091 /// TRUE is stored data is in this format 00092 bool HaveFormat(ESerialDataFormat format) const 00093 { 00094 const SInfo* info = m_Info.get(); 00095 return info && info->m_DataFormat == format; 00096 } 00097 00098 /// Get data source 00099 CByteSource& GetSource(void) const 00100 { 00101 return *m_Info->m_Source; 00102 } 00103 00104 /// Get member index 00105 TMemberIndex GetIndex(void) const; 00106 00107 /// Reset the buffer with a new data 00108 void SetData(const CItemInfo* itemInfo, TObjectPtr object, 00109 ESerialDataFormat dataFormat, CByteSource& data); 00110 00111 private: 00112 struct SInfo 00113 { 00114 public: 00115 SInfo(const CItemInfo* itemInfo, TObjectPtr object, 00116 ESerialDataFormat dataFormat, CByteSource& source); 00117 ~SInfo(void); 00118 00119 // member info 00120 const CItemInfo* m_ItemInfo; 00121 // main object 00122 TObjectPtr m_Object; 00123 // data format 00124 ESerialDataFormat m_DataFormat; 00125 // data source 00126 mutable CRef<CByteSource> m_Source; 00127 }; 00128 00129 // private method declarations to prevent implicit generation by compiler 00130 CDelayBuffer(const CDelayBuffer&); 00131 CDelayBuffer& operator==(const CDelayBuffer&); 00132 static void* operator new(size_t); 00133 00134 void DoUpdate(void); 00135 00136 auto_ptr<SInfo> m_Info; 00137 }; 00138 00139 /* @} */ 00140 00141 00142 END_NCBI_SCOPE 00143 00144 #endif /* DELAYBUF__HPP */ 00145 00146
1.4.6
Modified on Wed Dec 09 08:17:42 2009 by modify_doxy.py rev. 173732