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

Go to the SVN repository for this file.

1 /* $Id: delaybuf.cpp 99610 2023-04-25 15:11:28Z vasilche $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Eugene Vasilchenko
27 *
28 * File Description:
29 * !!! PUT YOUR DESCRIPTION HERE !!!
30 */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbistd.hpp>
34 #include <serial/delaybuf.hpp>
35 #include <serial/objostr.hpp>
36 #include <serial/objistr.hpp>
37 #include <util/bytesrc.hpp>
38 #include <serial/impl/item.hpp>
39 #include <serial/impl/stdtypes.hpp>
40 
42 
43 DEFINE_STATIC_FAST_MUTEX(s_UpdateMutex);
44 
46 {
47 }
48 
49 void CDelayBuffer::SetData(const CItemInfo* itemInfo, TObjectPtr object,
52 {
53  _ASSERT(!Delayed());
54 
55  m_Info.reset(new SInfo(itemInfo, object, dataFormat, flags, data));
56 }
57 
59 {
60  m_Info.reset(0);
61 }
62 
64 {
65  if ( m_Info.get() == nullptr ) {
66  return;
67  }
68  CFastMutexGuard guard(s_UpdateMutex);
69  if ( m_Info.get() == nullptr ) {
70  return;
71  }
72  _ASSERT(m_Info.get() != 0);
73  SInfo& info = *m_Info;
74 
75  {
76  unique_ptr<CObjectIStream> in(CObjectIStream::Create(info.m_DataFormat,
77  *info.m_Source));
78  in->SetFlags(info.m_Flags);
79  info.m_ItemInfo->UpdateDelayedBuffer(*in, info.m_Object);
80  _VERIFY(in->EndOfData());
81  }
82 
83  m_Info.reset(0);
84 }
85 
87 {
88  const SInfo* info = m_Info.get();
89  if ( !info )
90  return kInvalidMember;
91  else
92  return info->m_ItemInfo->GetIndex();
93 }
94 
98  : m_ItemInfo(itemInfo), m_Object(object),
99  m_DataFormat(format), m_Flags(flags),
100  m_Source(&source)
101 {
102 }
103 
105 {
106 }
107 
Include a standard set of the NCBI C++ Toolkit most basic headers.
static uch flags
DEFINE_STATIC_FAST_MUTEX(s_UpdateMutex)
char data[12]
Definition: iconv.c:80
#define _VERIFY(expr)
Definition: ncbidbg.hpp:161
void * TObjectPtr
Definition: serialdef.hpp:55
size_t TMemberIndex
Type used for indexing class members and choice variants.
Definition: serialdef.hpp:230
const TMemberIndex kInvalidMember
Special value returned from FindMember.
Definition: serialdef.hpp:237
ESerialDataFormat
Data file format.
Definition: serialdef.hpp:71
int TFormatFlags
Definition: delaybuf.hpp:107
unique_ptr< SInfo > m_Info
Definition: delaybuf.hpp:142
bool Delayed(void) const
Check if there is input data in the buffer.
Definition: delaybuf.hpp:69
void Forget(void)
Forget the stored data.
Definition: delaybuf.cpp:58
SInfo(const CItemInfo *itemInfo, TObjectPtr object, ESerialDataFormat dataFormat, TFormatFlags flags, CByteSource &source)
Definition: delaybuf.cpp:95
~CDelayBuffer(void)
Definition: delaybuf.cpp:45
static CObjectIStream * Create(ESerialDataFormat format)
Create serial object reader.
Definition: objistr.cpp:144
void DoUpdate(void)
Definition: delaybuf.cpp:63
void SetData(const CItemInfo *itemInfo, TObjectPtr object, ESerialDataFormat dataFormat, TFormatFlags flags, CByteSource &data)
Reset the buffer with a new data.
Definition: delaybuf.cpp:49
TMemberIndex GetIndex(void) const
Get member index.
Definition: delaybuf.cpp:86
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static MDB_envinfo info
Definition: mdb_load.c:37
const CharType(& source)[N]
Definition: pointer.h:1149
static Format format
Definition: njn_ioutil.cpp:53
std::istream & in(std::istream &in_, double &x_)
#define _ASSERT
Modified on Fri Sep 20 14:57:01 2024 by modify_doxy.py rev. 669887