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

Go to the SVN repository for this file.

1 #ifndef OBJSTACK__HPP
2 #define OBJSTACK__HPP
3 
4 /* $Id: objstack.hpp 98867 2023-01-18 13:06:21Z 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 * !!! PUT YOUR DESCRIPTION HERE !!!
33 */
34 
35 #define VIRTUAL_MID_LEVEL_IO 1
36 //#undef VIRTUAL_MID_LEVEL_IO
37 
38 #ifdef VIRTUAL_MID_LEVEL_IO
39 # define MLIOVIR virtual
40 #else
41 # define MLIOVIR
42 #endif
43 
44 #include <corelib/ncbistd.hpp>
45 #include <serial/exception.hpp>
46 #include <serial/impl/memberid.hpp>
47 #include <serial/typeinfo.hpp>
48 
49 
50 /** @addtogroup ObjStreamSupport
51  *
52  * @{
53  */
54 
55 
57 
58 class CObjectStack;
59 
61 {
62 public:
63  enum EFrameType {
64  eFrameOther = 0,
71  eFrameChoiceVariant
72  };
73 
74  void Reset(void);
75 
76  EFrameType GetFrameType(void) const;
77  bool HasTypeInfo(void) const;
78  bool HasTypeInfo(TTypeInfo type) const;
79  TTypeInfo GetTypeInfo(void) const;
80  bool HasMemberId(void) const;
81  const CMemberId& GetMemberId(void) const;
82 
84 
85  void SetNotag(bool set=true);
86  bool GetNotag(void) const;
87 
88  void SetNoEOC(bool set=true);
89  bool GetNoEOC(void) const;
90 
91  const char* GetFrameTypeName(void) const;
92  string GetFrameInfo(void) const;
93  string GetFrameName(void) const;
94 
97 
98 protected:
99  void SetMemberId(const CMemberId& memberid);
100 
101 private:
102  friend class CObjectStack;
103 
109  bool m_Notag; // means no XML tag
110  bool m_NoEOC; // no binary ASN end-of-content mark
111 };
112 
113 #define ThrowError(flag, mess) \
114  ThrowError1(DIAG_COMPILE_INFO,flag,mess)
115 
117 {
118 public:
121 
122  CObjectStack(void);
123  virtual ~CObjectStack(void);
124 
125  size_t GetStackDepth(void) const;
126 
128  TConstObjectPtr objectPtr = 0);
131 
132  void PopFrame(void);
133  void PopErrorFrame(void);
134 
135  void SetTopMemberId(const CMemberId& memberId);
136  bool IsNsQualified(void);
137 
138  bool IsCompressed(void) const;
139 
140 #if defined(NCBI_SERIAL_IO_TRACE)
141  void TracePushFrame(bool push) const;
142 #endif
143 
144 
145  bool StackIsEmpty(void) const;
146 
147  void ClearStack(void);
148 
149  string GetStackTraceASN(void) const;
150  virtual string GetStackTrace(void) const = 0;
151  virtual string GetPosition(void) const = 0;
152 
153  const TFrame& TopFrame(void) const;
154  TFrame& TopFrame(void);
155 
156  TFrame& FetchFrameFromTop(size_t index);
157  const TFrame& FetchFrameFromTop(size_t index) const;
158  const TFrame& FetchFrameFromBottom(size_t index) const;
160  bool IsKnownElement(const CTempString& name) const;
161 
162  static TTypeInfo GetRealTypeInfo(TTypeInfo typeInfo);
163  static ETypeFamily GetRealTypeFamily(TTypeInfo typeInfo);
164  static TTypeInfo GetContainerElementTypeInfo(TTypeInfo typeInfo);
165  static ETypeFamily GetContainerElementTypeFamily(TTypeInfo typeInfo);
166 
167  virtual void UnendedFrame(void);
168  const string& GetStackPath(void) const;
169 
170  void WatchPathHooks(bool set=true);
171 
173  m_PathHooks.insert(h);
174  }
175  void ResetPathHooks(void);
176 protected:
177  virtual void x_SetPathHooks(bool set) = 0;
178  virtual void ResetState(void);
179 
180 private:
182  TFrame& PushFrameLong(void);
183  void x_PushStackPath(void);
184  void x_PopStackPath(void);
185 
189  string m_MemberPath;
193 };
194 
195 #include <serial/impl/objstack.inl>
196 
197 #define BEGIN_OBJECT_FRAME_OFx(Stream, Args) \
198  (Stream).PushFrame Args; \
199  try {
200 
201 #define END_OBJECT_FRAME_OF(Stream) \
202  } catch (CSerialException& s_expt) { \
203  std::string msg((Stream).TopFrame().GetFrameName()); \
204  (Stream).PopFrame(); \
205  s_expt.AddFrameInfo(msg); \
206  throw; \
207  } catch ( CEofException& e_expt ) { \
208  (Stream).HandleEOF(e_expt); \
209  } catch (CException& expt) { \
210  std::string msg((Stream).TopFrame().GetFrameInfo()); \
211  (Stream).PopFrame(); \
212  NCBI_RETHROW_SAME(expt,msg); \
213  } \
214  (Stream).PopFrame()
215 
216 
217 #define BEGIN_OBJECT_FRAME_OF(Stream, Type) \
218  BEGIN_OBJECT_FRAME_OFx(Stream, (CObjectStackFrame::Type))
219 #define BEGIN_OBJECT_FRAME_OF2(Stream, Type, Arg) \
220  BEGIN_OBJECT_FRAME_OFx(Stream, (CObjectStackFrame::Type, Arg))
221 #define BEGIN_OBJECT_FRAME_OF3(Stream, Type, Arg1, Arg2) \
222  BEGIN_OBJECT_FRAME_OFx(Stream, (CObjectStackFrame::Type, Arg1, Arg2))
223 
224 #define BEGIN_OBJECT_FRAME(Type) BEGIN_OBJECT_FRAME_OF(*this, Type)
225 #define BEGIN_OBJECT_FRAME2(Type, Arg) BEGIN_OBJECT_FRAME_OF2(*this, Type, Arg)
226 #define BEGIN_OBJECT_FRAME3(Type, Arg1, Arg2) BEGIN_OBJECT_FRAME_OF3(*this, Type, Arg1, Arg2)
227 #define END_OBJECT_FRAME() END_OBJECT_FRAME_OF(*this)
228 
229 #define BEGIN_OBJECT_2FRAMES_OFx(Stream, Args) \
230  (Stream).In().PushFrame Args; \
231  (Stream).Out().PushFrame Args; \
232  try {
233 
234 #define END_OBJECT_2FRAMES_OF(Stream) \
235  } catch (CException& expt) { \
236  std::string msg((Stream).In().TopFrame().GetFrameInfo()); \
237  (Stream).Out().PopFrame(); \
238  (Stream).Out().SetFailFlagsNoError(CObjectOStream::fInvalidData); \
239  (Stream).In().SetFailFlags(CObjectIStream::fFail); \
240  (Stream).In().PopErrorFrame(); \
241  NCBI_RETHROW_SAME(expt,msg); \
242  } \
243  (Stream).Out().PopFrame(); \
244  (Stream).In().PopFrame()
245 
246 
247 #define BEGIN_OBJECT_2FRAMES_OF(Stream, Type) \
248  BEGIN_OBJECT_2FRAMES_OFx(Stream, (CObjectStackFrame::Type))
249 #define BEGIN_OBJECT_2FRAMES_OF2(Stream, Type, Arg) \
250  BEGIN_OBJECT_2FRAMES_OFx(Stream, (CObjectStackFrame::Type, Arg))
251 #define BEGIN_OBJECT_2FRAMES(Type) BEGIN_OBJECT_2FRAMES_OF(*this, Type)
252 #define BEGIN_OBJECT_2FRAMES2(Type, Arg) BEGIN_OBJECT_2FRAMES_OF2(*this, Type, Arg)
253 #define END_OBJECT_2FRAMES() END_OBJECT_2FRAMES_OF(*this)
254 
256 
257 #endif /* OBJSTACK__HPP */
258 
259 
260 /* @} */
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
Definition: set.hpp:45
Include a standard set of the NCBI C++ Toolkit most basic headers.
ENsQualifiedMode
Defines namespace qualification of XML tags.
Definition: serialdef.hpp:198
const void * TConstObjectPtr
Definition: serialdef.hpp:59
ETypeFamily
Type family.
Definition: serialdef.hpp:138
void Reset(void)
TFrame & TopFrame(void)
ENsQualifiedMode IsNsQualified(void) const
ENsQualifiedMode m_NsqMode
Definition: objstack.hpp:108
TFrame & PushFrame(void)
TTypeInfo m_TypeInfo
Definition: objstack.hpp:104
bool GetNotag(void) const
TFrame & PushFrame(EFrameType type, TTypeInfo typeInfo, TConstObjectPtr objectPtr=0)
bool HasTypeInfo(void) const
bool m_WatchPathHooks
Definition: objstack.hpp:190
TFrame * m_StackPtr
Definition: objstack.hpp:187
virtual string GetStackTrace(void) const =0
void SetNotag(bool set=true)
TFrame * m_Stack
Definition: objstack.hpp:186
virtual void x_SetPathHooks(bool set)=0
TFrame & FetchFrameFromTop(size_t index)
void SetNsQualified(ENsQualifiedMode mode)
set< CPathHook * > m_PathHooks
Definition: objstack.hpp:192
bool GetNoEOC(void) const
const CMemberId * m_MemberId
Definition: objstack.hpp:105
bool HasTypeInfo(TTypeInfo type) const
size_t GetStackDepth(void) const
TConstObjectPtr GetObjectPtr(void) const
void SetNoEOC(bool set=true)
TFrame & PushFrame(EFrameType type)
const TFrame & TopFrame(void) const
TTypeInfo GetTypeInfo(void) const
CObjectStackFrame TFrame
Definition: objstack.hpp:119
TFrame & PushFrame(EFrameType type, const CMemberId &memberId)
void SetTopMemberId(const CMemberId &memberId)
bool StackIsEmpty(void) const
TConstObjectPtr m_ObjectPtr
Definition: objstack.hpp:106
const CMemberId & GetMemberId(void) const
bool m_PathValid
Definition: objstack.hpp:191
void RegisterPathHook(CPathHook *h)
Definition: objstack.hpp:172
bool HasMemberId(void) const
void WatchPathHooks(bool set=true)
void PopFrame(void)
EFrameType GetFrameType(void) const
TFrame::EFrameType EFrameType
Definition: objstack.hpp:120
void SetMemberId(const CMemberId &memberid)
string m_MemberPath
Definition: objstack.hpp:189
TTypeInfo GetRecentTypeInfo(void) const
EFrameType m_FrameType
Definition: objstack.hpp:107
const TFrame & FetchFrameFromTop(size_t index) const
TFrame * m_StackEnd
Definition: objstack.hpp:188
const TFrame & FetchFrameFromBottom(size_t index) const
virtual string GetPosition(void) const =0
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_XSERIAL_EXPORT
Definition: ncbi_export.h:1435
list< Ts... > push
mdb_mode_t mode
Definition: lmdb++.h:38
Definition: type.c:6
Modified on Wed Jun 19 17:02:31 2024 by modify_doxy.py rev. 669887