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 */
bitvector Bit-vector container with runtime compression of bits
Definition: bm.h:108
virtual void WriteSeparator(void)
Definition: objostr.cpp:1170
CObjectIStream –.
Definition: objistr.hpp:92
virtual void WriteStringStore(const string &data)=0
unsigned NCBI_INT8_TYPE Uint8
Unsigned 8 byte sized integer.
Definition: ncbitype.h:146
signed int Int4
Alias for signed int.
Definition: ncbitype.h:120
unsigned int Uint4
Alias for unsigned int.
Definition: ncbitype.h:121
virtual void WriteBytes(const ByteBlock &block, const char *bytes, size_t length)=0
std::ofstream out("events_result.xml")
main entry point for tests
virtual void WriteChars(const CharBlock &block, const char *chars, size_t length)=0
EStringType
String type.
Definition: serialdef.hpp:184
virtual void CopyEnum(const CEnumeratedTypeValues &values, CObjectIStream &in)=0
virtual void BeginBytes(const ByteBlock &block)
Definition: objostr.cpp:1109
CObjectOStreamAsn –.
Definition: objostrasn.hpp:52
virtual void BeginChoice(const CChoiceTypeInfo *choiceType)
Definition: objostr.cpp:1018
CObjectOStream –.
Definition: objostr.hpp:82
virtual void WriteObjectReference(TObjectIndex index)=0
virtual void WriteEnum(const CEnumeratedTypeValues &values, TEnumValueType value)=0
CObjectStreamCopier –.
Definition: objcopy.hpp:70
signed NCBI_INT8_TYPE Int8
Signed 8 byte sized integer.
Definition: ncbitype.h:143
Serializable object that stores any combination of parsable data.
Definition: serialbase.hpp:263
MLIOVIR void WriteClass(const CClassTypeInfo *objectType, TConstObjectPtr objectPtr)
Definition: objostr.cpp:881
virtual void EndContainer(void)
Definition: objostr.cpp:787
static const BitmapCharRec *const chars[]
Definition: ncbi_10x20.c:1829
MLIOVIR void CopyClassSequential(const CClassTypeInfo *objectType, CObjectStreamCopier &copier)
Definition: objostr.cpp:973
const void * TConstObjectPtr
Definition: serialdef.hpp:59
virtual void CopyAnyContentObject(CObjectIStream &in)=0
virtual void WriteBitString(const CBitString &obj)=0
MLIOVIR void CopyClassRandom(const CClassTypeInfo *objectType, CObjectStreamCopier &copier)
Definition: objostr.cpp:924
virtual void WriteOtherBegin(TTypeInfo typeInfo)=0
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
size_t TObjectIndex
Definition: objostr.hpp:772
MLIOVIR void CopyContainer(const CContainerTypeInfo *containerType, CObjectStreamCopier &copier)
Definition: objostr.cpp:847
virtual void BeginContainer(const CContainerTypeInfo *containerType)=0
virtual void BeginChars(const CharBlock &block)
Definition: objostr.cpp:1139
virtual void WriteString(const string &str, EStringType type=eStringTypeVisible)=0
int TEnumValueType
Definition: serialdef.hpp:231
#define NCBI_DEPRECATED_CTOR(decl)
Macro used to mark a constructor as deprecated.
Definition: ncbimisc.hpp:1118
virtual void WriteOther(TConstObjectPtr object, TTypeInfo typeInfo)
Definition: objostr.cpp:775
MLIOVIR void WriteContainer(const CContainerTypeInfo *containerType, TConstObjectPtr containerPtr)
Definition: objostr.cpp:799
virtual void BeginClassMember(const CMemberId &id)=0
virtual void WriteChar(char data)=0
Definition: type.c:5
virtual void EndChars(const CharBlock &block)
Definition: objostr.cpp:1143
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:142
virtual void BeginContainerElement(TTypeInfo elementType)
Definition: objostr.cpp:791
VisibleString (in ASN.1 sense)
Definition: serialdef.hpp:185
virtual void WriteInt8(Int8 data)=0
virtual void WriteFileHeader(TTypeInfo type)
Definition: objostr.cpp:669
virtual void WriteFloat(float data)
Definition: objostr.cpp:710
#define NCBI_XSERIAL_EXPORT
Definition: ncbi_export.h:1410
virtual void EndChoice(void)
Definition: objostr.cpp:1021
void WriteClassMember(const CConstObjectInfoMI &member)
Definition: objostr.cpp:560
virtual void WriteDouble(double data)=0
virtual void WriteNullPointer(void)=0
virtual void EndClass(void)
Definition: objostr.cpp:873
virtual void EndBytes(const ByteBlock &block)
Definition: objostr.cpp:1113
CDelayBuffer.
Definition: delaybuf.hpp:57
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1185
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:74
virtual void WriteCString(const char *str)=0
enum ENcbiOwnership EOwnership
Ownership relations between objects.
virtual void WriteAnyContentObject(const CAnyContentObject &obj)=0
virtual string GetPosition(void) const override
Get current stream position as string.
Definition: objostr.cpp:499
virtual void CopyString(CObjectIStream &in, EStringType type=eStringTypeVisible)=0
virtual void CopyStringStore(CObjectIStream &in)=0
virtual void WriteBool(bool data)=0
virtual void BeginClass(const CClassTypeInfo *classInfo)=0
virtual void BeginChoiceVariant(const CChoiceTypeInfo *choiceType, const CMemberId &id)=0
virtual void WriteInt4(Int4 data)=0
virtual void WriteUint4(Uint4 data)=0
std::istream & in(std::istream &in_, double &x_)
virtual void CopyBitString(CObjectIStream &in)=0
static const char * str(char *buf, int n)
Definition: stats.c:84
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
virtual void WriteUint8(Uint8 data)=0
static uschar * buffer
Definition: pcretest.c:187
EFixNonPrint
How to process non-printing character in the ASN VisibleString.
Definition: serialdef.hpp:173
virtual void WriteNull(void)=0
Modified on Mon Apr 23 11:46:55 2018 by modify_doxy.py rev. 546573