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

Go to the SVN repository for this file.

1 #ifndef OBJOSTRASNB__HPP
2 #define OBJOSTRASNB__HPP
3 
4 /* $Id: objostrasnb.hpp 79560 2017-09-20 17:04:38Z 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 * Encode data object using ASN binary format (BER)
33 */
34 
35 #include <corelib/ncbistd.hpp>
36 #include <serial/objostr.hpp>
38 #include <stack>
39 
40 
41 /** @addtogroup ObjStreamSupport
42  *
43  * @{
44  */
45 
46 
48 
50 
51 /////////////////////////////////////////////////////////////////////////////
52 ///
53 /// CObjectOStreamAsnBinary --
54 ///
55 /// Encode serial object using ASN binary format (BER)
57  public CAsnBinaryDefs
58 {
59 public:
60 
61  /// Constructor.
62  ///
63  /// @param out
64  /// Output stream
65  /// @param how
66  /// Defines how to fix unprintable characters in ASN VisiableString
69 
70  /// Constructor.
71  ///
72  /// @param out
73  /// Output stream
74  /// @param deleteOut
75  /// when TRUE, the output stream will be deleted automatically
76  /// when the writer is deleted
77  /// @param how
78  /// Defines how to fix unprintable characters in ASN VisiableString
79  /// @deprecated
80  /// Use one with EOwnership enum instead
82  bool deleteOut,
83  EFixNonPrint how = eFNP_Default));
84 
85  /// Constructor.
86  ///
87  /// @param out
88  /// Output stream
89  /// @param deleteOut
90  /// When eTakeOwnership, the output stream will be deleted automatically
91  /// when the writer is deleted
92  /// @param how
93  /// Defines how to fix unprintable characters in ASN VisiableString
95  EOwnership deleteOut,
97 
98 
99  /// Destructor.
100  virtual ~CObjectOStreamAsnBinary(void);
101 
102 
103 
104  virtual void WriteEnum(const CEnumeratedTypeValues& values,
105  TEnumValueType value) override;
106  virtual void CopyEnum(const CEnumeratedTypeValues& values,
107  CObjectIStream& in) override;
108 
109  virtual void WriteNull(void) override;
110  virtual void WriteAnyContentObject(const CAnyContentObject& obj) override;
111  virtual void CopyAnyContentObject(CObjectIStream& in) override;
112 
113  virtual void WriteBitString(const CBitString& obj) override;
114  virtual void CopyBitString(CObjectIStream& in) override;
115 
116  void WriteLongTag(ETagClass tag_class,
117  ETagConstructed tag_constructed,
118  TLongTag tag_value);
119  void WriteClassTag(TTypeInfo typeInfo);
120  void WriteLongLength(size_t length);
121 
122  // use ASNTOOL-compatible formatting when writing Int8 and Uint8 types
123  void SetCStyleBigInt(bool set=true)
124  {
125  m_CStyleBigInt = set;
126  }
127  bool GetCStyleBigInt(void) const
128  {
129  return m_CStyleBigInt;
130  }
131 
132 private:
133  void WriteByte(Uint1 byte);
134  template<typename T> void WriteBytesOf(const T& value, size_t count);
135  void WriteBytes(const char* bytes, size_t size);
136  void WriteShortTag(ETagClass tag_class,
137  ETagConstructed tag_constructed,
138  ETagValue tag_value);
139  void WriteSysTag(ETagValue tag);
140  static TByte GetUTF8StringTag(void);
141  static TByte MakeUTF8StringTag(void);
142  void WriteStringTag(EStringType type);
143  void WriteTag(ETagClass tag_class,
144  ETagConstructed tag_constructed,
145  TLongTag tag_value);
146  void WriteIndefiniteLength(void);
147  void WriteShortLength(size_t length);
148  void WriteLength(size_t length);
149  void WriteEndOfContent(void);
150 
151 protected:
152  virtual void WriteBool(bool data) override;
153  virtual void WriteChar(char data) override;
154  virtual void WriteInt4(Int4 data) override;
155  virtual void WriteUint4(Uint4 data) override;
156  virtual void WriteInt8(Int8 data) override;
157  virtual void WriteUint8(Uint8 data) override;
158  virtual void WriteFloat(float data) override;
159  virtual void WriteDouble(double data) override;
160  void WriteDouble2(double data, unsigned digits);
161  virtual void WriteCString(const char* str) override;
162  virtual void WriteString(const string& s,
163  EStringType type = eStringTypeVisible) override;
164  virtual void WriteStringStore(const string& s) override;
165  virtual void CopyString(CObjectIStream& in,
166  EStringType type = eStringTypeVisible) override;
167  virtual void CopyStringStore(CObjectIStream& in) override;
168  void CopyStringValue(CObjectIStreamAsnBinary& in,
169  bool checkVisible = false);
170 
171  virtual void WriteNullPointer(void) override;
172  virtual void WriteObjectReference(TObjectIndex index) override;
173  virtual void WriteOtherBegin(TTypeInfo typeInfo) override;
174  virtual void WriteOtherEnd(TTypeInfo typeInfo) override;
175  virtual void WriteOther(TConstObjectPtr object, TTypeInfo typeInfo) override;
176 
177 #ifdef VIRTUAL_MID_LEVEL_IO
178  virtual void WriteNamedType(TTypeInfo namedTypeInfo,
179  TTypeInfo typeInfo, TConstObjectPtr object) override;
180 
181  virtual void WriteContainer(const CContainerTypeInfo* containerType,
182  TConstObjectPtr containerPtr) override;
183 
184  virtual void WriteClass(const CClassTypeInfo* objectType,
185  TConstObjectPtr objectPtr) override;
186  virtual void WriteClassMember(const CMemberId& memberId,
187  TTypeInfo memberType,
188  TConstObjectPtr memberPtr) override;
189  virtual bool WriteClassMember(const CMemberId& memberId,
190  const CDelayBuffer& buffer) override;
191 
192  // COPY
193  virtual void CopyNamedType(TTypeInfo namedTypeInfo,
194  TTypeInfo typeInfo,
195  CObjectStreamCopier& copier) override;
196  virtual void CopyContainer(const CContainerTypeInfo* containerType,
197  CObjectStreamCopier& copier) override;
198  virtual void CopyClassRandom(const CClassTypeInfo* objectType,
199  CObjectStreamCopier& copier) override;
200  virtual void CopyClassSequential(const CClassTypeInfo* objectType,
201  CObjectStreamCopier& copier) override;
202 #endif
203  virtual void BeginNamedType(TTypeInfo namedTypeInfo) override;
204  virtual void EndNamedType(void) override;
205 
206  virtual void BeginContainer(const CContainerTypeInfo* containerType) override;
207  virtual void EndContainer(void) override;
208 
209  virtual void BeginClass(const CClassTypeInfo* classInfo) override;
210  virtual void EndClass(void) override;
211  virtual void BeginClassMember(const CMemberId& id) override;
212  virtual void EndClassMember(void) override;
213 
214  virtual void BeginChoice(const CChoiceTypeInfo* choiceType) override;
215  virtual void EndChoice(void) override;
216  virtual void BeginChoiceVariant(const CChoiceTypeInfo* choiceType,
217  const CMemberId& id) override;
218  virtual void EndChoiceVariant(void) override;
219 
220  virtual void BeginBytes(const ByteBlock& block) override;
221  virtual void WriteBytes(const ByteBlock& block,
222  const char* bytes, size_t length) override;
223 
224  virtual void BeginChars(const CharBlock& block) override;
225  virtual void WriteChars(const CharBlock& block,
226  const char* chars, size_t length) override;
227 
228 #if HAVE_NCBI_C
229  friend class CObjectOStream::AsnIo;
230 #endif
231 
232 private:
233  void WriteNumberValue(Int4 data);
234  void WriteNumberValue(Int8 data);
235  void WriteNumberValue(Uint4 data);
236  void WriteNumberValue(Uint8 data);
237 
238 #if CHECK_OUTSTREAM_INTEGRITY
239  Int8 m_CurrentPosition;
240  enum ETagState {
241  eTagStart,
242  eTagValue,
243  eLengthStart,
244  eLengthValueFirst,
245  eLengthValue,
246  eData
247  };
248  ETagState m_CurrentTagState;
249  Int8 m_CurrentTagPosition;
250  Uint1 m_CurrentTagCode;
251  size_t m_CurrentTagLengthSize;
252  size_t m_CurrentTagLength;
253  Int8 m_CurrentTagLimit;
254  stack<Int8> m_Limits;
255 
256  void StartTag(TByte code);
257  void EndTag(void);
258  void SetTagLength(size_t length);
259 #endif
263 };
264 
265 
266 /* @} */
267 
268 
270 
271 #endif /* OBJOSTRASNB__HPP */
CNcbiOstream & WriteContainer(CNcbiOstream &os, const TCont &cont)
Write a container to a stream.
Definition: cgi_serial.hpp:216
Serializable object that stores any combination of parsable data.
Definition: serialbase.hpp:264
CDelayBuffer.
Definition: delaybuf.hpp:58
CObjectIStreamAsnBinary –.
Definition: objistrasnb.hpp:59
CObjectIStream –.
Definition: objistr.hpp:93
CObjectOStreamAsnBinary –.
Definition: objostrasnb.hpp:58
CObjectOStream –.
Definition: objostr.hpp:83
CObjectStreamCopier –.
Definition: objcopy.hpp:71
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
Definition: svg.hpp:69
Definition: svg.hpp:50
Definition: set.hpp:45
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define T(s)
Definition: common.h:230
std::ofstream out("events_result.xml")
main entry point for tests
static const char * str(char *buf, int n)
Definition: stats.c:84
char data[12]
Definition: iconv.c:80
#define NCBI_DEPRECATED_CTOR(decl)
Macro used to mark a constructor as deprecated.
Definition: ncbimisc.hpp:1209
EFixNonPrint
How to process non-printing character in the ASN VisibleString.
Definition: serialdef.hpp:173
int TEnumValueType
Definition: serialdef.hpp:232
const void * TConstObjectPtr
Definition: serialdef.hpp:59
EStringType
String type.
Definition: serialdef.hpp:185
@ eFNP_Default
Definition: serialdef.hpp:181
@ eStringTypeVisible
VisibleString (in ASN.1 sense)
Definition: serialdef.hpp:186
virtual void EndClassMember(void)
Definition: objostr.cpp:888
virtual void BeginClass(const CClassTypeInfo *classInfo)=0
virtual void BeginChoice(const CChoiceTypeInfo *choiceType)
Definition: objostr.cpp:1029
virtual void WriteUint8(Uint8 data)=0
virtual void BeginBytes(const ByteBlock &block)
Definition: objostr.cpp:1120
virtual void CopyString(CObjectIStream &in, EStringType type=eStringTypeVisible)=0
virtual void WriteOther(TConstObjectPtr object, TTypeInfo typeInfo)
Definition: objostr.cpp:786
virtual void WriteInt8(Int8 data)=0
virtual void EndClass(void)
Definition: objostr.cpp:884
virtual void WriteString(const string &str, EStringType type=eStringTypeVisible)=0
virtual void WriteBitString(const CBitString &obj)=0
virtual void WriteNullPointer(void)=0
virtual void WriteChar(char data)=0
virtual void CopyAnyContentObject(CObjectIStream &in)=0
virtual void CopyBitString(CObjectIStream &in)=0
virtual void WriteStringStore(const string &data)=0
virtual void WriteOtherEnd(TTypeInfo typeInfo)
Definition: objostr.cpp:794
virtual void WriteInt4(Int4 data)=0
virtual void WriteUint4(Uint4 data)=0
virtual void WriteCString(const char *str)=0
virtual void WriteObjectReference(TObjectIndex index)=0
virtual void BeginChoiceVariant(const CChoiceTypeInfo *choiceType, const CMemberId &id)=0
virtual void WriteChars(const CharBlock &block, const char *chars, size_t length)=0
MLIOVIR void CopyNamedType(TTypeInfo namedTypeInfo, TTypeInfo typeInfo, CObjectStreamCopier &copier)
Definition: objostr.cpp:761
MLIOVIR void WriteClass(const CClassTypeInfo *objectType, TConstObjectPtr objectPtr)
Definition: objostr.cpp:892
virtual void BeginContainer(const CContainerTypeInfo *containerType) override
virtual void CopyEnum(const CEnumeratedTypeValues &values, CObjectIStream &in)=0
virtual void EndContainer(void) override
virtual void WriteBytes(const ByteBlock &block, const char *bytes, size_t length)=0
MLIOVIR void CopyClassRandom(const CClassTypeInfo *objectType, CObjectStreamCopier &copier)
Definition: objostr.cpp:935
bool GetCStyleBigInt(void) const
virtual void CopyStringStore(CObjectIStream &in)=0
virtual void WriteFloat(float data)
Definition: objostr.cpp:721
virtual void EndChoice(void)
Definition: objostr.cpp:1032
virtual void WriteDouble(double data)=0
void SetCStyleBigInt(bool set=true)
virtual void BeginChars(const CharBlock &block)
Definition: objostr.cpp:1150
virtual void EndNamedType(void) override
virtual void WriteNull(void)=0
virtual void BeginNamedType(TTypeInfo namedTypeInfo) override
MLIOVIR void WriteNamedType(TTypeInfo namedTypeInfo, TTypeInfo typeInfo, TConstObjectPtr object)
Definition: objostr.cpp:742
virtual void WriteAnyContentObject(const CAnyContentObject &obj)=0
virtual void BeginClassMember(const CMemberId &id)=0
virtual void WriteOtherBegin(TTypeInfo typeInfo)=0
virtual void WriteBool(bool data)=0
virtual void EndChoiceVariant(void)
Definition: objostr.cpp:1035
virtual void WriteEnum(const CEnumeratedTypeValues &values, TEnumValueType value)=0
MLIOVIR void CopyClassSequential(const CClassTypeInfo *objectType, CObjectStreamCopier &copier)
Definition: objostr.cpp:984
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
enum ENcbiOwnership EOwnership
Ownership relations between objects.
#define NCBI_XSERIAL_EXPORT
Definition: ncbi_export.h:1435
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
static const BitmapCharRec *const chars[]
Definition: ncbi_10x20.c:1829
const char * tag
std::istream & in(std::istream &in_, double &x_)
static pcre_uint8 * buffer
Definition: pcretest.c:1051
static void WriteClassMember(CObjectOStream &out, const CObjectInfoMI &member)
Definition: read_hooks.cpp:47
void CopyContainer(const C1 &src, C2 &dst)
Definition: inftrees.h:24
Definition: type.c:6
Modified on Wed Jul 17 13:20:42 2024 by modify_doxy.py rev. 669887