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

Go to the SVN repository for this file.

1 /* $Id: asn_retrieve_job.cpp 38290 2017-04-21 21:03:01Z 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 
47 
48 #include <serial/objostrasn.hpp>
49 #include <serial/serial.hpp>
50 #include <serial/delaybuf.hpp>
51 
53 
55 
58 
60 
62 : CTextRetrieveJob(context), m_SO(so), m_Scope(&scope), m_ContextContainer(), m_BioContext()
63 {
64 }
65 
67 {
68 }
69 
71 {
73 
74  ETypeFamily family = type->GetTypeFamily();
75  if (family != eTypeFamilyClass)
76  return seh;
77 
79  if (classType->GetName() == "Bioseq") {
80  const CBioseq* bioseq = dynamic_cast<const CBioseq*>(classType->GetCObjectPtr(ptr));
81  if (bioseq) {
83  if (bh) {
84  seh = bh.GetParentEntry();
85  }
86  }
87  }
88  else if (classType->GetName() == "Bioseq-set") {
89  const CBioseq_set* bioseq_set = dynamic_cast<const CBioseq_set*>(classType->GetCObjectPtr(ptr));
90  if (bioseq_set) {
91  CBioseq_set_Handle bssh = scope.GetObjectHandle(*bioseq_set, CScope::eMissing_Null);
92  if (bssh) {
93  seh = bssh.GetParentEntry();
94  }
95  }
96  }
97 
98  return seh;
99 }
100 
102 {
104  m_RootItem->AddUserObject("AsnBioContextContainer", m_ContextContainer);
105 
106 
108  TConstObjectPtr ptr = &m_SO;
109 
110  //CNcbiOfstream("c:\\tmp\\test.asn") << MSerial_AsnText << m_SO;
111 
112  TTypeInfo realType = type;
113  TConstObjectPtr realPtr = ptr;
114  x_GetMemberObject(realType, realPtr);
115 
116  if (realType->GetTypeFamily() == eTypeFamilyPrimitive)
118  else {
120  x_AddItem(main);
121 
122  CSeq_entry_Handle seh = GetSeq_entry_Handle(realType, realPtr, *m_Scope);
123  if (seh) {
124  m_BioContext = new CAsnBioContext(seh);
126  }
127  main->AddItem(new CAsnHeaderItem(noMemeberId, type, ptr, m_BioContext), false);
128 
129  x_FillBlock(main, type, ptr, 0, 0);
130  main->AddItem(new CAsnBlockEndItem(0, false), false);
131  }
132 
133  x_CreateResult();
134 
135  return eCompleted;
136 }
137 
139  CCompositeTextItem* content,
140  const CClassTypeInfo* classType,
141  TConstObjectPtr classPtr,
142  size_t indent, size_t maxIndent)
143 {
144  string className = classType->GetName();
145 
146  CAsnBioContext* saveBioContext = m_BioContext;
147 
148  CSeq_entry_Handle seh = GetSeq_entry_Handle(classType, classPtr, *m_Scope);
149  if (seh) {
150  m_BioContext = new CAsnBioContext(seh);
152  }
153 
154  for (CClassTypeInfo::CIterator i(classType); i.Valid(); ++i) {
156 
157  const CMemberInfo* memberInfo = classType->GetMemberInfo(*i);
158  string name = memberInfo->GetId().GetName();
159 
160  TTypeInfo memberType = memberInfo->GetTypeInfo();
161  TConstObjectPtr memberPtr;
162  if (memberInfo->CanBeDelayed()) {
163  bool haveSetFlag = memberInfo->HaveSetFlag();
164  if (haveSetFlag && memberInfo->GetSetFlagNo(classPtr))
165  continue;
166 
167  const CDelayBuffer& buffer = memberInfo->GetDelayBuffer(classPtr);
168  if ( buffer )
169  const_cast<CDelayBuffer&>(buffer).Update();
170 
171  TConstObjectPtr memberPtr = memberInfo->GetItemPtr(classPtr);
172  if ( !haveSetFlag && memberInfo->Optional() ) {
173  TConstObjectPtr defaultPtr = memberInfo->GetDefault();
174  if ( !defaultPtr ) {
175  if ( memberType->IsDefault(memberPtr) )
176  continue; // DEFAULT
177  }
178  else {
179  if ( memberType->Equals(memberPtr, defaultPtr) )
180  continue; // OPTIONAL
181  }
182  }
183  }
184  else if (memberInfo->HaveSetFlag()) {
185  if (memberInfo->GetSetFlagNo(classPtr))
186  continue;
187  }
188  else if (memberInfo->GetDefault()) {
189  memberPtr = memberInfo->GetItemPtr(classPtr);
190  if ( memberType->Equals(memberPtr, memberInfo->GetDefault()) )
191  continue;
192  }
193  else if (memberInfo->Optional()) {
194  memberPtr = memberInfo->GetItemPtr(classPtr);
195  if ( memberType->IsDefault(memberPtr) )
196  continue;
197  }
198 
199  memberPtr = memberInfo->GetItemPtr(classPtr);
200 
201  ETypeFamily family = memberType->GetTypeFamily();
202  TConstObjectPtr realPtr = memberPtr;
203  TTypeInfo realType = memberType;
204  x_GetMemberObject(realType, realPtr);
205  family = realType->GetTypeFamily();
206 
207  if (family == eTypeFamilyPrimitive)
209  memberInfo->GetId(),
210  memberType,
211  memberPtr, indent + 1,
212  m_BioContext), false);
213  else {
214  CAsnElementBlockCollapsed* collapsed =
216  memberInfo->GetId(),
217  memberType,
218  memberPtr,
219  indent + 1,
220  m_BioContext);
221  CCompositeTextItem* expanded = new CCompositeTextItem();
222  content->AddItem(new CExpandItem(collapsed, expanded, indent != maxIndent), false);
223 
224  expanded->AddItem(new CAsnElementBlockStart(
225  memberInfo->GetId(),
226  memberType,
227  memberPtr,
228  indent + 1,
229  m_BioContext), false);
230  CCompositeTextItem* block_content = new CCompositeTextItem();
231  expanded->AddItem(block_content, false);
232  collapsed->SetExpandedValue(block_content);
233 
234  x_FillBlock(block_content, memberType, memberPtr, indent + 1, maxIndent);
235  expanded->AddItem(new CAsnBlockEndItem(indent + 1), false);
236  }
237  }
238 
239  m_BioContext = saveBioContext;
240 
241  x_SetNoComma(content);
242 }
243 
245  CCompositeTextItem* content,
246  const CContainerTypeInfo* type,
247  TConstObjectPtr ptr,
248  size_t indent,
249  size_t maxIndent)
250 {
252  if (!type->InitIterator(i, ptr))
253  return;
254 
255  size_t loaded = 0;
256 
257  TTypeInfo elementType = type->GetElementType();
258  do {
260 
261  TConstObjectPtr elementPtr = type->GetElementPtr(i);
262  ETypeFamily family = elementType->GetTypeFamily();
263 
264  TConstObjectPtr realPtr = elementPtr;
265  TTypeInfo realType = elementType;
266  x_GetMemberObject(realType, realPtr);
267  family = realType->GetTypeFamily();
268 
269  if (family == eTypeFamilyPrimitive)
271  noMemeberId,
272  elementType,
273  elementPtr,
274  indent + 1,
275  m_BioContext), false);
276  else {
277  CAsnElementBlockCollapsed* collapsed =
279  noMemeberId,
280  elementType,
281  elementPtr,
282  indent + 1,
283  m_BioContext);
284 
285  CCompositeTextItem* expanded = new CCompositeTextItem();
286  content->AddItem(new CExpandItem(collapsed, expanded, indent != maxIndent), false);
287 
288  expanded->AddItem(new CAsnElementBlockStart(
289  noMemeberId,
290  elementType,
291  elementPtr,
292  indent + 1,
293  m_BioContext), false);
294  CCompositeTextItem* block_content = new CCompositeTextItem();
295  expanded->AddItem(block_content, false);
296  collapsed->SetExpandedValue(block_content);
297  x_FillBlock(block_content, elementType, elementPtr, indent + 1, maxIndent);
298  expanded->AddItem(new CAsnBlockEndItem(indent + 1), false);
299  }
300 
301  ++loaded;
302  } while ( type->NextElement(i) );
303 
304  x_SetNoComma(content);
305 }
306 
308  CCompositeTextItem* content,
309  TTypeInfo containerType,
310  TConstObjectPtr containerPtr,
311  size_t indent, size_t maxIndent)
312 {
314 
315  TConstObjectPtr realPtr = containerPtr;
316  TTypeInfo realType = containerType;
317  x_GetMemberObject(realType, realPtr);
318  ETypeFamily family = realType->GetTypeFamily();
319 
320  if (family == eTypeFamilyClass)
321  x_FillClass(content,
323  realPtr,
324  indent, maxIndent);
325  else if (family == eTypeFamilyContainer)
327  content,
329  realPtr,
330  indent, maxIndent);
331 
332  //main = new CAsnHeaderItem(noMemeberId, type, ptr);
333 
334 }
335 
337 {
338  ITextItem* lastItem = block->GetItem(block->GetItemCount() - 1);
339  CAsnElementItem* asn_elem = dynamic_cast<CAsnElementItem*>(lastItem);
340 
341  if (asn_elem) {
342  asn_elem->SetTrailComma(false);
343  return;
344  }
345 
346  CCompositeTextItem* text_block = dynamic_cast<CCompositeTextItem*>(lastItem);
347  if (text_block) {
348  lastItem = text_block->GetItem(text_block->GetItemCount() - 1);
349  asn_elem = dynamic_cast<CAsnElementItem*>(lastItem);
350  if (asn_elem)
351  asn_elem->SetTrailComma(false);
352  return;
353  }
354 
355  CExpandItem* expandBlock = dynamic_cast<CExpandItem*>(lastItem);
356  if (expandBlock) {
357  CAsnElementItem* collapsedItem =
358  dynamic_cast<CAsnElementItem*>(expandBlock->GetCollapsedItem());
359  if (collapsedItem)
360  collapsedItem->SetTrailComma(false);
361 
362  CCompositeTextItem* expandedItem =
363  dynamic_cast<CCompositeTextItem*>(expandBlock->GetExpandedItem());
364  if (expandedItem) {
365  size_t count = expandedItem->GetItemCount();
366  CAsnBlockEndItem* block_end =
367  dynamic_cast<CAsnBlockEndItem*>(expandedItem->GetItem(count - 1));
368  if (block_end)
369  block_end->SetTrailComma(false);
370  }
371  }
372 }
373 
375 {
376  for(;;) {
377  ETypeFamily family = type->GetTypeFamily();
378  if (family == eTypeFamilyChoice) {
379  const CChoiceTypeInfo* choiceType =
381  TMemberIndex index = choiceType->GetIndex(ptr);
382 
383  if (!(index >= choiceType->GetVariants().FirstIndex() &&
384  index <= choiceType->GetVariants().LastIndex())) {
386  "Invalid CHOICE value, type name: \"" + choiceType->GetAccessName() + "\"");
387  }
388 
389  const CVariantInfo* variantInfo = choiceType->GetVariantInfo(index);
390  ptr = variantInfo->GetVariantPtr(ptr);
391  type = variantInfo->GetTypeInfo();
392  }
393  else if (family == eTypeFamilyPointer) {
394  const CPointerTypeInfo* pointerType =
396  ptr = pointerType->GetObjectPointer(ptr);
397  type = pointerType->GetPointedType();
398  }
399  else if (family == eTypeFamilyClass) {
400  const CClassTypeInfo* classType =
402  if (!classType->Implicit())
403  break;
404  const CMemberInfo* memberInfo =
405  classType->GetMemberInfo(classType->GetMembers().FirstIndex());
406  ptr = memberInfo->GetItemPtr(ptr);
407  type = memberInfo->GetTypeInfo();
408  }
409  else
410  break;
411  }
412 }
413 
static CRef< CScope > m_Scope
USING_SCOPE(objects)
static CMemberId noMemeberId
static CSeq_entry_Handle GetSeq_entry_Handle(TTypeInfo type, TConstObjectPtr ptr, CScope &scope)
void AddBioContext(CAsnBioContext *bioContext)
void SetTrailComma(bool fTrailComma)
void SetTrailComma(bool fTrailComma)
static CTextItem * CreateItem(const CMemberId &memberId, TTypeInfo type, TConstObjectPtr ptr, size_t indent, CAsnBioContext *bioContext)
virtual void x_FillBlock(CCompositeTextItem *content, TTypeInfo containerType, TConstObjectPtr containerPtr, size_t indent, size_t maxIndent)
CRef< objects::CScope > m_Scope
static void x_SetNoComma(CCompositeTextItem *block)
CAsnRetrieveJob(CTextPanelContext &context, const CSerialObject &so, objects::CScope &scope)
virtual void x_FillContainer(CCompositeTextItem *content, const CContainerTypeInfo *type, TConstObjectPtr ptr, size_t indent, size_t maxIndent)
CAsnBioContextContainer * m_ContextContainer
virtual EJobState x_Run()
virtual void x_FillClass(CCompositeTextItem *content, const CClassTypeInfo *classType, TConstObjectPtr classPtr, size_t indent, size_t maxIndent)
const CSerialObject & m_SO
virtual ~CAsnRetrieveJob()
CAsnBioContext * m_BioContext
static void x_GetMemberObject(TTypeInfo &type, TConstObjectPtr &ptr)
CBioseq_Handle –.
CBioseq_set_Handle –.
ITextItem * GetItem(size_t index)
size_t GetItemCount() const
void AddItem(ITextItem *item, bool updatePositions=true)
CDelayBuffer.
Definition: delaybuf.hpp:58
CTextItem * GetExpandedItem()
Definition: expand_item.hpp:60
CTextItem * GetCollapsedItem()
Definition: expand_item.hpp:59
CScope –.
Definition: scope.hpp:92
CSeq_entry_Handle –.
Base class for all serializable objects.
Definition: serialbase.hpp:150
void x_CheckCancelled() const
void x_AddItem(ITextItem *item)
shared_ptr< CRootTextItem > m_RootItem
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
int main(int argc, const char *argv[])
static int type
Definition: getdata.c:31
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
bool Optional(void) const
const CMemberId & GetId(void) const
const string & GetName(void) const
bool GetSetFlagNo(TConstObjectPtr object) const
true if 'setFlag' is eSetNo
TConstObjectPtr GetDefault(void) const
TObjectPtr GetItemPtr(TObjectPtr object) const
TConstObjectPtr GetVariantPtr(TConstObjectPtr choicePtr) const
CDelayBuffer & GetDelayBuffer(TObjectPtr object) const
static TMemberIndex FirstIndex(void)
Definition: memberlist.hpp:78
bool CanBeDelayed(void) const
TTypeInfo GetTypeInfo(void) const
bool HaveSetFlag(void) const
EJobState
Job states (describe FSM)
Definition: app_job.hpp:86
@ eCompleted
Definition: app_job.hpp:89
size_t TMemberIndex
Type used for indexing class members and choice variants.
Definition: serialdef.hpp:230
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
CBioseq_Handle GetObjectHandle(const CBioseq &bioseq, EMissing action=eMissing_Default)
Definition: scope.hpp:726
@ eMissing_Null
Definition: scope.hpp:157
CSeq_entry_Handle GetParentEntry(void) const
Get parent Seq-entry handle.
CSeq_entry_Handle GetParentEntry(void) const
Return a handle for the parent seq-entry of the bioseq.
#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 const CObject * GetCObjectPtr(TConstObjectPtr objectPtr) const override
Definition: classinfob.cpp:298
virtual bool IsDefault(TConstObjectPtr object) const =0
Check, whether the object contains default value.
ETypeFamily GetTypeFamily(void) const
TTypeInfo GetPointedType(void) const
const CItemsInfo & GetVariants(void) const
TMemberIndex GetIndex(TConstObjectPtr object) const
const CMemberInfo * GetMemberInfo(TMemberIndex index) const
const CVariantInfo * GetVariantInfo(TMemberIndex index) const
bool Implicit(void) const
virtual bool Equals(TConstObjectPtr object1, TConstObjectPtr object2, ESerialRecursionMode how=eRecursive) const =0
Check if both objects contain the same values.
TConstObjectPtr GetObjectPointer(TConstObjectPtr object) const
const string & GetAccessName(void) const
Return internal or regular name.
Definition: typeinfo.cpp:289
const CItemsInfo & GetMembers(void) const
int i
static pcre_uint8 * buffer
Definition: pcretest.c:1051
string indent(" ")
Definition: type.c:6
static CS_CONTEXT * context
Definition: will_convert.c:21
Modified on Sat May 25 14:19:17 2024 by modify_doxy.py rev. 669887