NCBI C++ ToolKit
delaybuf.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef DELAYBUF__HPP
2 #define DELAYBUF__HPP
3 
4 /* $Id: delaybuf.hpp 80811 2018-01-11 14:18:53Z gouriano $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Eugene Vasilchenko
30 *
31 * File Description:
32 * Memory buffer to hold unparsed input data
33 */
34 
35 #include <corelib/ncbistd.hpp>
36 #include <corelib/ncbiobj.hpp>
37 #include <serial/serialdef.hpp>
38 #include <memory>
39 
40 
41 /** @addtogroup ObjStreamSupport
42  *
43  * @{
44  */
45 
46 
48 
49 class CByteSource;
50 class CItemInfo;
51 
52 /////////////////////////////////////////////////////////////////////////////
53 ///
54 /// CDelayBuffer
55 ///
56 /// Memory buffer to hold unparsed input data
58 {
59 public:
61  {
62  }
63  ~CDelayBuffer(void);
64 
65  /// Check if there is input data in the buffer
66  ///
67  /// @return
68  /// TRUE is the buffer is not empty
69  bool Delayed(void) const
70  {
71  return m_Info.get() != 0;
72  }
73 
75 
76  /// Forget the stored data
77  void Forget(void);
78 
79  /// Parse stored data
80  void Update(void)
81  {
82  if ( Delayed() )
83  DoUpdate();
84  }
85 
86  /// Check stored data format
87  ///
88  /// @param format
89  /// Data format
90  /// @return
91  /// TRUE is stored data is in this format
93  {
94  const SInfo* info = m_Info.get();
95  return info && info->m_DataFormat == format;
96  }
97 
98  /// Get data source
99  CByteSource& GetSource(void) const
100  {
101  return *m_Info->m_Source;
102  }
103 
104  /// Get member index
105  TMemberIndex GetIndex(void) const;
106 
107  typedef int TFormatFlags;
108 
109  /// Reset the buffer with a new data
110  void SetData(const CItemInfo* itemInfo, TObjectPtr object,
112  CByteSource& data);
113 
114 private:
115  struct SInfo
116  {
117  public:
118  SInfo(const CItemInfo* itemInfo, TObjectPtr object,
121  ~SInfo(void);
122 
123  // member info
125  // main object
127  // data format
129  // data format flags
131  // data source
133  };
134 
135  // private method declarations to prevent implicit generation by compiler
138  static void* operator new(size_t);
139 
140  void DoUpdate(void);
141 
142  unique_ptr<SInfo> m_Info;
143 };
144 
145 /* @} */
146 
147 
149 
150 #endif /* DELAYBUF__HPP */
CDelayBuffer.
Definition: delaybuf.hpp:58
Include a standard set of the NCBI C++ Toolkit most basic headers.
static uch flags
char data[12]
Definition: iconv.c:80
void * TObjectPtr
Definition: serialdef.hpp:55
size_t TMemberIndex
Type used for indexing class members and choice variants.
Definition: serialdef.hpp:230
ESerialDataFormat
Data file format.
Definition: serialdef.hpp:71
CDelayBuffer(const CDelayBuffer &)
int TFormatFlags
Definition: delaybuf.hpp:107
CByteSource & GetSource(void) const
Get data source.
Definition: delaybuf.hpp:99
CDelayBuffer & operator==(const CDelayBuffer &)
const CItemInfo * m_ItemInfo
Definition: delaybuf.hpp:124
unique_ptr< SInfo > m_Info
Definition: delaybuf.hpp:142
void Update(void)
Parse stored data.
Definition: delaybuf.hpp:80
bool Delayed(void) const
Check if there is input data in the buffer.
Definition: delaybuf.hpp:69
DECLARE_OPERATOR_BOOL_PTR(m_Info.get())
TObjectPtr m_Object
Definition: delaybuf.hpp:126
CRef< CByteSource > m_Source
Definition: delaybuf.hpp:132
bool HaveFormat(ESerialDataFormat format) const
Check stored data format.
Definition: delaybuf.hpp:92
CDelayBuffer(void)
Definition: delaybuf.hpp:60
ESerialDataFormat m_DataFormat
Definition: delaybuf.hpp:128
TFormatFlags m_Flags
Definition: delaybuf.hpp:130
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_XSERIAL_EXPORT
Definition: ncbi_export.h:1435
static MDB_envinfo info
Definition: mdb_load.c:37
const CharType(& source)[N]
Definition: pointer.h:1149
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
static Format format
Definition: njn_ioutil.cpp:53
Modified on Sat Apr 20 12:15:53 2024 by modify_doxy.py rev. 669887