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

Go to the SVN repository for this file.

1 #ifndef OBJOSTRASN__HPP
2 #define OBJOSTRASN__HPP
3 
4 /* $Id: objostrasn.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 text format
33 */
34 
35 #include <corelib/ncbistd.hpp>
36 #include <serial/objostr.hpp>
37 
38 
39 /** @addtogroup ObjStreamSupport
40  *
41  * @{
42  */
43 
44 
46 
47 /////////////////////////////////////////////////////////////////////////////
48 ///
49 /// CObjectOStreamAsn --
50 ///
51 /// Encode serial data object using ASN text format
53 {
54 public:
55 
56  /// Constructor.
57  ///
58  /// @param out
59  /// Output stream
60  /// @param how
61  /// Defines how to fix unprintable characters in ASN VisiableString
64 
65  /// Constructor.
66  ///
67  /// @param out
68  /// Output stream
69  /// @param deleteOut
70  /// when TRUE, the output stream will be deleted automatically
71  /// when the writer is deleted
72  /// @param how
73  /// Defines how to fix unprintable characters in ASN VisiableString
74  /// @deprecated
75  /// Use one with EOwnership enum instead
77  bool deleteOut,
78  EFixNonPrint how = eFNP_Default));
79 
80  /// Constructor.
81  ///
82  /// @param out
83  /// Output stream
84  /// @param deleteOut
85  /// When eTakeOwnership, the output stream will be deleted automatically
86  /// when the writer is deleted
87  /// @param how
88  /// Defines how to fix unprintable characters in ASN VisiableString
90  EOwnership deleteOut,
92 
93  /// Destructor.
94  virtual ~CObjectOStreamAsn(void);
95 
96  /// Get current stream position as string.
97  /// Useful for diagnostic and information messages.
98  ///
99  /// @return
100  /// string
101  virtual string GetPosition(void) const override;
102 
103 
104  virtual void WriteFileHeader(TTypeInfo type) override;
105  virtual void WriteEnum(const CEnumeratedTypeValues& values,
106  TEnumValueType value) override;
107  virtual void CopyEnum(const CEnumeratedTypeValues& values,
108  CObjectIStream& in) override;
109 
110 protected:
111  void WriteEnum(const CEnumeratedTypeValues& values,
112  TEnumValueType value, const string& valueName);
113  virtual void WriteBool(bool data) override;
114  virtual void WriteChar(char data) override;
115  virtual void WriteInt4(Int4 data) override;
116  virtual void WriteUint4(Uint4 data) override;
117  virtual void WriteInt8(Int8 data) override;
118  virtual void WriteUint8(Uint8 data) override;
119  virtual void WriteFloat(float data) override;
120  virtual void WriteDouble(double data) override;
121  void WriteDouble2(double data, unsigned digits);
122  virtual void WriteCString(const char* str) override;
123  virtual void WriteString(const string& str,
124  EStringType type = eStringTypeVisible) override;
125  virtual void WriteStringStore(const string& str) override;
126  virtual void CopyString(CObjectIStream& in,
127  EStringType type = eStringTypeVisible) override;
128  virtual void CopyStringStore(CObjectIStream& in) override;
129 
130  virtual void WriteNullPointer(void) override;
131  virtual void WriteObjectReference(TObjectIndex index) override;
132  virtual void WriteOtherBegin(TTypeInfo typeInfo) override;
133  virtual void WriteOther(TConstObjectPtr object, TTypeInfo typeInfo) override;
134  void WriteId(const string& str, bool checkCase = false);
135 
136  virtual void WriteNull(void) override;
137  virtual void WriteAnyContentObject(const CAnyContentObject& obj) override;
138  virtual void CopyAnyContentObject(CObjectIStream& in) override;
139 
140  virtual void WriteBitString(const CBitString& obj) override;
141  virtual void CopyBitString(CObjectIStream& in) override;
142 
143 #ifdef VIRTUAL_MID_LEVEL_IO
144  virtual void WriteContainer(const CContainerTypeInfo* containerType,
145  TConstObjectPtr containerPtr) override;
146 
147  virtual void WriteClass(const CClassTypeInfo* objectType,
148  TConstObjectPtr objectPtr) override;
149  virtual void WriteClassMember(const CMemberId& memberId,
150  TTypeInfo memberType,
151  TConstObjectPtr memberPtr) override;
152  virtual bool WriteClassMember(const CMemberId& memberId,
153  const CDelayBuffer& buffer) override;
154 
155  // COPY
156  virtual void CopyContainer(const CContainerTypeInfo* containerType,
157  CObjectStreamCopier& copier) override;
158  virtual void CopyClassRandom(const CClassTypeInfo* objectType,
159  CObjectStreamCopier& copier) override;
160  virtual void CopyClassSequential(const CClassTypeInfo* objectType,
161  CObjectStreamCopier& copier) override;
162 #endif
163  // low level I/O
164  virtual void BeginContainer(const CContainerTypeInfo* containerType) override;
165  virtual void EndContainer(void) override;
166  virtual void BeginContainerElement(TTypeInfo elementType) override;
167 
168  virtual void BeginClass(const CClassTypeInfo* classInfo) override;
169  virtual void EndClass(void) override;
170  virtual void BeginClassMember(const CMemberId& id) override;
171 
172  virtual void BeginChoice(const CChoiceTypeInfo* choiceType) override;
173  virtual void EndChoice(void) override;
174  virtual void BeginChoiceVariant(const CChoiceTypeInfo* choiceType,
175  const CMemberId& id) override;
176 
177  virtual void BeginBytes(const ByteBlock& block) override;
178  virtual void WriteBytes(const ByteBlock& block,
179  const char* bytes, size_t length) override;
180  virtual void EndBytes(const ByteBlock& block) override;
181 
182  virtual void BeginChars(const CharBlock& block) override;
183  virtual void WriteChars(const CharBlock& block,
184  const char* chars, size_t length) override;
185  virtual void EndChars(const CharBlock& block) override;
186 
187  // Write current separator to the stream
188  virtual void WriteSeparator(void) override;
189 
190 private:
191  void WriteBytes(const char* bytes, size_t length);
192  void WriteString(const char* str, size_t length);
193  void WriteMemberId(const CMemberId& id);
194 
195  void StartBlock(void);
196  void NextElement(void);
197  void EndBlock(void);
198 
200 };
201 
202 
203 /* @} */
204 
205 
207 
208 #endif /* OBJOSTRASN__HPP */
Serializable object that stores any combination of parsable data.
Definition: serialbase.hpp:264
CDelayBuffer.
Definition: delaybuf.hpp:58
CObjectIStream –.
Definition: objistr.hpp:93
CObjectOStreamAsn –.
Definition: objostrasn.hpp:53
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
Include a standard set of the NCBI C++ Toolkit most basic headers.
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 BeginClass(const CClassTypeInfo *classInfo)=0
void WriteClassMember(const CConstObjectInfoMI &member)
Definition: objostr.cpp:571
virtual void EndBytes(const ByteBlock &block)
Definition: objostr.cpp:1124
virtual void WriteFileHeader(TTypeInfo type)
Definition: objostr.cpp:680
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 EndChars(const CharBlock &block)
Definition: objostr.cpp:1154
virtual void WriteInt8(Int8 data)=0
virtual void EndClass(void)
Definition: objostr.cpp:884
virtual void WriteSeparator(void)
Definition: objostr.cpp:1181
virtual void WriteString(const string &str, EStringType type=eStringTypeVisible)=0
virtual void WriteBitString(const CBitString &obj)=0
virtual void WriteNullPointer(void)=0
MLIOVIR void WriteContainer(const CContainerTypeInfo *containerType, TConstObjectPtr containerPtr)
Definition: objostr.cpp:810
virtual void WriteChar(char data)=0
virtual void CopyAnyContentObject(CObjectIStream &in)=0
virtual void CopyBitString(CObjectIStream &in)=0
virtual void BeginContainer(const CContainerTypeInfo *containerType)=0
virtual void WriteStringStore(const string &data)=0
virtual void WriteInt4(Int4 data)=0
virtual void WriteUint4(Uint4 data)=0
virtual void WriteCString(const char *str)=0
size_t TObjectIndex
Definition: objostr.hpp:775
virtual void WriteObjectReference(TObjectIndex index)=0
virtual void BeginChoiceVariant(const CChoiceTypeInfo *choiceType, const CMemberId &id)=0
virtual string GetPosition(void) const override
Get current stream position as string.
Definition: objostr.cpp:510
virtual void WriteChars(const CharBlock &block, const char *chars, size_t length)=0
MLIOVIR void WriteClass(const CClassTypeInfo *objectType, TConstObjectPtr objectPtr)
Definition: objostr.cpp:892
virtual void CopyEnum(const CEnumeratedTypeValues &values, CObjectIStream &in)=0
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
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
virtual void BeginChars(const CharBlock &block)
Definition: objostr.cpp:1150
virtual void WriteNull(void)=0
MLIOVIR void CopyContainer(const CContainerTypeInfo *containerType, CObjectStreamCopier &copier)
Definition: objostr.cpp:858
virtual void WriteAnyContentObject(const CAnyContentObject &obj)=0
virtual void BeginContainerElement(TTypeInfo elementType)
Definition: objostr.cpp:802
virtual void BeginClassMember(const CMemberId &id)=0
virtual void WriteOtherBegin(TTypeInfo typeInfo)=0
virtual void WriteBool(bool data)=0
virtual void EndContainer(void)
Definition: objostr.cpp:798
virtual void WriteEnum(const CEnumeratedTypeValues &values, TEnumValueType value)=0
MLIOVIR void CopyClassSequential(const CClassTypeInfo *objectType, CObjectStreamCopier &copier)
Definition: objostr.cpp:984
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 GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
static const BitmapCharRec *const chars[]
Definition: ncbi_10x20.c:1829
std::istream & in(std::istream &in_, double &x_)
static pcre_uint8 * buffer
Definition: pcretest.c:1051
Definition: type.c:6
Modified on Tue Apr 23 07:37:16 2024 by modify_doxy.py rev. 669887