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

Go to the SVN repository for this file.

1 #ifndef OBJISTRASN__HPP
2 #define OBJISTRASN__HPP
3 
4 /* $Id: objistrasn.hpp 97030 2022-06-10 12:57:23Z ludwigf $
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 * Decode input data in ASN text format
33 */
34 
35 #include <corelib/ncbistd.hpp>
36 #include <serial/objistr.hpp>
37 #include <corelib/tempstr.hpp>
38 
39 
40 /** @addtogroup ObjStreamSupport
41  *
42  * @{
43  */
44 
45 
47 
48 /////////////////////////////////////////////////////////////////////////////
49 ///
50 /// CObjectIStreamAsn --
51 ///
52 /// Decode input data in ASN.1 text format
54 {
55 public:
56  /// Constructor.
57  ///
58  /// @param how
59  /// Defines how to fix unprintable characters in ASN VisiableString
61 
62  /// Constructor.
63  ///
64  /// @param in
65  /// input stream
66  /// @param how
67  /// Defines how to fix unprintable characters in ASN VisiableString
70 
71  /// Constructor.
72  ///
73  /// @param in
74  /// input stream
75  /// @param deleteIn
76  /// when TRUE, the input stream will be deleted automatically
77  /// when the reader is deleted
78  /// @param how
79  /// Defines how to fix unprintable characters in ASN VisiableString
80  /// @deprecated
81  /// Use one with EOwnership enum instead
83  bool deleteIn,
84  EFixNonPrint how = eFNP_Default));
85 
86  /// Constructor.
87  ///
88  /// @param in
89  /// input stream
90  /// @param deleteIn
91  /// When eTakeOwnership, the input stream will be deleted automatically
92  /// when the reader is deleted
93  /// @param how
94  /// Defines how to fix unprintable characters in ASN VisiableString
96  EOwnership deleteIn,
98 
99  /// Constructor.
100  ///
101  /// @param buffer
102  /// Data source memory buffer
103  /// @param size
104  /// Memory buffer size
105  /// @param how
106  /// Defines how to fix unprintable characters in ASN VisiableString
107  CObjectIStreamAsn(const char* buffer, size_t size,
108  EFixNonPrint how = eFNP_Default);
109 
110  /// Check if there is still some meaningful data that can be read;
111  /// this function will skip white spaces and comments
112  ///
113  /// @return
114  /// TRUE if there is no more data
115  virtual bool EndOfData(void) override;
116 
117 
118  /// Get current stream location as tuple (positiontype:string, size_t).
119  /// Useful for customized diagnostic and information messages.
120  /// The meaning of positiontype depends on the implementation and coincides
121  /// with the prefix of the string returned by GetPosition().
122  ///
123  virtual void Location(string&, size_t&) const override;
124 
125  virtual string ReadFileHeader(void) override;
126  virtual TEnumValueType ReadEnum(const CEnumeratedTypeValues& values) override;
127  virtual void ReadNull(void) override;
128 
129  void ReadAnyContent(string& value);
130  virtual void ReadAnyContentObject(CAnyContentObject& obj) override;
131  void SkipAnyContent(void);
132  virtual void SkipAnyContentObject(void) override;
133 
134  virtual void ReadBitString(CBitString& obj) override;
135  virtual void SkipBitString(void) override;
136 
137 protected:
139 
140  // action: read ID into local buffer
141  // return: ID pointer and length
142  // note: it is not zero ended
143  CTempString ScanEndOfId(bool isId);
144  CTempString ReadTypeId(char firstChar);
145  CTempString ReadMemberId(char firstChar);
146  CTempString ReadUCaseId(char firstChar);
147  CTempString ReadLCaseId(char firstChar);
148  CTempString ReadNumber(void);
149 
150  virtual bool ReadBool(void) override;
151  virtual char ReadChar(void) override;
152  virtual Int4 ReadInt4(void) override;
153  virtual Uint4 ReadUint4(void) override;
154  virtual Int8 ReadInt8(void) override;
155  virtual Uint8 ReadUint8(void) override;
156  virtual double ReadDouble(void) override;
157  virtual void ReadString(string& s,EStringType type = eStringTypeVisible) override;
158  void ReadStringValue(string& s, EFixNonPrint fix_method);
159  void FixInput(size_t count, EFixNonPrint fix_method, size_t line);
160 
161  virtual void SkipBool(void) override;
162  virtual void SkipChar(void) override;
163  virtual void SkipSNumber(void) override;
164  virtual void SkipUNumber(void) override;
165  virtual void SkipFNumber(void) override;
166  virtual void SkipString(EStringType type = eStringTypeVisible) override;
167  virtual void SkipNull(void) override;
168  virtual void SkipByteBlock(void) override;
169 
170 #ifdef VIRTUAL_MID_LEVEL_IO
171  virtual void ReadContainer(const CContainerTypeInfo* containerType,
172  TObjectPtr containerPtr) override;
173  virtual void SkipContainer(const CContainerTypeInfo* containerType) override;
174 
175  virtual void ReadClassSequential(const CClassTypeInfo* classType,
176  TObjectPtr classPtr) override;
177  virtual void ReadClassRandom(const CClassTypeInfo* classType,
178  TObjectPtr classPtr) override;
179  virtual void SkipClassSequential(const CClassTypeInfo* classType) override;
180  virtual void SkipClassRandom(const CClassTypeInfo* classType) override;
181 #endif
182  // low level I/O
183  virtual void BeginContainer(const CContainerTypeInfo* containerType) override;
184  virtual void EndContainer(void) override;
185  virtual bool BeginContainerElement(TTypeInfo elementType) override;
186 
187  virtual void BeginClass(const CClassTypeInfo* classInfo) override;
188  virtual void EndClass(void) override;
189 
190  virtual TMemberIndex BeginClassMember(const CClassTypeInfo* classType) override;
191  virtual TMemberIndex BeginClassMember(const CClassTypeInfo* classType,
192  TMemberIndex pos) override;
193 
194  virtual void BeginChoice(const CChoiceTypeInfo* choiceType) override;
195  virtual void EndChoice(void) override;
196  virtual TMemberIndex BeginChoiceVariant(const CChoiceTypeInfo* choiceType) override;
197 
198  virtual void BeginBytes(ByteBlock& block) override;
199  int GetHexChar(void);
200  virtual size_t ReadBytes(ByteBlock& block, char* dst, size_t length) override;
201  virtual void EndBytes(const ByteBlock& block) override;
202 
203  virtual void BeginChars(CharBlock& block) override;
204  virtual size_t ReadChars(CharBlock& block, char* dst, size_t length) override;
205 
206 private:
207  virtual EPointerType ReadPointerType(void) override;
208  virtual TObjectIndex ReadObjectPointer(void) override;
209  virtual string ReadOtherPointer(void) override;
210  virtual void StartDelayBuffer(void) override;
211 
212  // low level methods
213  char GetChar(void);
214  char PeekChar(void);
215 
216  // parse methods
217  char GetChar(bool skipWhiteSpace);
218  char PeekChar(bool skipWhiteSpace);
219 
220  bool GetChar(char c, bool skipWhiteSpace = false);
221  void Expect(char c, bool skipWhiteSpace = false);
222  bool Expect(char charTrue, char charFalse, bool skipWhiteSpace = false);
223  void ExpectString(const char* s, bool skipWhiteSpace = false);
224 
225  static bool FirstIdChar(char c);
226  static bool IdChar(char c);
227 
228  void SkipEndOfLine(char c);
229  char SkipWhiteSpace(void);
230  char SkipWhiteSpaceAndGetChar(void);
231  void SkipComments(void);
232  void UnexpectedMember(const CTempString& id, const CItemsInfo& items);
233  void BadStringChar(size_t startLine, char c);
234  void UnendedString(size_t startLine);
235 
236  void AppendStringData(string& s,
237  size_t count,
238  EFixNonPrint fix_method,
239  size_t line);
240  void AppendLongStringData(string& s,
241  size_t count,
242  EFixNonPrint fix_method,
243  size_t line);
244 
245  void StartBlock(void);
246  bool NextElement(void);
247  void EndBlock(void);
248  TMemberIndex GetAltItemIndex(const CClassTypeInfoBase* classType,
249  const CTempString& id,
250  const TMemberIndex pos = kInvalidMember);
251  TMemberIndex GetMemberIndex(const CClassTypeInfo* classType,
252  const CTempString& id);
253  TMemberIndex GetMemberIndex(const CClassTypeInfo* classType,
254  const CTempString& id,
255  const TMemberIndex pos);
256  TMemberIndex GetChoiceIndex(const CChoiceTypeInfo* choiceType,
257  const CTempString& id);
258 
260 };
261 
262 
263 /* @} */
264 
265 
267 
268 #endif /* OBJISTRB__HPP */
void SkipComments(CStreamBuffer &b)
Definition: test.cpp:37
char SkipWhiteSpace(CStreamBuffer &b)
Definition: test.cpp:78
void ReadNumber(CStreamBuffer &b)
Definition: test.cpp:172
void SkipEndOfLine(CStreamBuffer &b, char lastChar)
Definition: test.cpp:32
bool IdChar(char c)
Definition: test.cpp:26
int GetHexChar(CStreamBuffer &b)
Definition: test.cpp:235
bool FirstIdChar(char c)
Definition: test.cpp:20
char SkipWhiteSpaceAndGetChar(CStreamBuffer &b)
Definition: test.cpp:110
Serializable object that stores any combination of parsable data.
Definition: serialbase.hpp:264
CObjectIStreamAsn –.
Definition: objistrasn.hpp:54
CObjectIStream –.
Definition: objistr.hpp:93
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
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.
#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
void * TObjectPtr
Definition: serialdef.hpp:55
int TEnumValueType
Definition: serialdef.hpp:232
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
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 ReadString(string &s, EStringType type=eStringTypeVisible)=0
virtual EPointerType ReadPointerType(void)=0
virtual bool ReadBool(void)=0
virtual void Location(string &, size_t &) const
Get current stream location as tuple (positiontype:string, size_t).
Definition: objistr.cpp:815
MLIOVIR void ReadClassSequential(const CClassTypeInfo *classType, TObjectPtr classPtr)
Definition: objistr.cpp:1398
virtual void ReadNull(void)=0
virtual void EndContainer(void)=0
virtual void EndBytes(const ByteBlock &block)
Definition: objistr.cpp:1671
virtual void SkipByteBlock(void)=0
virtual bool EndOfData(void)
Check if there is still some meaningful data that can be read; in text streams this function will ski...
Definition: objistr.cpp:588
virtual TMemberIndex BeginClassMember(const CClassTypeInfo *classType)=0
virtual size_t ReadChars(CharBlock &block, char *buffer, size_t count)=0
virtual string ReadOtherPointer(void)=0
virtual void SkipString(EStringType type=eStringTypeVisible)=0
MLIOVIR void ReadContainer(const CContainerTypeInfo *containerType, TObjectPtr containerPtr)
Definition: objistr.cpp:1318
virtual void SkipFNumber(void)=0
virtual void BeginBytes(ByteBlock &block)=0
virtual double ReadDouble(void)=0
virtual string ReadFileHeader(void)
Read file header.
Definition: objistr.cpp:1121
virtual void SkipBool(void)=0
virtual TMemberIndex BeginChoiceVariant(const CChoiceTypeInfo *choiceType)=0
virtual void SkipSNumber(void)=0
virtual void BeginContainer(const CContainerTypeInfo *containerType)=0
virtual void SkipUNumber(void)=0
virtual Uint4 ReadUint4(void)
Definition: objistr.cpp:1724
virtual void SkipNull(void)=0
virtual void BeginChars(CharBlock &block)=0
virtual char ReadChar(void)=0
virtual void ReadAnyContentObject(CAnyContentObject &obj)=0
virtual size_t ReadBytes(ByteBlock &block, char *buffer, size_t count)=0
virtual void ReadBitString(CBitString &obj)=0
virtual void SkipBitString(void)=0
TObjectIndex ReadIndex(void)
virtual TEnumValueType ReadEnum(const CEnumeratedTypeValues &values)=0
size_t TObjectIndex
Definition: objistr.hpp:1029
virtual bool BeginContainerElement(TTypeInfo elementType)=0
virtual Int8 ReadInt8(void)=0
virtual TObjectIndex ReadObjectPointer(void)=0
MLIOVIR void SkipContainer(const CContainerTypeInfo *containerType)
Definition: objistr.cpp:1349
MLIOVIR void SkipClassSequential(const CClassTypeInfo *classType)
Definition: objistr.cpp:1451
virtual Int4 ReadInt4(void)
Definition: objistr.cpp:1715
virtual void SkipAnyContentObject(void)=0
virtual Uint8 ReadUint8(void)=0
virtual void EndClass(void)
Definition: objistr.cpp:1368
virtual void StartDelayBuffer(void)
Definition: objistr.cpp:1014
virtual void BeginClass(const CClassTypeInfo *classInfo)=0
void FixInput(size_t count, EFixNonPrint fix_method, size_t line)
virtual void EndChoice(void)
Definition: objistr.cpp:1475
MLIOVIR void SkipClassRandom(const CClassTypeInfo *classType)
Definition: objistr.cpp:1430
void ExpectString(const char *s, bool skipWhiteSpace=false)
virtual void BeginChoice(const CChoiceTypeInfo *choiceType)
Definition: objistr.cpp:1472
MLIOVIR void ReadClassRandom(const CClassTypeInfo *classType, TObjectPtr classPtr)
Definition: objistr.cpp:1376
virtual void SkipChar(void)=0
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::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
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
std::istream & in(std::istream &in_, double &x_)
#define count
static uint8_t * buffer
Definition: pcre2test.c:1016
Definition: type.c:6
Modified on Fri Sep 20 14:58:30 2024 by modify_doxy.py rev. 669887