1#if defined(OBJSTACK__HPP)  &&  !defined(OBJSTACK__INL)
2#define OBJSTACK__INL
3
4/*  $Id: objstack.inl 507795 2016-07-21 17:24:14Z 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
35inline
36void CObjectStackFrame::Reset(void)
37{
38    m_TypeInfo = 0;
39    m_MemberId = 0;
40    m_ObjectPtr = 0;
41    m_FrameType = eFrameOther;
42    m_NsqMode = eNSQNotSet;
43    m_Notag = false;
44    m_NoEOC = false;
45}
46
47inline
48CObjectStackFrame::EFrameType CObjectStackFrame::GetFrameType(void) const
49{
50    return m_FrameType;
51}
52
53inline
54bool CObjectStackFrame::HasTypeInfo(void) const
55{
56    return (m_FrameType != eFrameOther &&
57            m_FrameType != eFrameChoiceVariant &&
58            m_TypeInfo  != 0);
59}
60
61inline
62bool CObjectStackFrame::HasTypeInfo(TTypeInfo type) const
63{
64    return m_TypeInfo == type;
65}
66
67inline
68TTypeInfo CObjectStackFrame::GetTypeInfo(void) const
69{
70    _ASSERT(m_FrameType != eFrameOther &&
71            m_FrameType != eFrameChoiceVariant);
72    _ASSERT(m_TypeInfo != 0);
73    return m_TypeInfo;
74}
75
76inline
77TConstObjectPtr CObjectStackFrame::GetObjectPtr(void) const
78{
79    return m_ObjectPtr;
80}
81
82inline
83bool CObjectStackFrame::HasMemberId(void) const
84{
85    return (m_FrameType == eFrameClassMember ||
86            m_FrameType == eFrameChoiceVariant) && (m_MemberId != 0);
87}
88
89inline
90const CMemberId& CObjectStackFrame::GetMemberId(void) const
91{
92    _ASSERT(m_FrameType == eFrameClassMember ||
93            m_FrameType == eFrameChoiceVariant ||
94            m_FrameType == eFrameArray);
95    _ASSERT(m_MemberId != 0);
96    return *m_MemberId;
97}
98
99inline
100void CObjectStackFrame::SetMemberId(const CMemberId& memberid)
101{
102    _ASSERT(m_FrameType == eFrameClassMember ||
103            m_FrameType == eFrameChoiceVariant);
104    m_MemberId = &memberid;
105}
106
107inline
108void CObjectStackFrame::SetNotag(bool set)
109{
110    m_Notag = set;
111#if defined(NCBI_SERIAL_IO_TRACE)
112    cout << ", "  << (m_Notag ? "N" : "!N");
113#endif
114}
115inline
116bool CObjectStackFrame::GetNotag(void) const
117{
118    return m_Notag;
119}
120
121inline
122void CObjectStackFrame::SetNoEOC(bool set)
123{
124    m_NoEOC = set;
125}
126inline
127bool CObjectStackFrame::GetNoEOC(void) const
128{
129    return m_NoEOC;
130}
131
132inline
133ENsQualifiedMode CObjectStackFrame::IsNsQualified(void) const
134{
135    return m_NsqMode;
136}
137inline
138void CObjectStackFrame::SetNsQualified(ENsQualifiedMode mode)
139{
140    m_NsqMode = mode;
141}
142
143
144inline
145size_t CObjectStack::GetStackDepth(void) const
146{
147    return static_cast<size_t>(m_StackPtr - m_Stack);
148}
149
150inline
151bool CObjectStack::StackIsEmpty(void) const
152{
153    return m_Stack == m_StackPtr;
154}
155
156inline
157CObjectStack::TFrame& CObjectStack::PushFrame(void)
158{
159    TFrame* newPtr = m_StackPtr + 1;
160    if ( newPtr >= m_StackEnd )
161        return PushFrameLong();
162    m_StackPtr = newPtr;
163    return *newPtr;
164}
165
166inline
167CObjectStack::TFrame& CObjectStack::PushFrame(EFrameType type)
168{
169    TFrame& frame = PushFrame();
170    frame.m_FrameType = type;
171#if defined(NCBI_SERIAL_IO_TRACE)
172    TracePushFrame(true);
173#endif
174    return frame;
175}
176
177inline
178CObjectStack::TFrame& CObjectStack::PushFrame(EFrameType type,
179                                              TTypeInfo typeInfo,
180                                              TConstObjectPtr objectPtr)
181{
182    _ASSERT(type != TFrame::eFrameOther &&
183            type != TFrame::eFrameClassMember &&
184            type != TFrame::eFrameChoiceVariant);
185    _ASSERT(typeInfo != 0);
186    TFrame& frame = PushFrame(type);
187    frame.m_TypeInfo = typeInfo;
188    frame.m_ObjectPtr = objectPtr;
189    return frame;
190}
191
192inline
193CObjectStack::TFrame& CObjectStack::PushFrame(EFrameType type,
194                                              const CMemberId& memberId)
195{
196    _ASSERT(type == TFrame::eFrameClassMember ||
197            type == TFrame::eFrameChoiceVariant);
198    TFrame& frame = PushFrame(type);
199    frame.m_MemberId = &memberId;
200    if ( m_WatchPathHooks ) x_PushStackPath();
201    return frame;
202}
203
204inline
205void CObjectStack::PopFrame(void)
206{
207    _ASSERT(!StackIsEmpty());
208#if defined(NCBI_SERIAL_IO_TRACE)
209    TracePushFrame(false);
210#endif
211    if ( m_WatchPathHooks ) x_PopStackPath();
212    m_StackPtr->Reset();
213    --m_StackPtr;
214}
215
216inline
217CObjectStack::TFrame& CObjectStack::FetchFrameFromTop(size_t index)
218{
219    TFrame* ptr = m_StackPtr - index;
220    _ASSERT(ptr > m_Stack);
221    return *ptr;
222}
223
224inline
225const CObjectStack::TFrame& CObjectStack::FetchFrameFromTop(size_t index) const
226{
227    TFrame* ptr = m_StackPtr - index;
228    _ASSERT(ptr > m_Stack);
229    return *ptr;
230}
231
232inline
233const CObjectStack::TFrame& CObjectStack::TopFrame(void) const
234{
235    _ASSERT(!StackIsEmpty());
236    return *m_StackPtr;
237}
238
239inline
240CObjectStack::TFrame& CObjectStack::TopFrame(void)
241{
242    _ASSERT(!StackIsEmpty());
243    return *m_StackPtr;
244}
245
246inline
247void CObjectStack::SetTopMemberId(const CMemberId& memberid)
248{
249    if ( m_WatchPathHooks ) {
250        x_PopStackPath();
251        TopFrame().SetMemberId(memberid);
252        x_PushStackPath();
253    }
254    else {
255        TopFrame().SetMemberId(memberid);
256    }
257}
258
259inline
260const CObjectStack::TFrame& CObjectStack::FetchFrameFromBottom(size_t index) const
261{
262    TFrame* ptr = m_Stack + 1 + index;
263    _ASSERT(ptr <= m_StackPtr);
264    return *ptr;
265}
266
267inline
268TTypeInfo CObjectStack::GetRecentTypeInfo(void) const
269{
270    for (TFrame* ptr = m_StackPtr; ptr >= m_Stack; --ptr) {
271        if (ptr->HasTypeInfo()) {
272            return ptr->GetTypeInfo();
273        }
274    }
275    return nullptr;
276}
277
278inline
279void CObjectStack::WatchPathHooks(bool set)
280{
281    m_WatchPathHooks = set;
282    m_PathValid = false;
283    GetStackPath();
284}
285
286
287#endif /* def OBJSTACK__HPP  &&  ndef OBJSTACK__INL */
288