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

Go to the SVN repository for this file.

1 /* $Id: variant.cpp 84832 2018-12-17 14:45:09Z gouriano $
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 * Author: Eugene Vasilchenko
27 *
28 * File Description:
29 * !!! PUT YOUR DESCRIPTION HERE !!!
30 *
31 * ===========================================================================
32 */
33 
34 #include <ncbi_pch.hpp>
35 #include <corelib/ncbistd.hpp>
36 #include <corelib/ncbimtx.hpp>
37 
38 #include <serial/impl/variant.hpp>
39 #include <serial/objectinfo.hpp>
40 #include <serial/objectiter.hpp>
41 #include <serial/objistr.hpp>
42 #include <serial/objostr.hpp>
43 #include <serial/objcopy.hpp>
44 #include <serial/delaybuf.hpp>
46 #include <serial/impl/ptrinfo.hpp>
47 #include <serial/serialimpl.hpp>
48 
50 
52 {
53 public:
54 
55  static
57  TConstObjectPtr choicePtr);
58  static
60  TConstObjectPtr choicePtr);
61  static
63  TConstObjectPtr choicePtr);
64  static
66  TConstObjectPtr choicePtr);
67  static TObjectPtr GetInlineVariant(const CVariantInfo* variantInfo,
68  TObjectPtr choicePtr);
69  static TObjectPtr GetPointerVariant(const CVariantInfo* variantInfo,
70  TObjectPtr choicePtr);
71  static TObjectPtr GetDelayedVariant(const CVariantInfo* variantInfo,
72  TObjectPtr choicePtr);
73  static TObjectPtr GetSubclassVariant(const CVariantInfo* variantInfo,
74  TObjectPtr choicePtr);
75 
76  static void ReadInlineVariant(CObjectIStream& in,
77  const CVariantInfo* variantInfo,
78  TObjectPtr choicePtr);
80  const CVariantInfo* variantInfo,
81  TObjectPtr choicePtr);
83  const CVariantInfo* variantInfo,
84  TObjectPtr choicePtr);
86  const CVariantInfo* variantInfo,
87  TObjectPtr choicePtr);
89  const CVariantInfo* variantInfo,
90  TObjectPtr choicePtr);
91  static void ReadHookedVariant(CObjectIStream& in,
92  const CVariantInfo* variantInfo,
93  TObjectPtr choicePtr);
95  const CVariantInfo* variantInfo,
96  TConstObjectPtr choicePtr);
98  const CVariantInfo* variantInfo,
99  TConstObjectPtr choicePtr);
101  const CVariantInfo* variantInfo,
102  TConstObjectPtr choicePtr);
104  const CVariantInfo* variantInfo,
105  TConstObjectPtr choicePtr);
107  const CVariantInfo* variantInfo,
108  TConstObjectPtr choicePtr);
110  const CVariantInfo* variantInfo,
111  TConstObjectPtr choicePtr);
113  const CVariantInfo* variantInfo);
115  const CVariantInfo* variantInfo);
116  static void SkipHookedVariant(CObjectIStream& in,
117  const CVariantInfo* variantInfo);
118  static void CopyNonObjectVariant(CObjectStreamCopier& copier,
119  const CVariantInfo* variantInfo);
120  static void CopyObjectPointerVariant(CObjectStreamCopier& copier,
121  const CVariantInfo* variantInfo);
122  static void CopyHookedVariant(CObjectStreamCopier& copier,
123  const CVariantInfo* variantInfo);
124 };
125 
127 
130  const CTypeRef& type)
131  : CParent(id, offset, type), m_ChoiceType(choiceType),
132  m_VariantType(eInlineVariant), m_DelayOffset(eNoOffset),
133  m_GetConstFunction(&TFunc::GetConstInlineVariant),
134  m_GetFunction(&TFunc::GetInlineVariant),
135  m_ReadHookData(&TFunc::ReadInlineVariant, &TFunc::ReadHookedVariant),
136  m_WriteHookData(&TFunc::WriteInlineVariant, &TFunc::WriteHookedVariant),
137  m_SkipHookData(&TFunc::SkipNonObjectVariant, &TFunc::SkipHookedVariant),
138  m_CopyHookData(&TFunc::CopyNonObjectVariant, &TFunc::CopyHookedVariant)
139 {
140 }
141 
144  TTypeInfo type)
145  : CParent(id, offset, type), m_ChoiceType(choiceType),
146  m_VariantType(eInlineVariant), m_DelayOffset(eNoOffset),
147  m_GetConstFunction(&TFunc::GetConstInlineVariant),
148  m_GetFunction(&TFunc::GetInlineVariant),
149  m_ReadHookData(&TFunc::ReadInlineVariant, &TFunc::ReadHookedVariant),
150  m_WriteHookData(&TFunc::WriteInlineVariant, &TFunc::WriteHookedVariant),
151  m_SkipHookData(&TFunc::SkipNonObjectVariant, &TFunc::SkipHookedVariant),
152  m_CopyHookData(&TFunc::CopyNonObjectVariant, &TFunc::CopyHookedVariant)
153 {
154 }
155 
157  const char* id, TPointerOffsetType offset,
158  const CTypeRef& type)
159  : CParent(id, offset, type), m_ChoiceType(choiceType),
160  m_VariantType(eInlineVariant), m_DelayOffset(eNoOffset),
161  m_GetConstFunction(&TFunc::GetConstInlineVariant),
162  m_GetFunction(&TFunc::GetInlineVariant),
163  m_ReadHookData(&TFunc::ReadInlineVariant, &TFunc::ReadHookedVariant),
164  m_WriteHookData(&TFunc::WriteInlineVariant, &TFunc::WriteHookedVariant),
165  m_SkipHookData(&TFunc::SkipNonObjectVariant, &TFunc::SkipHookedVariant),
166  m_CopyHookData(&TFunc::CopyNonObjectVariant, &TFunc::CopyHookedVariant)
167 {
168 }
169 
171  const char* id, TPointerOffsetType offset,
172  TTypeInfo type)
173  : CParent(id, offset, type), m_ChoiceType(choiceType),
174  m_VariantType(eInlineVariant), m_DelayOffset(eNoOffset),
175  m_GetConstFunction(&TFunc::GetConstInlineVariant),
176  m_GetFunction(&TFunc::GetInlineVariant),
177  m_ReadHookData(&TFunc::ReadInlineVariant, &TFunc::ReadHookedVariant),
178  m_WriteHookData(&TFunc::WriteInlineVariant, &TFunc::WriteHookedVariant),
179  m_SkipHookData(&TFunc::SkipNonObjectVariant, &TFunc::SkipHookedVariant),
180  m_CopyHookData(&TFunc::CopyNonObjectVariant, &TFunc::CopyHookedVariant)
181 {
182 }
183 
185 {
186  if ( !IsInline() ) {
187  NCBI_THROW(CSerialException,eIllegalCall,
188  "SetPointer() is not first call");
189  }
191  UpdateFunctions();
192  return this;
193 }
194 
196 {
197  if ( !IsInline() ) {
198  NCBI_THROW(CSerialException,eIllegalCall,
199  "SetObjectPointer() is not first call");
200  }
202  UpdateFunctions();
203  return this;
204 }
205 
207 {
208  if ( !IsInline() ) {
209  NCBI_THROW(CSerialException,eIllegalCall,
210  "SetSubClass() is not first call");
211  }
212  if ( CanBeDelayed() ) {
213  NCBI_THROW(CSerialException,eIllegalCall,
214  "sub class cannot be delayed");
215  }
217  UpdateFunctions();
218  return this;
219 }
220 
222 
224 {
225  if ( IsSubClass() ) {
226  NCBI_THROW(CSerialException,eIllegalCall,
227  "sub class cannot be delayed");
228  }
229  if ( EnabledDelayBuffers() ) {
231  UpdateFunctions();
232  }
233  return this;
234 }
235 
237 {
238  // determine function pointers
239  TVariantGetConst getConstFunc;
240  TVariantGet getFunc;
241  TVariantReadFunction readFunc;
242  TVariantWriteFunction writeFunc;
243  TVariantSkipFunction skipFunc;
244  TVariantCopyFunction copyFunc;
245 
246  // read/write/get
247  if ( CanBeDelayed() ) {
248  _ASSERT(!IsSubClass());
249  getConstFunc = &TFunc::GetConstDelayedVariant;
250  getFunc = &TFunc::GetDelayedVariant;
251  readFunc = &TFunc::ReadDelayedVariant;
252  writeFunc = &TFunc::WriteDelayedVariant;
253  }
254  else if ( IsInline() ) {
255  getConstFunc = &TFunc::GetConstInlineVariant;
256  getFunc = &TFunc::GetInlineVariant;
257  readFunc = &TFunc::ReadInlineVariant;
258  writeFunc = &TFunc::WriteInlineVariant;
259  }
260  else if ( IsObjectPointer() ) {
261  getConstFunc = &TFunc::GetConstPointerVariant;
262  getFunc = &TFunc::GetPointerVariant;
263  readFunc = &TFunc::ReadObjectPointerVariant;
264  writeFunc = &TFunc::WriteObjectPointerVariant;
265  }
266  else if ( IsNonObjectPointer() ) {
267  getConstFunc = &TFunc::GetConstPointerVariant;
268  getFunc = &TFunc::GetPointerVariant;
269  readFunc = &TFunc::ReadPointerVariant;
270  writeFunc = &TFunc::WritePointerVariant;
271  }
272  else { // subclass
273  getConstFunc = &TFunc::GetConstSubclassVariant;
274  getFunc = &TFunc::GetSubclassVariant;
275  readFunc = &TFunc::ReadSubclassVariant;
276  writeFunc = &TFunc::WriteSubclassVariant;
277  }
278 
279  // copy/skip
280  if ( IsObject() ) {
281  copyFunc = &TFunc::CopyObjectPointerVariant;
282  skipFunc = &TFunc::SkipObjectPointerVariant;
283  }
284  else {
285  copyFunc = &TFunc::CopyNonObjectVariant;
286  skipFunc = &TFunc::SkipNonObjectVariant;
287  }
288 
289  // update function pointers
290  m_GetConstFunction = getConstFunc;
291  m_GetFunction = getFunc;
296 }
297 
299  TObjectPtr choicePtr) const
300 {
302  _ASSERT(GetDelayBuffer(choicePtr).GetIndex() == GetIndex());
303 
304  TObjectPtr variantPtr = GetItemPtr(choicePtr);
305  TTypeInfo variantType = GetTypeInfo();
306  if ( IsPointer() ) {
307  // create object itself
308  variantPtr = CTypeConverter<TObjectPtr>::Get(variantPtr) =
309  variantType->Create();
310  if ( IsObjectPointer() ) {
311  _TRACE("Should check for real pointer type (CRef...)");
312  CTypeConverter<CObject>::Get(variantPtr).AddReference();
313  }
314  }
315 
316  BEGIN_OBJECT_FRAME_OF2(in, eFrameChoice, GetChoiceType());
317  BEGIN_OBJECT_FRAME_OF2(in, eFrameChoiceVariant, GetId());
318  variantType->ReadData(in, variantPtr);
321 }
322 
324 {
326 }
327 
329 {
331 }
332 
334 {
336 }
337 
339 {
341 }
342 
344 {
345  return GetChoiceType()->Create();
346 }
347 
350  TConstObjectPtr choicePtr)
351 {
352  _ASSERT(!variantInfo->CanBeDelayed());
353  _ASSERT(variantInfo->IsInline());
354  _ASSERT(variantInfo->GetChoiceType()->GetIndex(choicePtr) ==
355  variantInfo->GetIndex());
356  return variantInfo->GetItemPtr(choicePtr);
357 }
358 
361  TConstObjectPtr choicePtr)
362 {
363  _ASSERT(!variantInfo->CanBeDelayed());
364  _ASSERT(variantInfo->IsPointer());
365  _ASSERT(variantInfo->GetChoiceType()->GetIndex(choicePtr) ==
366  variantInfo->GetIndex());
367  TConstObjectPtr variantPtr = variantInfo->GetItemPtr(choicePtr);
368  variantPtr = CTypeConverter<TConstObjectPtr>::Get(variantPtr);
369  _ASSERT(variantPtr);
370  return variantPtr;
371 }
372 
375  TConstObjectPtr choicePtr)
376 {
377  _ASSERT(variantInfo->CanBeDelayed());
378  _ASSERT(variantInfo->GetChoiceType()->GetIndex(choicePtr) ==
379  variantInfo->GetIndex());
380  const_cast<CDelayBuffer&>(variantInfo->GetDelayBuffer(choicePtr)).Update();
381  TConstObjectPtr variantPtr = variantInfo->GetItemPtr(choicePtr);
382  if ( variantInfo->IsPointer() ) {
383  variantPtr = CTypeConverter<TConstObjectPtr>::Get(variantPtr);
384  _ASSERT(variantPtr);
385  }
386  return variantPtr;
387 }
388 
391  TConstObjectPtr choicePtr)
392 {
393  _ASSERT(variantInfo->IsSubClass());
394  _ASSERT(variantInfo->GetChoiceType()->GetIndex(choicePtr) ==
395  variantInfo->GetIndex());
396  const CChoiceTypeInfo* choiceType = variantInfo->GetChoiceType();
397  const CChoicePointerTypeInfo* choicePtrType =
399  TConstObjectPtr variantPtr =
400  choicePtrType->GetPointerTypeInfo()->GetObjectPointer(choicePtr);
401  _ASSERT(variantPtr);
402  return variantPtr;
403 }
404 
407  TObjectPtr choicePtr)
408 {
409  _ASSERT(!variantInfo->CanBeDelayed());
410  _ASSERT(variantInfo->IsInline());
411  _ASSERT(variantInfo->GetChoiceType()->GetIndex(choicePtr) ==
412  variantInfo->GetIndex());
413  return variantInfo->GetItemPtr(choicePtr);
414 }
415 
418  TObjectPtr choicePtr)
419 {
420  _ASSERT(!variantInfo->CanBeDelayed());
421  _ASSERT(variantInfo->IsPointer());
422  _ASSERT(variantInfo->GetChoiceType()->GetIndex(choicePtr) ==
423  variantInfo->GetIndex());
424  TObjectPtr variantPtr = variantInfo->GetItemPtr(choicePtr);
425  variantPtr = CTypeConverter<TObjectPtr>::Get(variantPtr);
426  _ASSERT(variantPtr);
427  return variantPtr;
428 }
429 
432  TObjectPtr choicePtr)
433 {
434  _ASSERT(variantInfo->CanBeDelayed());
435  _ASSERT(variantInfo->GetChoiceType()->GetIndex(choicePtr) ==
436  variantInfo->GetIndex());
437  variantInfo->GetDelayBuffer(choicePtr).Update();
438  TObjectPtr variantPtr = variantInfo->GetItemPtr(choicePtr);
439  if ( variantInfo->IsPointer() ) {
440  variantPtr = CTypeConverter<TObjectPtr>::Get(variantPtr);
441  _ASSERT(variantPtr);
442  }
443  return variantPtr;
444 }
445 
448  TObjectPtr choicePtr)
449 {
450  _ASSERT(variantInfo->IsSubClass());
451  _ASSERT(variantInfo->GetChoiceType()->GetIndex(choicePtr) ==
452  variantInfo->GetIndex());
453  const CChoiceTypeInfo* choiceType = variantInfo->GetChoiceType();
454  const CChoicePointerTypeInfo* choicePtrType =
456  TObjectPtr variantPtr =
457  choicePtrType->GetPointerTypeInfo()->GetObjectPointer(choicePtr);
458  _ASSERT(variantPtr);
459  return variantPtr;
460 }
461 
463  const CVariantInfo* variantInfo,
464  TObjectPtr choicePtr)
465 {
466  _ASSERT(!variantInfo->CanBeDelayed());
467  _ASSERT(variantInfo->IsInline());
468  const CChoiceTypeInfo* choiceType = variantInfo->GetChoiceType();
469  TMemberIndex index = variantInfo->GetIndex();
470  choiceType->SetIndex(choicePtr, index, in.GetMemoryPool());
471  in.ReadObject(variantInfo->GetItemPtr(choicePtr),
472  variantInfo->GetTypeInfo());
473  if (in.GetVerifyData() == eSerialVerifyData_Yes) {
474  variantInfo->Validate(choicePtr, in);
475  }
476 }
477 
479  const CVariantInfo* variantInfo,
480  TObjectPtr choicePtr)
481 {
482  _ASSERT(!variantInfo->CanBeDelayed());
483  _ASSERT(variantInfo->IsNonObjectPointer());
484  const CChoiceTypeInfo* choiceType = variantInfo->GetChoiceType();
485  TMemberIndex index = variantInfo->GetIndex();
486  choiceType->SetIndex(choicePtr, index, in.GetMemoryPool());
487  TObjectPtr variantPtr = variantInfo->GetItemPtr(choicePtr);
488  variantPtr = CTypeConverter<TObjectPtr>::Get(variantPtr);
489  _ASSERT(variantPtr != 0 );
490  in.ReadObject(variantPtr, variantInfo->GetTypeInfo());
491 }
492 
494  const CVariantInfo* variantInfo,
495  TObjectPtr choicePtr)
496 {
497  _ASSERT(!variantInfo->CanBeDelayed());
498  _ASSERT(variantInfo->IsObjectPointer());
499  const CChoiceTypeInfo* choiceType = variantInfo->GetChoiceType();
500  TMemberIndex index = variantInfo->GetIndex();
501  choiceType->SetIndex(choicePtr, index, in.GetMemoryPool());
502  TObjectPtr variantPtr = variantInfo->GetItemPtr(choicePtr);
503  variantPtr = CTypeConverter<TObjectPtr>::Get(variantPtr);
504  _ASSERT(variantPtr != 0 );
505  in.ReadExternalObject(variantPtr, variantInfo->GetTypeInfo());
506 }
507 
509  const CVariantInfo* variantInfo,
510  TObjectPtr choicePtr)
511 {
512  _ASSERT(!variantInfo->CanBeDelayed());
513  _ASSERT(variantInfo->IsSubClass());
514  const CChoiceTypeInfo* choiceType = variantInfo->GetChoiceType();
515  TMemberIndex index = variantInfo->GetIndex();
516  choiceType->SetIndex(choicePtr, index, in.GetMemoryPool());
517  const CChoicePointerTypeInfo* choicePtrType =
519  TObjectPtr variantPtr =
520  choicePtrType->GetPointerTypeInfo()->GetObjectPointer(choicePtr);
521  _ASSERT(variantPtr);
522  in.ReadExternalObject(variantPtr, variantInfo->GetTypeInfo());
523 }
524 
526  const CVariantInfo* variantInfo,
527  TObjectPtr choicePtr)
528 {
529  _ASSERT(variantInfo->CanBeDelayed());
530  const CChoiceTypeInfo* choiceType = variantInfo->GetChoiceType();
531  TMemberIndex index = variantInfo->GetIndex();
532  TTypeInfo variantType = variantInfo->GetTypeInfo();
533  if ( index != choiceType->GetIndex(choicePtr) ) {
534  // index is differnet from current -> first, reset choice
535  choiceType->ResetIndex(choicePtr);
536  CDelayBuffer& buffer = variantInfo->GetDelayBuffer(choicePtr);
537  if ( !buffer ) {
538  in.StartDelayBuffer();
539  if ( variantInfo->IsObjectPointer() )
540  in.SkipExternalObject(variantType);
541  else
542  in.SkipObject(variantType);
543  in.EndDelayBuffer(buffer, variantInfo, choicePtr);
544  // update index
545  choiceType->SetDelayIndex(choicePtr, index);
546  return;
547  }
548  buffer.Update();
549  _ASSERT(!variantInfo->GetDelayBuffer(choicePtr));
550  }
551  // select for reading
552  choiceType->SetIndex(choicePtr, index, in.GetMemoryPool());
553 
554  TObjectPtr variantPtr = variantInfo->GetItemPtr(choicePtr);
555  if ( variantInfo->IsPointer() ) {
556  variantPtr = CTypeConverter<TObjectPtr>::Get(variantPtr);
557  _ASSERT(variantPtr != 0 );
558  if ( variantInfo->IsObjectPointer() ) {
559  in.ReadExternalObject(variantPtr, variantType);
560  return;
561  }
562  }
563  in.ReadObject(variantPtr, variantType);
564 }
565 
567  const CVariantInfo* variantInfo,
568  TConstObjectPtr choicePtr)
569 {
570  _ASSERT(!variantInfo->CanBeDelayed());
571  _ASSERT(variantInfo->IsInline());
572  _ASSERT(variantInfo->GetChoiceType()->GetIndex(choicePtr) ==
573  variantInfo->GetIndex());
574  if (out.GetVerifyData() == eSerialVerifyData_Yes) {
575  variantInfo->Validate(choicePtr, out);
576  }
577  out.WriteObject(variantInfo->GetItemPtr(choicePtr),
578  variantInfo->GetTypeInfo());
579 }
580 
582  const CVariantInfo* variantInfo,
583  TConstObjectPtr choicePtr)
584 {
585  _ASSERT(!variantInfo->CanBeDelayed());
586  _ASSERT(variantInfo->IsNonObjectPointer());
587  _ASSERT(variantInfo->GetChoiceType()->GetIndex(choicePtr) ==
588  variantInfo->GetIndex());
589  TConstObjectPtr variantPtr = variantInfo->GetItemPtr(choicePtr);
590  variantPtr = CTypeConverter<TConstObjectPtr>::Get(variantPtr);
591  _ASSERT(variantPtr != 0 );
592  out.WriteObject(variantPtr, variantInfo->GetTypeInfo());
593 }
594 
596  const CVariantInfo* variantInfo,
597  TConstObjectPtr choicePtr)
598 {
599  _ASSERT(!variantInfo->CanBeDelayed());
600  _ASSERT(variantInfo->IsObjectPointer());
601  _ASSERT(variantInfo->GetChoiceType()->GetIndex(choicePtr) ==
602  variantInfo->GetIndex());
603  TConstObjectPtr variantPtr = variantInfo->GetItemPtr(choicePtr);
604  variantPtr = CTypeConverter<TConstObjectPtr>::Get(variantPtr);
605  _ASSERT(variantPtr != 0 );
606  out.WriteExternalObject(variantPtr, variantInfo->GetTypeInfo());
607 }
608 
610  const CVariantInfo* variantInfo,
611  TConstObjectPtr choicePtr)
612 {
613  _ASSERT(!variantInfo->CanBeDelayed());
614  _ASSERT(variantInfo->IsSubClass());
615  _ASSERT(variantInfo->GetChoiceType()->GetIndex(choicePtr) ==
616  variantInfo->GetIndex());
617  const CChoiceTypeInfo* choiceType = variantInfo->GetChoiceType();
618  const CChoicePointerTypeInfo* choicePtrType =
620  TConstObjectPtr variantPtr =
621  choicePtrType->GetPointerTypeInfo()->GetObjectPointer(choicePtr);
622  _ASSERT(variantPtr);
623  out.WriteExternalObject(variantPtr, variantInfo->GetTypeInfo());
624 }
625 
627  const CVariantInfo* variantInfo,
628  TConstObjectPtr choicePtr)
629 {
630  _ASSERT(variantInfo->CanBeDelayed());
631  _ASSERT(variantInfo->GetChoiceType()->GetIndex(choicePtr) ==
632  variantInfo->GetIndex());
633  const CDelayBuffer& buffer = variantInfo->GetDelayBuffer(choicePtr);
634  if ( buffer.GetIndex() == variantInfo->GetIndex() ) {
635  if ( buffer.HaveFormat(out.GetDataFormat()) ) {
636  out.Write(buffer.GetSource());
637  return;
638  }
639  const_cast<CDelayBuffer&>(buffer).Update();
640  _ASSERT(!variantInfo->GetDelayBuffer(choicePtr));
641  }
642  TConstObjectPtr variantPtr = variantInfo->GetItemPtr(choicePtr);
643  if ( variantInfo->IsPointer() ) {
644  variantPtr = CTypeConverter<TConstObjectPtr>::Get(variantPtr);
645  _ASSERT(variantPtr != 0 );
646  if ( variantInfo->IsObjectPointer() ) {
647  out.WriteExternalObject(variantPtr, variantInfo->GetTypeInfo());
648  return;
649  }
650  }
651  out.WriteObject(variantPtr, variantInfo->GetTypeInfo());
652 }
653 
655  const CVariantInfo* variantInfo)
656 {
657  _ASSERT(variantInfo->IsNotObject());
658  copier.CopyObject(variantInfo->GetTypeInfo());
659 }
660 
662  const CVariantInfo* variantInfo)
663 {
664  _ASSERT(variantInfo->IsObjectPointer());
665  copier.CopyExternalObject(variantInfo->GetTypeInfo());
666 }
667 
669  const CVariantInfo* variantInfo)
670 {
671  _ASSERT(variantInfo->IsNotObject());
672  in.SkipObject(variantInfo->GetTypeInfo());
673 }
674 
676  const CVariantInfo* variantInfo)
677 {
678  _ASSERT(variantInfo->IsObjectPointer());
679  in.SkipExternalObject(variantInfo->GetTypeInfo());
680 }
681 
683  const CVariantInfo* variantInfo,
684  TObjectPtr choicePtr)
685 {
686  CReadChoiceVariantHook* hook =
687  variantInfo->m_ReadHookData.GetHook(stream.m_ChoiceVariantHookKey);
688  if (!hook) {
689  hook = variantInfo->m_ReadHookData.GetPathHook(stream);
690  }
691  if ( hook ) {
692  CObjectInfo choice(choicePtr, variantInfo->GetChoiceType());
693  TMemberIndex index = variantInfo->GetIndex();
694  CObjectInfo::CChoiceVariant variant(choice, index);
695  _ASSERT(variant.Valid());
696  hook->ReadChoiceVariant(stream, variant);
697  }
698  else
699  variantInfo->DefaultReadVariant(stream, choicePtr);
700 }
701 
703  const CVariantInfo* variantInfo,
704  TConstObjectPtr choicePtr)
705 {
707  variantInfo->m_WriteHookData.GetHook(stream.m_ChoiceVariantHookKey);
708  if (!hook) {
709  hook = variantInfo->m_WriteHookData.GetPathHook(stream);
710  }
711  if ( hook ) {
712  CConstObjectInfo choice(choicePtr, variantInfo->GetChoiceType());
713  TMemberIndex index = variantInfo->GetIndex();
714  CConstObjectInfo::CChoiceVariant variant(choice, index);
715  _ASSERT(variant.Valid());
716  hook->WriteChoiceVariant(stream, variant);
717  }
718  else
719  variantInfo->DefaultWriteVariant(stream, choicePtr);
720 }
721 
723  const CVariantInfo* variantInfo)
724 {
725  CSkipChoiceVariantHook* hook =
727  if (!hook) {
728  hook = variantInfo->m_SkipHookData.GetPathHook(stream);
729  }
730  if ( hook ) {
731  CObjectTypeInfo type(variantInfo->GetChoiceType());
732  TMemberIndex index = variantInfo->GetIndex();
733  CObjectTypeInfo::CChoiceVariant variant(type, index);
734  _ASSERT(variant.Valid());
735  hook->SkipChoiceVariant(stream, variant);
736  }
737  else
738  variantInfo->DefaultSkipVariant(stream);
739 }
740 
742  const CVariantInfo* variantInfo)
743 {
744  CCopyChoiceVariantHook* hook =
745  variantInfo->m_CopyHookData.GetHook(stream.m_ChoiceVariantHookKey);
746  if (!hook) {
747  hook = variantInfo->m_CopyHookData.GetPathHook(stream.In());
748  }
749  if ( hook ) {
750  CObjectTypeInfo type(variantInfo->GetChoiceType());
751  TMemberIndex index = variantInfo->GetIndex();
752  CObjectTypeInfo::CChoiceVariant variant(type, index);
753  _ASSERT(variant.Valid());
754  hook->CopyChoiceVariant(stream, variant);
755  }
756  else
757  variantInfo->DefaultCopyVariant(stream);
758 }
759 
761 {
764 }
765 
768 {
771 }
772 
774 {
777 }
778 
780 {
783 }
784 
787 {
789  m_ReadHookData.SetPathHook(in,path,hook);
790 }
791 
793 {
796 }
797 
800 {
803 }
804 
806 {
809 }
810 
812 {
815 }
816 
819 {
821  m_WriteHookData.SetPathHook(out,path,hook);
822 }
823 
826 {
829 }
830 
832 {
835 }
836 
839 {
841  m_SkipHookData.SetPathHook(in,path,hook);
842 }
843 
845 {
848 }
849 
852 {
855 }
856 
858 {
861 }
862 
864 {
867 }
868 
869 void CVariantInfo::SetPathCopyHook(CObjectStreamCopier* stream, const string& path,
871 {
873  m_CopyHookData.SetPathHook(stream ? &(stream->In()) : 0,path,hook);
874 }
875 
CConstObjectInfoCV –.
Definition: objectiter.hpp:557
CConstObjectInfo –.
Definition: objectinfo.hpp:421
Copy hook for a choice variant (CHOICE)
Definition: objhook.hpp:280
CDelayBuffer.
Definition: delaybuf.hpp:58
CObjectIStream –.
Definition: objistr.hpp:93
CObjectInfoCV –.
Definition: objectiter.hpp:588
CObjectInfo –.
Definition: objectinfo.hpp:597
CObjectOStream –.
Definition: objostr.hpp:83
CObjectStreamCopier –.
Definition: objcopy.hpp:71
CObjectTypeInfoCV –.
Definition: objectiter.hpp:477
CObjectTypeInfo –.
Definition: objectinfo.hpp:94
Read hook for a choice variant (CHOICE)
Definition: objhook.hpp:117
Root class for all serialization exceptions.
Definition: exception.hpp:50
Skip hook for a choice variant (CHOICE)
Definition: objhook.hpp:239
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
static TConstObjectPtr GetConstPointerVariant(const CVariantInfo *variantInfo, TConstObjectPtr choicePtr)
Definition: variant.cpp:360
static void ReadObjectPointerVariant(CObjectIStream &in, const CVariantInfo *variantInfo, TObjectPtr choicePtr)
Definition: variant.cpp:493
static void WriteSubclassVariant(CObjectOStream &out, const CVariantInfo *variantInfo, TConstObjectPtr choicePtr)
Definition: variant.cpp:609
static TObjectPtr GetSubclassVariant(const CVariantInfo *variantInfo, TObjectPtr choicePtr)
Definition: variant.cpp:447
static void WritePointerVariant(CObjectOStream &out, const CVariantInfo *variantInfo, TConstObjectPtr choicePtr)
Definition: variant.cpp:581
static void CopyHookedVariant(CObjectStreamCopier &copier, const CVariantInfo *variantInfo)
Definition: variant.cpp:741
static void CopyObjectPointerVariant(CObjectStreamCopier &copier, const CVariantInfo *variantInfo)
Definition: variant.cpp:661
static TConstObjectPtr GetConstSubclassVariant(const CVariantInfo *variantInfo, TConstObjectPtr choicePtr)
Definition: variant.cpp:390
static void ReadHookedVariant(CObjectIStream &in, const CVariantInfo *variantInfo, TObjectPtr choicePtr)
Definition: variant.cpp:682
static TObjectPtr GetDelayedVariant(const CVariantInfo *variantInfo, TObjectPtr choicePtr)
Definition: variant.cpp:431
static void SkipHookedVariant(CObjectIStream &in, const CVariantInfo *variantInfo)
Definition: variant.cpp:722
static void WriteHookedVariant(CObjectOStream &out, const CVariantInfo *variantInfo, TConstObjectPtr choicePtr)
Definition: variant.cpp:702
static void SkipObjectPointerVariant(CObjectIStream &in, const CVariantInfo *variantInfo)
Definition: variant.cpp:675
static void ReadDelayedVariant(CObjectIStream &in, const CVariantInfo *variantInfo, TObjectPtr choicePtr)
Definition: variant.cpp:525
static void ReadInlineVariant(CObjectIStream &in, const CVariantInfo *variantInfo, TObjectPtr choicePtr)
Definition: variant.cpp:462
static TConstObjectPtr GetConstDelayedVariant(const CVariantInfo *variantInfo, TConstObjectPtr choicePtr)
Definition: variant.cpp:374
static void WriteInlineVariant(CObjectOStream &out, const CVariantInfo *variantInfo, TConstObjectPtr choicePtr)
Definition: variant.cpp:566
static void ReadSubclassVariant(CObjectIStream &in, const CVariantInfo *variantInfo, TObjectPtr choicePtr)
Definition: variant.cpp:508
static TObjectPtr GetPointerVariant(const CVariantInfo *variantInfo, TObjectPtr choicePtr)
Definition: variant.cpp:417
static void CopyNonObjectVariant(CObjectStreamCopier &copier, const CVariantInfo *variantInfo)
Definition: variant.cpp:654
static void SkipNonObjectVariant(CObjectIStream &in, const CVariantInfo *variantInfo)
Definition: variant.cpp:668
static void ReadPointerVariant(CObjectIStream &in, const CVariantInfo *variantInfo, TObjectPtr choicePtr)
Definition: variant.cpp:478
static void WriteObjectPointerVariant(CObjectOStream &out, const CVariantInfo *variantInfo, TConstObjectPtr choicePtr)
Definition: variant.cpp:595
static void WriteDelayedVariant(CObjectOStream &out, const CVariantInfo *variantInfo, TConstObjectPtr choicePtr)
Definition: variant.cpp:626
static TObjectPtr GetInlineVariant(const CVariantInfo *variantInfo, TObjectPtr choicePtr)
Definition: variant.cpp:406
static TConstObjectPtr GetConstInlineVariant(const CVariantInfo *variantInfo, TConstObjectPtr choicePtr)
Definition: variant.cpp:349
Write hook for a choice variant (CHOICE)
Definition: objhook.hpp:190
Include a standard set of the NCBI C++ Toolkit most basic headers.
std::ofstream out("events_result.xml")
main entry point for tests
static int type
Definition: getdata.c:31
int offset
Definition: replacements.h:160
#define _TRACE(message)
Definition: ncbidbg.hpp:122
#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 IsSubClass(void) const
void SetCopyFunction(TVariantCopyFunction func)
Definition: variant.cpp:333
void DefaultSkipVariant(CObjectIStream &in) const
EVariantType m_VariantType
Definition: variant.hpp:180
void SetWriteFunction(TVariantWriteFunction func)
Definition: variant.cpp:328
CVariantInfo * SetSubClass(void)
Definition: variant.cpp:206
TObjectPtr CreateChoice(void) const
Definition: variant.cpp:343
void SetPathCopyHook(CObjectStreamCopier *copier, const string &path, CCopyChoiceVariantHook *hook)
Definition: variant.cpp:869
CVariantInfo * SetPointer(void)
Definition: variant.cpp:184
const CMemberId & GetId(void) const
CHookData< CWriteChoiceVariantHook, TVariantWriteFunction > m_WriteHookData
Definition: variant.hpp:188
void SetLocalCopyHook(CObjectStreamCopier &copier, CCopyChoiceVariantHook *hook)
Definition: variant.cpp:850
TConstObjectPtr(* TVariantGetConst)(const CVariantInfo *variantInfo, TConstObjectPtr choicePtr)
Definition: variant.hpp:71
void DefaultWriteVariant(CObjectOStream &out, TConstObjectPtr choicePtr) const
void SetGlobalCopyHook(CCopyChoiceVariantHook *hook)
Definition: variant.cpp:844
void SetPathSkipHook(CObjectIStream *in, const string &path, CSkipChoiceVariantHook *hook)
Definition: variant.cpp:837
void SetLocalWriteHook(CObjectOStream &out, CWriteChoiceVariantHook *hook)
Definition: variant.cpp:798
void SetPathReadHook(CObjectIStream *in, const string &path, CReadChoiceVariantHook *hook)
Definition: variant.cpp:785
TObjectPtr GetItemPtr(TObjectPtr object) const
bool IsInline(void) const
void ResetLocalWriteHook(CObjectOStream &out)
Definition: variant.cpp:811
TVariantGet m_GetFunction
Definition: variant.hpp:185
bool IsObject(void) const
void SetReadFunction(TVariantReadFunction func)
Definition: variant.cpp:323
void ResetGlobalWriteHook(void)
Definition: variant.cpp:805
CHookData< CSkipChoiceVariantHook, TVariantSkipFunction > m_SkipHookData
Definition: variant.hpp:189
void ResetGlobalCopyHook(void)
Definition: variant.cpp:857
void ResetLocalSkipHook(CObjectIStream &in)
Definition: variant.cpp:831
TMemberIndex GetIndex(void) const
const CChoiceTypeInfo * GetChoiceType(void) const
bool IsNonObjectPointer(void) const
bool IsPointer(void) const
void SetGlobalWriteHook(CWriteChoiceVariantHook *hook)
Definition: variant.cpp:792
TVariantGetConst m_GetConstFunction
Definition: variant.hpp:184
CVariantInfo * SetObjectPointer(void)
Definition: variant.cpp:195
void DefaultCopyVariant(CObjectStreamCopier &copier) const
void SetGlobalReadHook(CReadChoiceVariantHook *hook)
Definition: variant.cpp:760
CDelayBuffer & GetDelayBuffer(TObjectPtr object) const
TObjectPtr(* TVariantGet)(const CVariantInfo *variantInfo, TObjectPtr choicePtr)
Definition: variant.hpp:73
TTypeInfo GetTypeInfo(void) const
bool IsNotObject(void) const
void SetPathWriteHook(CObjectOStream *out, const string &path, CWriteChoiceVariantHook *hook)
Definition: variant.cpp:817
CHookData< CReadChoiceVariantHook, TVariantReadFunction > m_ReadHookData
Definition: variant.hpp:187
virtual void UpdateDelayedBuffer(CObjectIStream &in, TObjectPtr classPtr) const override
Definition: variant.cpp:298
void ResetLocalCopyHook(CObjectStreamCopier &copier)
Definition: variant.cpp:863
bool CanBeDelayed(void) const
CHookData< CCopyChoiceVariantHook, TVariantCopyFunction > m_CopyHookData
Definition: variant.hpp:190
void ResetLocalReadHook(CObjectIStream &in)
Definition: variant.cpp:779
void DefaultReadVariant(CObjectIStream &in, TObjectPtr choicePtr) const
CVariantInfo(const CChoiceTypeInfo *choiceType, const CMemberId &id, TPointerOffsetType offset, const CTypeRef &type)
Definition: variant.cpp:128
CVariantInfo * SetDelayBuffer(CDelayBuffer *buffer)
Definition: variant.cpp:223
void ResetGlobalReadHook(void)
Definition: variant.cpp:773
virtual void UpdateFunctions(void) override
Definition: variant.cpp:236
void SetLocalReadHook(CObjectIStream &in, CReadChoiceVariantHook *hook)
Definition: variant.cpp:766
bool IsObjectPointer(void) const
void SetSkipFunction(TVariantSkipFunction func)
Definition: variant.cpp:338
void SetLocalSkipHook(CObjectIStream &in, CSkipChoiceVariantHook *hook)
Definition: variant.cpp:824
void Validate(TConstObjectPtr classPtr, const CObjectStack &stk) const
TPointerOffsetType m_DelayOffset
Definition: variant.hpp:182
@ eSubClassVariant
Definition: variant.hpp:82
@ eNonObjectPointerVariant
Definition: variant.hpp:80
@ eObjectPointerVariant
Definition: variant.hpp:81
static TObjectType & Get(TObjectPtr object)
Definition: serialutil.hpp:56
void * TObjectPtr
Definition: serialdef.hpp:55
size_t TMemberIndex
Type used for indexing class members and choice variants.
Definition: serialdef.hpp:230
const void * TConstObjectPtr
Definition: serialdef.hpp:59
ssize_t TPointerOffsetType
Definition: serialdef.hpp:241
#define XSERIAL_TYPEINFO_WRITELOCK
Definition: serialimpl.hpp:277
static const TObjectType * SafeCast(TTypeInfo type)
Definition: serialutil.hpp:76
@ eSerialVerifyData_Yes
do verify
Definition: serialdef.hpp:111
void(* TVariantSkipFunction)(CObjectIStream &in, const CVariantInfo *variantInfo)
Definition: hookfunc.hpp:115
void(* TVariantReadFunction)(CObjectIStream &in, const CVariantInfo *variantInfo, TObjectPtr classPtr)
Definition: hookfunc.hpp:107
void SetDefaultFunction(TFunction func)
Definition: hookdata.hpp:133
void SetPathHook(CObjectStack *stk, const string &path, THook *hook)
Definition: hookdata.hpp:151
void ResetGlobalHook(void)
Definition: hookdata.hpp:162
void(* TVariantCopyFunction)(CObjectStreamCopier &copier, const CVariantInfo *variantInfo)
Definition: hookfunc.hpp:113
void SetLocalHook(TLocalHooks &key, THook *hook)
Definition: hookdata.hpp:141
THook * GetPathHook(CObjectStack &stk) const
Definition: hookdata.hpp:177
void SetGlobalHook(THook *hook)
Definition: hookdata.hpp:146
THook * GetHook(const TLocalHooks &key) const
Definition: hookdata.hpp:173
void ResetLocalHook(TLocalHooks &key)
Definition: hookdata.hpp:157
void(* TVariantWriteFunction)(CObjectOStream &out, const CVariantInfo *variantInfo, TConstObjectPtr classPtr)
Definition: hookfunc.hpp:110
void CopyExternalObject(TTypeInfo type)
void Update(void)
Parse stored data.
Definition: delaybuf.hpp:80
virtual void SkipChoiceVariant(CObjectIStream &stream, const CObjectTypeInfoCV &variant)=0
CLocalHookSet< CCopyChoiceVariantHook > m_ChoiceVariantHookKey
Definition: objcopy.hpp:160
virtual void WriteChoiceVariant(CObjectOStream &out, const CConstObjectInfoCV &variant)=0
#define BEGIN_OBJECT_FRAME_OF2(Stream, Type, Arg)
Definition: objstack.hpp:219
CLocalHookSet< CWriteChoiceVariantHook > m_ChoiceVariantHookKey
Definition: objostr.hpp:832
CObjectIStream & In(void) const
virtual void ReadChoiceVariant(CObjectIStream &in, const CObjectInfoCV &variant)=0
This method will be called at approriate time when the object of requested type is to be read.
virtual void CopyChoiceVariant(CObjectStreamCopier &copier, const CObjectTypeInfoCV &variant)=0
bool Valid(void) const
CLocalHookSet< CSkipChoiceVariantHook > m_ChoiceVariantSkipHookKey
Definition: objistr.hpp:1151
CLocalHookSet< CReadChoiceVariantHook > m_ChoiceVariantHookKey
Definition: objistr.hpp:1148
#define END_OBJECT_FRAME_OF(Stream)
Definition: objstack.hpp:201
void CopyObject(TTypeInfo type)
Copy object, omitting file header both in input and output streams.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
TMemberIndex GetIndex(TConstObjectPtr object) const
void ReadData(CObjectIStream &in, TObjectPtr object) const
void SetDelayIndex(TObjectPtr object, TMemberIndex index) const
Definition: choice.cpp:365
TConstObjectPtr GetObjectPointer(TConstObjectPtr object) const
void ResetIndex(TObjectPtr object) const
TObjectPtr Create(CObjectMemoryPool *memoryPool=0) const
Create object of this type on heap (can be deleted by operator delete)
void SetIndex(TObjectPtr object, TMemberIndex index, CObjectMemoryPool *pool=0) const
const CPointerTypeInfo * GetPointerTypeInfo(void) const
Definition: choiceptr.hpp:62
#define NCBI_XSERIAL_EXPORT
Definition: ncbi_export.h:1435
Multi-threading – mutexes; rw-locks; semaphore.
std::istream & in(std::istream &in_, double &x_)
static pcre_uint8 * buffer
Definition: pcretest.c:1051
bool EnabledDelayBuffers(void)
Definition: member.cpp:281
CVariantInfoFunctions TFunc
Definition: variant.cpp:126
Definition: type.c:6
#define _ASSERT
Modified on Wed Apr 17 13:10:39 2024 by modify_doxy.py rev. 669887