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

Go to the SVN repository for this file.

1 /* $Id: delaybuf.cpp 56236 2012-11-14 14:51:26Z 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 
44 {
45 }
46 
47 void CDelayBuffer::SetData(const CItemInfo* itemInfo, TObjectPtr object,
48  ESerialDataFormat dataFormat, TFormatFlags flags,
49  CByteSource& data)
50 {
51  _ASSERT(!Delayed());
52 
53  m_Info.reset(new SInfo(itemInfo, object, dataFormat, flags, data));
54 }
55 
57 {
58  m_Info.reset(0);
59 }
60 
62 {
63  _ASSERT(m_Info.get() != 0);
64  SInfo& info = *m_Info;
65 
66  {
67  auto_ptr<CObjectIStream> in(CObjectIStream::Create(info.m_DataFormat,
68  *info.m_Source));
69  in->SetFlags(info.m_Flags);
70  info.m_ItemInfo->UpdateDelayedBuffer(*in, info.m_Object);
71  _VERIFY(in->EndOfData());
72  }
73 
74  m_Info.reset(0);
75 }
76 
78 {
79  const SInfo* info = m_Info.get();
80  if ( !info )
81  return kInvalidMember;
82  else
83  return info->m_ItemInfo->GetIndex();
84 }
85 
89  : m_ItemInfo(itemInfo), m_Object(object),
90  m_DataFormat(format), m_Flags(flags),
91  m_Source(&source)
92 {
93 }
94 
96 {
97 }
98 
int TFormatFlags
Definition: delaybuf.hpp:107
const TMemberIndex kInvalidMember
Special value returned from FindMember.
Definition: serialdef.hpp:219
TMemberIndex GetIndex(void) const
static CObjectIStream * Create(ESerialDataFormat format)
Create serial object reader.
Definition: objistr.cpp:134
ESerialDataFormat format
~CDelayBuffer(void)
Definition: delaybuf.cpp:43
#define _VERIFY(expr)
Definition: ncbidbg.hpp:159
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
const CItemInfo * m_ItemInfo
Definition: delaybuf.hpp:124
auto_ptr< SInfo > m_Info
Definition: delaybuf.hpp:142
size_t TMemberIndex
Type used for indexing class members and choice variants.
Definition: serialdef.hpp:212
void Forget(void)
Forget the stored data.
Definition: delaybuf.cpp:56
bool Delayed(void) const
Check if there is input data in the buffer.
Definition: delaybuf.hpp:69
const CharType(& source)[N]
Definition: pointer.h:1107
SInfo(const CItemInfo *itemInfo, TObjectPtr object, ESerialDataFormat dataFormat, TFormatFlags flags, CByteSource &source)
Definition: delaybuf.cpp:86
void SetData(const CItemInfo *itemInfo, TObjectPtr object, ESerialDataFormat dataFormat, TFormatFlags flags, CByteSource &data)
Reset the buffer with a new data.
Definition: delaybuf.cpp:47
ESerialDataFormat
Data file format.
Definition: serialdef.hpp:71
void DoUpdate(void)
Definition: delaybuf.cpp:61
#define _ASSERT
TMemberIndex GetIndex(void) const
Get member index.
Definition: delaybuf.cpp:77
std::istream & in(std::istream &in_, double &x_)
void * TObjectPtr
Definition: serialdef.hpp:55
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
Modified on Wed May 24 16:18:35 2017 by modify_doxy.py rev. 533848