NCBI C++ ToolKit
xml_retrieve_job.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: xml_retrieve_job.cpp 31534 2014-10-21 15:31:35Z katargir $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Authors: Roman Katargin
27 *
28 * File Description:
29 *
30 */
31 
32 #include <ncbi_pch.hpp>
33 
37 
38 #include <serial/objostrasn.hpp>
39 #include <serial/serial.hpp>
40 #include <serial/delaybuf.hpp>
41 
43 
50 
53 
56 
58 : CTextRetrieveJob(context), m_SO(so), m_OpenIndent(4)
59 {
60 }
61 
63 {
64 }
65 
67 {
69  x_AddItem(main);
70 
72 
73  main->AddItem(new CXmlVersionItem(), false);
74  main->AddItem(new CXmlDoctypeItem(objInfo), false);
75  x_Object(main, objInfo, 0);
76 
78 
79  return eCompleted;
80 }
81 
83  CCompositeTextItem* content,
84  CConstObjectInfo objInfo,
85  size_t indent)
86 {
88 
89  CConstObjectInfo realObj = (objInfo.GetTypeFamily() == eTypeFamilyPointer) ?
90  objInfo.GetPointedObject() : objInfo;
91 
92  ETypeFamily family = realObj.GetTypeFamily();
93 
94  if (family == eTypeFamilyClass)
95  x_Class(content, objInfo, indent);
96  else if (family == eTypeFamilyContainer)
97  x_Container(content, objInfo, indent);
98  else if (family == eTypeFamilyChoice)
99  x_Choice(content, objInfo, indent);
100  else if (family == eTypeFamilyPrimitive)
101  x_Primitive(content, objInfo, indent);
102 }
103 
104 
106  CCompositeTextItem* content,
107  CConstObjectInfo objInfo,
108  size_t indent)
109 {
110  if (objInfo.GetTypeFamily() == eTypeFamilyPointer)
111  objInfo = objInfo.GetPointedObject();
112 
113  CObjectTypeInfo elementType = objInfo.GetElementType();
114  if (elementType.GetTypeFamily() == eTypeFamilyPointer)
115  elementType = elementType.GetPointedType();
116 
117  string typeName = elementType.GetTypeInfo()->GetName();
118 
119  size_t elemCount = 0;
120  size_t loaded = 0;
121 
123  while(ei) {
124  ++elemCount;
126 
127  CConstObjectInfo element = *ei;
128 
129  // Container of unnamed types
130  if (elementType.GetTypeFamily() != eTypeFamilyPrimitive && typeName.empty()) {
131  const string tagName = m_TagStack.top() + "_E";
132  CCompositeTextItem* expanded = new CCompositeTextItem();
133  content->AddItem(new CXmlExpandItem(element, new CXmlClosedBlock(indent, tagName, expanded), expanded,
134  (indent <= m_OpenIndent)), false);
135  expanded->AddItem(new CXmlOpenTagItem(indent, tagName), false);
136  m_TagStack.push(tagName);
137  x_Object(expanded, element, indent + 1);
138  m_TagStack.pop();
139  expanded->AddItem(new CXmlCloseTagItem(indent, tagName), false);
140  }
141  else
142  x_Object(content, element, indent);
143 
144  ++loaded;
145  ++ei;
146  }
147 }
148 
149 
151  CCompositeTextItem* content,
152  CConstObjectInfo objInfo,
153  size_t indent)
154 {
155  if (objInfo.GetTypeFamily() == eTypeFamilyPointer)
156  objInfo = objInfo.GetPointedObject();
157 
158  const string tagName = objInfo.GetTypeInfo()->GetName();
159 
160  if (tagName.empty())
161  x_ChoiceMember(content, objInfo, indent);
162  else {
163  CCompositeTextItem* expanded = new CCompositeTextItem();
164  content->AddItem(new CXmlExpandItem(objInfo, new CXmlClosedBlock(indent, tagName, expanded), expanded,
165  (indent <= m_OpenIndent)), false);
166  expanded->AddItem(new CXmlOpenTagItem(indent, tagName), false);
167  m_TagStack.push(tagName);
168  x_ChoiceMember(expanded, objInfo, indent + 1);
169  m_TagStack.pop();
170  expanded->AddItem(new CXmlCloseTagItem(indent, tagName), false);
171  }
172 }
173 
175  CCompositeTextItem* content,
176  CConstObjectInfo objInfo,
177  size_t indent)
178 {
179  string choiceName = objInfo.GetTypeInfo()->GetName();
180  if (choiceName.empty()) // Noname choice (direct member definition)
181  choiceName = m_TagStack.top();
182 
184  string variantName = cv.GetAlias();
185  CObjectTypeInfo variantType = cv.GetVariantType();
186  CConstObjectInfo variant = cv.GetVariant();
187 
188  //const CVariantInfo* variantInfo = type->GetVariantInfo(index);
189  //string variantName = variantInfo->GetId().GetName();
190 
191  const string tagName = choiceName + "_" + variantName;
192 
193  ETypeFamily family = (variantType.GetTypeFamily() == eTypeFamilyPointer) ?
194  variantType.GetPointedType().GetTypeFamily() : variantType.GetTypeFamily();
195 
196  if (variantType.GetTypeInfo()->GetName().empty() && family == eTypeFamilyPrimitive)
197  content->AddItem(new CXmlValueItem(indent, tagName, variant), false);
198  else {
199  CCompositeTextItem* expanded = new CCompositeTextItem();
200  content->AddItem(new CXmlExpandItem(variant, new CXmlClosedBlock(indent, tagName, expanded), expanded,
201  (indent <= m_OpenIndent)), false);
202  expanded->AddItem(new CXmlOpenTagItem(indent, tagName), false);
203  m_TagStack.push(tagName);
204  x_Object(expanded, variant, indent + 1);
205  m_TagStack.pop();
206  expanded->AddItem(new CXmlCloseTagItem(indent, tagName), false);
207  }
208 }
209 
211  CCompositeTextItem* content, CConstObjectInfo objInfo, size_t indent)
212 {
213  TTypeInfo typeInfo = (objInfo.GetTypeFamily() == eTypeFamilyPointer) ?
214  objInfo.GetPointedObject().GetTypeInfo() : objInfo.GetTypeInfo();
215 
216  const string tagName = typeInfo->GetName();
217 
218  CCompositeTextItem* expanded = new CCompositeTextItem();
219  content->AddItem(new CXmlExpandItem(objInfo, new CXmlClosedBlock(indent, tagName, expanded), expanded,
220  (indent <= m_OpenIndent)), false);
221  expanded->AddItem(new CXmlOpenTagItem(indent, tagName), false);
222  m_TagStack.push(tagName);
223  x_ClassMembers(expanded, objInfo, indent + 1);
224  m_TagStack.pop();
225  expanded->AddItem(new CXmlCloseTagItem(indent, tagName), false);
226 }
227 
229  CCompositeTextItem* content, CConstObjectInfo objInfo, size_t indent)
230 {
231  if (objInfo.GetTypeFamily() == eTypeFamilyPointer)
232  objInfo = objInfo.GetPointedObject();
233  const CClassTypeInfo* classType = objInfo.GetClassTypeInfo();
234  TConstObjectPtr classPtr = objInfo.GetObjectPtr();
235 
236  string className = classType->GetName();
237 
238  for (CConstObjectInfo::CMemberIterator mi = objInfo.BeginMembers(); mi; ++mi) {
240 
241  CConstObjectInfo member = *mi;
242  TTypeInfo memberType = member.GetTypeInfo();
243 
244  const CMemberInfo* memberInfo = mi.GetMemberInfo();
245  TConstObjectPtr memberPtr;
246 
247  if (memberInfo->CanBeDelayed()) {
248  bool haveSetFlag = memberInfo->HaveSetFlag();
249  if (haveSetFlag && memberInfo->GetSetFlagNo(classPtr))
250  continue;
251 
252  const CDelayBuffer& buffer = memberInfo->GetDelayBuffer(classPtr);
253  if ( buffer )
254  const_cast<CDelayBuffer&>(buffer).Update();
255 
256  TConstObjectPtr memberPtr = memberInfo->GetItemPtr(classPtr);
257  if ( !haveSetFlag && memberInfo->Optional() ) {
258  TConstObjectPtr defaultPtr = memberInfo->GetDefault();
259  if ( !defaultPtr ) {
260  if ( memberType->IsDefault(memberPtr) )
261  continue; // DEFAULT
262  }
263  else {
264  if ( memberType->Equals(memberPtr, defaultPtr) )
265  continue; // OPTIONAL
266  }
267  }
268  }
269  else if (memberInfo->HaveSetFlag()) {
270  if (memberInfo->GetSetFlagNo(classPtr))
271  continue;
272  }
273  else if (memberInfo->GetDefault()) {
274  memberPtr = memberInfo->GetItemPtr(classPtr);
275  if ( memberType->Equals(memberPtr, memberInfo->GetDefault()) )
276  continue;
277  }
278  else if (memberInfo->Optional()) {
279  memberPtr = memberInfo->GetItemPtr(classPtr);
280  if ( memberType->IsDefault(memberPtr) )
281  continue;
282  }
283 
284  string memberName = mi.GetMemberInfo()->GetId().GetName();
285 
286  if (memberName.empty()) // class-container (SET OF ...)
287  x_Object(content, member, indent);
288  else {
289  const string tagName = className + "_" + memberName;
290 
291  TTypeInfo realType = memberType;
292  if (realType->GetTypeFamily() == eTypeFamilyPointer) {
293  const CPointerTypeInfo* pointerType =
295  realType = pointerType->GetPointedType();
296  }
297 
298  if (memberType->GetName().empty() && realType->GetTypeFamily() == eTypeFamilyPrimitive)
299  content->AddItem(new CXmlValueItem(indent, tagName, member), false);
300  else {
301  CCompositeTextItem* expanded = new CCompositeTextItem();
302  content->AddItem(new CXmlExpandItem(member, new CXmlClosedBlock(indent, tagName, expanded), expanded,
303  (indent <= m_OpenIndent)), false);
304  expanded->AddItem(new CXmlOpenTagItem(indent, tagName), false);
305  m_TagStack.push(tagName);
306  x_Object(expanded, member, indent + 1);
307  m_TagStack.pop();
308  expanded->AddItem(new CXmlCloseTagItem(indent, tagName), false);
309  }
310  }
311  }
312 }
313 
315  CCompositeTextItem* content, CConstObjectInfo objInfo, size_t indent)
316 {
317  string tagName = objInfo.GetTypeInfo()->GetName();
318  if (tagName.empty()) tagName = m_TagStack.top() + "_E";
319  content->AddItem(new CXmlValueItem(indent, tagName, objInfo), false);
320 }
321 
void AddItem(ITextItem *item, bool updatePositions=true)
CConstObjectInfoCV –.
Definition: objectiter.hpp:557
CConstObjectInfoEI –.
Definition: objectiter.hpp:56
CConstObjectInfoMI –.
Definition: objectiter.hpp:397
CConstObjectInfo –.
Definition: objectinfo.hpp:421
CDelayBuffer.
Definition: delaybuf.hpp:58
CObjectTypeInfo –.
Definition: objectinfo.hpp:94
Base class for all serializable objects.
Definition: serialbase.hpp:150
void x_CheckCancelled() const
void x_AddItem(ITextItem *item)
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
void x_Container(CCompositeTextItem *content, CConstObjectInfo objInfo, size_t indent)
const size_t m_OpenIndent
stack< string > m_TagStack
void x_Object(CCompositeTextItem *content, CConstObjectInfo objInfo, size_t indent)
CXmlRetrieveJob(CTextPanelContext &context, const CSerialObject &so)
void x_Primitive(CCompositeTextItem *content, CConstObjectInfo objInfo, size_t indent)
void x_ChoiceMember(CCompositeTextItem *content, CConstObjectInfo objInfo, size_t indent)
virtual EJobState x_Run()
virtual ~CXmlRetrieveJob()
void x_Class(CCompositeTextItem *content, CConstObjectInfo objInfo, size_t indent)
void x_Choice(CCompositeTextItem *content, CConstObjectInfo objInfo, size_t indent)
void x_ClassMembers(CCompositeTextItem *content, CConstObjectInfo objInfo, size_t indent)
const CSerialObject & m_SO
int main(int argc, const char *argv[])
bool Optional(void) const
bool GetSetFlagNo(TConstObjectPtr object) const
true if 'setFlag' is eSetNo
TConstObjectPtr GetDefault(void) const
TObjectPtr GetItemPtr(TObjectPtr object) const
CDelayBuffer & GetDelayBuffer(TObjectPtr object) const
bool CanBeDelayed(void) const
bool HaveSetFlag(void) const
EJobState
Job states (describe FSM)
Definition: app_job.hpp:86
@ eCompleted
Definition: app_job.hpp:89
const void * TConstObjectPtr
Definition: serialdef.hpp:59
ETypeFamily
Type family.
Definition: serialdef.hpp:138
virtual const CTypeInfo * GetThisTypeInfo(void) const =0
static const TObjectType * SafeCast(TTypeInfo type)
Definition: serialutil.hpp:76
@ eTypeFamilyClass
Definition: serialdef.hpp:140
@ eTypeFamilyContainer
Definition: serialdef.hpp:142
@ eTypeFamilyChoice
Definition: serialdef.hpp:141
@ eTypeFamilyPointer
Definition: serialdef.hpp:143
@ eTypeFamilyPrimitive
Definition: serialdef.hpp:139
const string & GetAlias(void) const
CObjectTypeInfo GetPointedType(void) const
Get type information of data to which this type refers.
Definition: objectinfo.cpp:91
CObjectTypeInfo GetVariantType(void) const
Get variant data type.
CConstObjectInfo GetPointedObject(void) const
Get data and type information of object to which this type refers.
Definition: objectinfo.cpp:96
CChoiceVariant GetCurrentChoiceVariant(void) const
Get data and type information of selected choice variant.
TTypeInfo GetTypeInfo(void) const
const CClassTypeInfo * GetClassTypeInfo(void) const
Definition: objectinfo.cpp:61
CConstObjectInfo GetVariant(void) const
Get variant data.
CMemberIterator BeginMembers(void) const
Create class member iterator.
ETypeFamily GetTypeFamily(void) const
Get data type family.
CElementIterator BeginElements(void) const
Create container elements iterator.
TConstObjectPtr GetObjectPtr(void) const
Get pointer to object.
CObjectTypeInfo GetElementType(void) const
Get type information of an element of container.
Definition: objectinfo.cpp:85
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
const string & GetName(void) const
Get name of this type.
Definition: typeinfo.cpp:249
virtual bool IsDefault(TConstObjectPtr object) const =0
Check, whether the object contains default value.
ETypeFamily GetTypeFamily(void) const
TTypeInfo GetPointedType(void) const
virtual bool Equals(TConstObjectPtr object1, TConstObjectPtr object2, ESerialRecursionMode how=eRecursive) const =0
Check if both objects contain the same values.
static pcre_uint8 * buffer
Definition: pcretest.c:1051
string indent(" ")
static CS_CONTEXT * context
Definition: will_convert.c:21
USING_SCOPE(objects)
Modified on Tue May 28 05:53:07 2024 by modify_doxy.py rev. 669887