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

Go to the SVN repository for this file.

1 /* $Id: objostr.cpp 101054 2023-10-23 14:30:08Z 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>
37 #include <corelib/ncbimtx.hpp>
38 #include <corelib/ncbithr.hpp>
39 #include <corelib/ncbi_param.hpp>
40 
41 #include <util/bytesrc.hpp>
42 
43 #include <serial/objostr.hpp>
44 #include <serial/objistr.hpp>
45 #include <serial/objcopy.hpp>
46 #include <serial/impl/typeref.hpp>
47 #include <serial/impl/objlist.hpp>
48 #include <serial/impl/memberid.hpp>
49 #include <serial/typeinfo.hpp>
50 #include <serial/enumvalues.hpp>
52 #include <serial/delaybuf.hpp>
54 #include <serial/impl/choice.hpp>
56 #include <serial/impl/continfo.hpp>
57 #include <serial/impl/member.hpp>
58 #include <serial/impl/variant.hpp>
59 #include <serial/objectinfo.hpp>
60 #include <serial/objectiter.hpp>
61 #include <serial/impl/objlist.hpp>
62 #include <serial/serialimpl.hpp>
63 #include <serial/error_codes.hpp>
64 
65 #if defined(NCBI_OS_MSWIN)
66 # include <corelib/ncbi_os_mswin.hpp>
67 # include <io.h>
68 # include <fcntl.h>
69 #endif
70 
71 #undef _TRACE
72 #define _TRACE(arg) ((void)0)
73 
74 #define NCBI_USE_ERRCODE_X Serial_OStream
75 
77 
78 NCBI_PARAM_DECL(bool, SERIAL, FastWriteDouble);
79 NCBI_PARAM_DEF(bool, SERIAL, FastWriteDouble, true);
80 typedef NCBI_PARAM_TYPE(SERIAL, FastWriteDouble) TFastWriteDouble;
82 
83 
85  const string& fileName,
86  TSerialOpenFlags openFlags,
87  TSerial_Format_Flags formatFlags)
88 {
89  CNcbiOstream* outStream = 0;
90  bool deleteStream;
91  if ( ((openFlags & eSerial_StdWhenEmpty) && fileName.empty()) ||
92  ((openFlags & eSerial_StdWhenDash) && fileName == "-") ||
93  ((openFlags & eSerial_StdWhenStd) && fileName == "stdout") ) {
94 #if defined(NCBI_OS_MSWIN)
95  NcbiSys_setmode(NcbiSys_fileno(stdout), (format == eSerial_AsnBinary) ? O_BINARY : O_TEXT);
96 #endif
97  outStream = &NcbiCout;
98  deleteStream = false;
99  }
100  else {
101  switch ( format ) {
102  case eSerial_AsnText:
103  case eSerial_Xml:
104  case eSerial_Json:
105  outStream = new CNcbiOfstream(fileName.c_str());
106  break;
107  case eSerial_AsnBinary:
108  outStream = new CNcbiOfstream(fileName.c_str(),
109  IOS_BASE::out | IOS_BASE::binary);
110  break;
111  default:
113  "CObjectOStream::Open: unsupported format");
114  }
115  if ( !*outStream ) {
116  delete outStream;
117  NCBI_THROW(CSerialException,eNotOpen, string("cannot open file: ")+fileName);
118  }
119  deleteStream = true;
120  }
121 
122  return Open(format, *outStream,
123  deleteStream ? eTakeOwnership : eNoOwnership, formatFlags);
124 }
125 
127  CNcbiOstream& outStream,
128  bool bdeleteStream)
129 {
130  EOwnership deleteStream = bdeleteStream ? eTakeOwnership : eNoOwnership;
131  switch ( format ) {
132  case eSerial_AsnText:
133  return OpenObjectOStreamAsn(outStream, deleteStream);
134  case eSerial_AsnBinary:
135  return OpenObjectOStreamAsnBinary(outStream, deleteStream);
136  case eSerial_Xml:
137  return OpenObjectOStreamXml(outStream, deleteStream);
138  case eSerial_Json:
139  return OpenObjectOStreamJson(outStream, deleteStream);
140  default:
141  break;
142  }
144  "CObjectOStream::Open: unsupported format");
145 }
146 
148  CNcbiOstream& outStream,
149  EOwnership deleteStream,
150  TSerial_Format_Flags formatFlags)
151 {
152  CObjectOStream* os = NULL;
153  switch ( format ) {
154  case eSerial_AsnText:
155  os = OpenObjectOStreamAsn(outStream, deleteStream);
156  break;
157  case eSerial_AsnBinary:
158  os = OpenObjectOStreamAsnBinary(outStream, deleteStream);
159  break;
160  case eSerial_Xml:
161  os = OpenObjectOStreamXml(outStream, deleteStream);
162  break;
163  case eSerial_Json:
164  os = OpenObjectOStreamJson(outStream, deleteStream);
165  break;
166  default:
167  break;
168  }
169  if (os != NULL) {
170  os->SetFormattingFlags(formatFlags);
171  return os;
172  }
174  "CObjectOStream::Open: unsupported format");
175 }
176 
177 /////////////////////////////////////////////////////////////////////////////
178 // data verification setup
179 
180 
181 NCBI_PARAM_ENUM_ARRAY(ESerialVerifyData, SERIAL, VERIFY_DATA_WRITE)
182 {
183  {"NO", eSerialVerifyData_No},
184  {"NEVER", eSerialVerifyData_Never},
185  {"YES", eSerialVerifyData_Yes},
186  {"ALWAYS", eSerialVerifyData_Always},
187  {"DEFVALUE", eSerialVerifyData_DefValue},
188  {"DEFVALUE_ALWAYS", eSerialVerifyData_DefValueAlways}
189 };
190 NCBI_PARAM_ENUM_DECL(ESerialVerifyData, SERIAL, VERIFY_DATA_WRITE);
192 typedef NCBI_PARAM_TYPE(SERIAL, VERIFY_DATA_WRITE) TSerialVerifyData;
193 
194 
196 {
197  ESerialVerifyData now = TSerialVerifyData::GetThreadDefault();
198  if (now != eSerialVerifyData_Never &&
199  now != eSerialVerifyData_Always &&
202  TSerialVerifyData::ResetThreadDefault();
203  } else {
204  if (verify != now &&
207  "CObjectOStream::SetVerifyDataThread: data verification disabled");
208  }
209  TSerialVerifyData::SetThreadDefault(verify);
210  }
211  }
212 }
213 
215 {
216  ESerialVerifyData now = TSerialVerifyData::GetDefault();
217  if (now != eSerialVerifyData_Never &&
218  now != eSerialVerifyData_Always &&
221  TSerialVerifyData::ResetDefault();
222  } else {
223  if (verify != now &&
226  "CObjectOStream::SetVerifyDataGlobal: data verification disabled");
227  }
228  TSerialVerifyData::SetDefault(verify);
229  }
230  }
231 }
232 
234 {
235  ESerialVerifyData now = TSerialVerifyData::GetThreadDefault();
236  if (now == eSerialVerifyData_Default) {
237  now = TSerialVerifyData::GetDefault();
238  if (now == eSerialVerifyData_Default) {
239 // this is to provide compatibility with old implementation
240  const char* str = getenv(SERIAL_VERIFY_DATA_WRITE);
241  if (str) {
242  if (NStr::CompareNocase(str,"YES") == 0) {
243  now = eSerialVerifyData_Yes;
244  } else if (NStr::CompareNocase(str,"NO") == 0) {
245  now = eSerialVerifyData_No;
246  } else if (NStr::CompareNocase(str,"NEVER") == 0) {
248  } else if (NStr::CompareNocase(str,"ALWAYS") == 0) {
250  } else if (NStr::CompareNocase(str,"DEFVALUE") == 0) {
252  } else if (NStr::CompareNocase(str,"DEFVALUE_ALWAYS") == 0) {
254  }
255  }
256  }
257  }
258  if (now != eSerialVerifyData_Default) {
259  return now;
260  }
261  // change the default here, if you like
262  return eSerialVerifyData_Yes;
263 }
264 
265 /////////////////////////////////////////////////////////////////////////////
266 // FixWrongChars setup
267 
268 NCBI_PARAM_ENUM_ARRAY(EFixNonPrint, SERIAL, WRONG_CHARS_WRITE)
269 {
270  {"SKIP", eFNP_Skip},
271  {"ALLOW", eFNP_Allow},
272  {"REPLACE", eFNP_Replace},
273  {"REPLACE_AND_WARN", eFNP_ReplaceAndWarn},
274  {"THROW", eFNP_Throw},
275  {"ABORT", eFNP_Abort}
276 };
277 NCBI_PARAM_ENUM_DECL(EFixNonPrint, SERIAL, WRONG_CHARS_WRITE);
279 typedef NCBI_PARAM_TYPE(SERIAL, WRONG_CHARS_WRITE) TSerialFixChars;
280 
282 {
283  static CSafeStatic<TSerialFixChars> s_SerialFixChars;
284  return s_SerialFixChars->Get();
285 }
286 
289  if (GetStackDepth() > 1 && FetchFrameFromTop(1).HasTypeInfo() &&
290  FetchFrameFromTop(1).GetTypeInfo()->GetDataSpec() != EDataSpec::eASN) {
291  return eFNP_Allow;
292  }
293  }
294  return m_FixMethod;
295 }
296 
297 /////////////////////////////////////////////////////////////////////////////
298 
300  CNcbiOstream& out, EOwnership edeleteOut)
301  : m_Output(out, edeleteOut == eTakeOwnership), m_Fail(fNoError), m_Flags(fFlagNone),
302  m_Separator(""),
303  m_DataFormat(format),
304  m_ParseDelayBuffers(eDelayBufferPolicyNotSet),
305  m_SpecialCaseWrite(eWriteAsNormal),
306  m_AutoSeparator(false),
307  m_WriteNamedIntegersByValue(false),
308  m_FastWriteDouble(s_FastWriteDouble->Get()),
309  m_EnforceWritingDefaults(false),
310  m_TypeAlias(nullptr),
311  m_NonPrintSubst('#'),
312  m_FixMethod(x_GetFixCharsMethodDefault()),
313  m_VerifyData(x_GetVerifyDataDefault())
314 {
315 }
316 
318 {
319  try {
320  Close();
321  ResetLocalHooks();
322  }
323  NCBI_CATCH_X(4, "Cannot close serializing output stream")
324 }
325 
326 
328 {
329  if ( GetFlags() & fFlagNoAutoFlush ) {
330  FlushBuffer();
331  }
332  else {
333  Flush();
334  }
335 }
336 
337 
339 {
340  if (m_Fail != fNotOpen) {
341  try {
342  DefaultFlush();
343  if ( m_Objects )
344  m_Objects->Clear();
345  ClearStack();
346  m_Fail = fNotOpen;
347  ResetState();
348  m_Output.Close();
349  }
350  catch (CException& exc) {
351  if ( InGoodState() )
352  RethrowError(fWriteError, "cannot close output stream",exc);
353  }
354  }
355 }
356 
358 {
360  ResetPathHooks();
364 }
365 
367 {
368  TFailFlags old = m_Fail;
369  m_Fail |= flags;
370  return old;
371 }
372 
374  const char* message)
375 {
376  TFailFlags old = m_Fail;
377  m_Fail |= flags;
378  if ( !old && flags ) {
379  // first fail
380  ERR_POST_X(5, "CObjectOStream: error at "<<
381  GetPosition()<<": "<<GetStackTrace() << ": " << message);
382  }
383  return old;
384 }
385 
387 {
388  if ( fail() ) {
389  // fail flag already set
390  return false;
391  }
392  else if ( m_Output.fail() ) {
393  // IO exception thrown without setting fail flag
396  return false;
397  }
398  else {
399  // ok
400  return true;
401  }
402 }
403 
405 {
406  PopFrame();
407  throw;
408 }
409 
410 void CObjectOStream::Unended(const string& msg)
411 {
412  if ( InGoodState() )
413  ThrowError(fFail, msg);
414 }
415 
417 {
418  Unended("internal error: unended object stack frame");
419 }
420 
422 {
425  if (hook) {
427  if (item) {
428  item->SetPathWriteHook(this, GetStackPath(), set ? hook : NULL);
429  }
430  }
431  }
434  if (hook) {
436  if (item) {
437  item->SetPathWriteHook(this, GetStackPath(), set ? hook : NULL);
438  }
439  }
440  }
443  if (hook) {
445  if (item) {
446  item->SetPathWriteHook(this, GetStackPath(), set ? hook : NULL);
447  }
448  }
449  }
450 }
451 
453  CWriteObjectHook* hook)
454 {
455  m_PathWriteObjectHooks.SetHook(path,hook);
456  WatchPathHooks();
457 }
459  CWriteClassMemberHook* hook)
460 {
461  m_PathWriteMemberHooks.SetHook(path,hook);
462  WatchPathHooks();
463 }
466 {
467  m_PathWriteVariantHooks.SetHook(path,hook);
468  WatchPathHooks();
469 }
470 
472 {
473  m_ParseDelayBuffers = policy;
474 }
477 {
478  return m_ParseDelayBuffers;
479 }
480 
482 {
485  }
486  return
493 }
494 
496 {
497  return GetStackTraceASN();
498 }
499 
501 {
502  return m_Output.GetStreamPos();
503 }
504 
506 {
507  return m_Output.GetStreamPos();
508 }
509 
510 string CObjectOStream::GetPosition(void) const
511 {
513 }
514 
516  TFailFlags flags, const char* message,
517  CException* exc)
518 {
519  ThrowError1(diag_info, flags, string(message),exc);
520 }
521 
523  TFailFlags flags, const string& message,
524  CException* exc)
525 {
527  try {
528  DefaultFlush();
529  } catch(...) {
530  }
531  string msg(message);
532  if (flags == fUnassigned) {
533  msg = "cannot write unassigned member "+message;
534  }
535  SetFailFlags(flags, msg.c_str());
536  msg.insert(0,GetPosition()+": ");
537  switch (flags)
538  {
539  case fNoError:
540  CNcbiDiag(diag_info, eDiag_Trace) << ErrCode(NCBI_ERRCODE_X, 12)
541  << message;
542  return;
543 // case fEOF: err = CSerialException::eEOF; break;
544  default:
545  case fWriteError: err = CSerialException::eIoError; break;
546 // case fFormatError: err = CSerialException::eFormatError; break;
547  case fOverflow: err = CSerialException::eOverflow; break;
548  case fInvalidData: err = CSerialException::eInvalidData; break;
549  case fIllegalCall: err = CSerialException::eIllegalCall; break;
550  case fFail: err = CSerialException::eFail; break;
551  case fNotOpen: err = CSerialException::eNotOpen; break;
553  case fUnassigned:
554  throw CUnassignedMember(diag_info,exc,CUnassignedMember::eWrite, msg);
555  }
556  throw CSerialException(diag_info,exc,err,msg);
557 }
558 
560 {
561  FlushBuffer();
562  if ( m_Objects )
563  m_Objects->Clear();
564 }
565 
567 {
568  WriteObject(object.GetObjectPtr(), object.GetTypeInfo());
569 }
570 
572 {
573  const CMemberInfo* memberInfo = member.GetMemberInfo();
574  TConstObjectPtr classPtr = member.GetClassObject().GetObjectPtr();
575  WriteClassMember(memberInfo->GetId(),
576  memberInfo->GetTypeInfo(),
577  memberInfo->GetMemberPtr(classPtr));
578 }
579 
581  TTypeInfo memberType, TConstObjectPtr memberPtr, ESpecialCaseWrite)
582 {
583  WriteClassMember(memberId,memberType,memberPtr);
584 }
585 
587 {
588  const CVariantInfo* variantInfo = object.GetVariantInfo();
589  TConstObjectPtr choicePtr = object.GetChoiceObject().GetObjectPtr();
590  variantInfo->DefaultWriteVariant(*this, choicePtr);
591 }
592 
594 {
595  // root writer
596  BEGIN_OBJECT_FRAME2(eFrameNamed, object.GetTypeInfo());
597 
598  WriteFileHeader(object.GetTypeInfo());
599 
600  WriteObject(object);
601 
602  EndOfWrite();
603 
605 
606  if ( GetAutoSeparator() )
607  Separator(*this);
608 }
609 
611 {
612  // root writer
613  BEGIN_OBJECT_FRAME2(eFrameNamed, typeInfo);
614 
615  WriteFileHeader(typeInfo);
616 
617  WriteObject(object, typeInfo);
618 
619  EndOfWrite();
620 
622 
623  if ( GetAutoSeparator() )
624  Separator(*this);
625 }
626 
628 {
629  Write(object, type.Get());
630 }
631 
633 {
634  if ( m_Objects )
635  m_Objects->RegisterObject(typeInfo);
636 }
637 
639  TTypeInfo typeInfo)
640 {
641  if ( m_Objects )
642  m_Objects->RegisterObject(object, typeInfo);
643 }
644 
646 {
647  if ( m_Objects ) {
648  size_t firstObject = m_Objects->GetObjectCount();
649  WriteObject(object);
650  size_t lastObject = m_Objects->GetObjectCount();
651  m_Objects->ForgetObjects(firstObject, lastObject);
652  }
653  else {
654  WriteObject(object);
655  }
656 }
657 
659  TTypeInfo typeInfo)
660 {
661  _TRACE("CObjectOStream::WriteExternalObject(" <<
662  NStr::PtrToString(objectPtr) << ", "
663  << typeInfo->GetName() << ')');
664  RegisterObject(objectPtr, typeInfo);
665  WriteObject(objectPtr, typeInfo);
666 }
667 
669 {
670  CRef<CByteSourceReader> reader = source.Open();
671  m_Output.Write(*reader);
672  return true;
673 }
674 
675 void CObjectOStream::Write(const char* data, size_t size)
676 {
678 }
679 
681 {
682  // do nothing by default
683 }
684 
686  TTypeInfo declaredTypeInfo)
687 {
688  _TRACE("WritePointer("<<NStr::PtrToString(objectPtr)<<", "
689  <<declaredTypeInfo->GetName()<<")");
690  if ( objectPtr == 0 ) {
691  _TRACE("WritePointer: "<<NStr::PtrToString(objectPtr)<<": null");
693  return;
694  }
695  TTypeInfo realTypeInfo = declaredTypeInfo->GetRealTypeInfo(objectPtr);
696  if ( m_Objects ) {
697  const CWriteObjectInfo* info =
698  m_Objects->RegisterObject(objectPtr, realTypeInfo);
699  if ( info ) {
700  // old object
701  WriteObjectReference(info->GetIndex());
702  return;
703  }
704  }
705  if ( declaredTypeInfo == realTypeInfo ) {
706  _TRACE("WritePointer: "<<NStr::PtrToString(objectPtr)<<": new");
707  WriteThis(objectPtr, realTypeInfo);
708  }
709  else {
710  _TRACE("WritePointer: "<<NStr::PtrToString(objectPtr)<<
711  ": new "<<realTypeInfo->GetName());
712  WriteOther(objectPtr, realTypeInfo);
713  }
714 }
715 
717 {
718  WriteObject(object, typeInfo);
719 }
720 
722 {
723  WriteDouble(data);
724 }
725 
726 #if SIZEOF_LONG_DOUBLE != 0
727 void CObjectOStream::WriteLDouble(long double data)
728 {
729  // TODO: remove conversion to double when CXX-5612 will be implemented
730  WriteDouble((double)data);
731 }
732 #endif
733 
735 {
736 }
737 
739 {
740 }
741 
743 #ifndef VIRTUAL_MID_LEVEL_IO
744  namedTypeInfo
745 #endif
746  ,
747  TTypeInfo objectType,
748  TConstObjectPtr objectPtr)
749 {
750 #ifndef VIRTUAL_MID_LEVEL_IO
751  BEGIN_OBJECT_FRAME2(eFrameNamed, namedTypeInfo);
752  BeginNamedType(namedTypeInfo);
753 #endif
754  WriteObject(objectPtr, objectType);
755 #ifndef VIRTUAL_MID_LEVEL_IO
756  EndNamedType();
758 #endif
759 }
760 
762  TTypeInfo objectType,
763  CObjectStreamCopier& copier)
764 {
765 #ifndef VIRTUAL_MID_LEVEL_IO
766  BEGIN_OBJECT_2FRAMES_OF2(copier, eFrameNamed, namedTypeInfo);
767  copier.In().BeginNamedType(namedTypeInfo);
768  BeginNamedType(namedTypeInfo);
769 
770  CopyObject(objectType, copier);
771 
772  EndNamedType();
773  copier.In().EndNamedType();
774  END_OBJECT_2FRAMES_OF(copier);
775 #else
776  BEGIN_OBJECT_FRAME_OF2(copier.In(), eFrameNamed, namedTypeInfo);
777  copier.In().BeginNamedType(namedTypeInfo);
778 
779  CopyObject(objectType, copier);
780 
781  copier.In().EndNamedType();
782  END_OBJECT_FRAME_OF(copier.In());
783 #endif
784 }
785 
787  TTypeInfo typeInfo)
788 {
789  WriteOtherBegin(typeInfo);
790  WriteObject(object, typeInfo);
791  WriteOtherEnd(typeInfo);
792 }
793 
795 {
796 }
797 
799 {
800 }
801 
803 {
804 }
805 
807 {
808 }
809 
811  TConstObjectPtr containerPtr)
812 {
813  BEGIN_OBJECT_FRAME2(eFrameArray, cType);
814  BeginContainer(cType);
815 
817  if ( cType->InitIterator(i, containerPtr) ) {
818  TTypeInfo elementType = cType->GetElementType();
819  BEGIN_OBJECT_FRAME2(eFrameArrayElement, elementType);
820 
821  const CPointerTypeInfo* pointerType =
822  dynamic_cast<const CPointerTypeInfo*>(elementType);
823  do {
824  TConstObjectPtr elementPtr = cType->GetElementPtr(i);
825  if ( pointerType &&
826  !pointerType->GetObjectPointer(elementPtr) ) {
829  "NULL element while writing container "+
830  cType->GetName());
831  }
832  continue;
833  }
834 
835  BeginContainerElement(elementType);
836 
837  WriteObject(elementPtr, elementType);
838 
840  } while ( cType->NextElement(i) );
841 
843  }
844 
845  EndContainer();
847 }
848 
850 {
852 
853  WriteObject(element);
854 
856 }
857 
859  CObjectStreamCopier& copier)
860 {
861  BEGIN_OBJECT_2FRAMES_OF2(copier, eFrameArray, cType);
862  copier.In().BeginContainer(cType);
863  BeginContainer(cType);
864 
865  TTypeInfo elementType = cType->GetElementType();
866  BEGIN_OBJECT_2FRAMES_OF2(copier, eFrameArrayElement, elementType);
867 
868  while ( copier.In().BeginContainerElement(elementType) ) {
869  BeginContainerElement(elementType);
870 
871  CopyObject(elementType, copier);
872 
874  copier.In().EndContainerElement();
875  }
876 
877  END_OBJECT_2FRAMES_OF(copier);
878 
879  EndContainer();
880  copier.In().EndContainer();
881  END_OBJECT_2FRAMES_OF(copier);
882 }
883 
885 {
886 }
887 
889 {
890 }
891 
893  TConstObjectPtr classPtr)
894 {
895  BEGIN_OBJECT_FRAME2(eFrameClass, classType);
896  BeginClass(classType);
897 
898  for ( CClassTypeInfo::CIterator i(classType); i.Valid(); ++i ) {
899  classType->GetMemberInfo(*i)->WriteMember(*this, classPtr);
900  }
901 
902  EndClass();
904 }
905 
907  TTypeInfo memberType,
908  TConstObjectPtr memberPtr)
909 {
910  BEGIN_OBJECT_FRAME2(eFrameClassMember, memberId);
911  BeginClassMember(memberId);
912 
913  WriteObject(memberPtr, memberType);
914 
915  EndClassMember();
917 }
918 
920  const CDelayBuffer& buffer)
921 {
922  if ( !buffer.HaveFormat(GetDataFormat()) )
923  return false;
924 
925  BEGIN_OBJECT_FRAME2(eFrameClassMember, memberId);
926  BeginClassMember(memberId);
927 
928  Write(buffer.GetSource());
929 
930  EndClassMember();
932  return true;
933 }
934 
936  CObjectStreamCopier& copier)
937 {
938  BEGIN_OBJECT_2FRAMES_OF2(copier, eFrameClass, classType);
939  copier.In().BeginClass(classType);
940  BeginClass(classType);
941 
942  vector<Uint1> read(classType->GetMembers().LastIndex() + 1);
943 
944  BEGIN_OBJECT_2FRAMES_OF(copier, eFrameClassMember);
945 
946  TMemberIndex index;
947  while ( (index = copier.In().BeginClassMember(classType)) !=
948  kInvalidMember ) {
949  const CMemberInfo* memberInfo = classType->GetMemberInfo(index);
950  copier.In().SetTopMemberId(memberInfo->GetId());
951  SetTopMemberId(memberInfo->GetId());
952  copier.SetPathHooks(*this, true);
953 
954  if ( read[index] ) {
955  copier.In().DuplicatedMember(memberInfo);
956  }
957  else {
958  read[index] = true;
959  BeginClassMember(memberInfo->GetId());
960 
961  memberInfo->CopyMember(copier);
962 
963  EndClassMember();
964  }
965 
966  copier.SetPathHooks(*this, false);
967  copier.In().EndClassMember();
968  }
969 
970  END_OBJECT_2FRAMES_OF(copier);
971 
972  // init all absent members
973  for ( CClassTypeInfo::CIterator i(classType); i.Valid(); ++i ) {
974  if ( !read[*i] ) {
975  classType->GetMemberInfo(*i)->CopyMissingMember(copier);
976  }
977  }
978 
979  EndClass();
980  copier.In().EndClass();
981  END_OBJECT_2FRAMES_OF(copier);
982 }
983 
985  CObjectStreamCopier& copier)
986 {
987  BEGIN_OBJECT_2FRAMES_OF2(copier, eFrameClass, classType);
988  copier.In().BeginClass(classType);
989  BeginClass(classType);
990 
991  CClassTypeInfo::CIterator pos(classType);
992  BEGIN_OBJECT_2FRAMES_OF(copier, eFrameClassMember);
993 
994  TMemberIndex index;
995  while ( (index = copier.In().BeginClassMember(classType, *pos)) !=
996  kInvalidMember ) {
997  const CMemberInfo* memberInfo = classType->GetMemberInfo(index);
998  copier.In().SetTopMemberId(memberInfo->GetId());
999  SetTopMemberId(memberInfo->GetId());
1000  copier.SetPathHooks(*this, true);
1001 
1002  for ( TMemberIndex i = *pos; i < index; ++i ) {
1003  // init missing member
1004  classType->GetMemberInfo(i)->CopyMissingMember(copier);
1005  }
1006  BeginClassMember(memberInfo->GetId());
1007 
1008  memberInfo->CopyMember(copier);
1009 
1010  pos.SetIndex(index + 1);
1011 
1012  EndClassMember();
1013  copier.SetPathHooks(*this, false);
1014  copier.In().EndClassMember();
1015  }
1016 
1017  END_OBJECT_2FRAMES_OF(copier);
1018 
1019  // init all absent members
1020  for ( ; pos.Valid(); ++pos ) {
1021  classType->GetMemberInfo(*pos)->CopyMissingMember(copier);
1022  }
1023 
1024  EndClass();
1025  copier.In().EndClass();
1026  END_OBJECT_2FRAMES_OF(copier);
1027 }
1028 
1030 {
1031 }
1033 {
1034 }
1036 {
1037 }
1038 
1040  CObjectStreamCopier& copier)
1041 {
1042  BEGIN_OBJECT_2FRAMES_OF2(copier, eFrameChoice, choiceType);
1043 
1044  BeginChoice(choiceType);
1045  copier.In().BeginChoice(choiceType);
1046  BEGIN_OBJECT_2FRAMES_OF(copier, eFrameChoiceVariant);
1047  TMemberIndex index = copier.In().BeginChoiceVariant(choiceType);
1048  if ( index == kInvalidMember ) {
1049  if (choiceType->MayBeEmpty() || copier.In().CanSkipUnknownVariants()) {
1050  copier.In().SkipAnyContentVariant();
1051  } else {
1052  copier.ThrowError(CObjectIStream::fFormatError,
1053  "choice variant id expected");
1054  }
1055  } else {
1056  for (;;) {
1057  const CVariantInfo* variantInfo = choiceType->GetVariantInfo(index);
1058  if (variantInfo->GetId().IsAttlist()) {
1059  const CMemberInfo* memberInfo =
1060  dynamic_cast<const CMemberInfo*>(
1061  choiceType->GetVariants().GetItemInfo(index));
1062  SetTopMemberId(memberInfo->GetId());
1063  BeginClassMember(memberInfo->GetId());
1064  memberInfo->CopyMember(copier);
1065  EndClassMember();
1066  copier.In().EndChoiceVariant();
1067  index = copier.In().BeginChoiceVariant(choiceType);
1068  if ( index == kInvalidMember ) {
1069  if (copier.In().CanSkipUnknownVariants()) {
1070  copier.In().SkipAnyContentVariant();
1071  break;
1072  } else {
1073  copier.ThrowError(CObjectIStream::fFormatError,
1074  "choice variant id expected");
1075  }
1076  }
1077  variantInfo = choiceType->GetVariantInfo(index);
1078  }
1079  copier.In().SetTopMemberId(variantInfo->GetId());
1080  copier.Out().SetTopMemberId(variantInfo->GetId());
1081  copier.SetPathHooks(copier.Out(), true);
1082  BeginChoiceVariant(choiceType, variantInfo->GetId());
1083 
1084  variantInfo->CopyVariant(copier);
1085 
1086  EndChoiceVariant();
1087  copier.SetPathHooks(copier.Out(), false);
1088  copier.In().EndChoiceVariant();
1089  break;
1090  }
1091  }
1092  END_OBJECT_2FRAMES_OF(copier);
1093  copier.In().EndChoice();
1094  EndChoice();
1095  END_OBJECT_2FRAMES_OF(copier);
1096 }
1097 
1099  TConstObjectPtr aliasPtr)
1100 {
1101  if (aliasType->IsFullAlias()) {
1102  m_TypeAlias = aliasType;
1103  }
1104  WriteNamedType(aliasType, aliasType->GetPointedType(),
1105  aliasType->GetDataPtr(aliasPtr));
1106  m_TypeAlias = nullptr;
1107 }
1108 
1110  CObjectStreamCopier& copier)
1111 {
1112  if (aliasType->IsFullAlias()) {
1113  copier.In().m_TypeAlias = m_TypeAlias = aliasType;
1114  }
1115  CopyNamedType(aliasType, aliasType->GetPointedType(),
1116  copier);
1117  copier.In().m_TypeAlias = m_TypeAlias = nullptr;
1118 }
1119 
1121 {
1122 }
1123 
1125 {
1126 }
1127 
1129 {
1130  _ASSERT(!m_Ended);
1131  _ASSERT(m_Length == 0);
1132  if ( GetStream().InGoodState() ) {
1133  GetStream().EndBytes(*this);
1134  m_Ended = true;
1135  }
1136 }
1137 
1139 {
1140  if ( !m_Ended ) {
1141  try {
1142  GetStream().Unended("byte block not fully written");
1143  }
1144  catch (...) {
1145  ERR_POST_X(6, "unended byte block");
1146  }
1147  }
1148 }
1149 
1151 {
1152 }
1153 
1155 {
1156 }
1157 
1159 {
1160  _ASSERT(!m_Ended);
1161  _ASSERT(m_Length == 0);
1162  if ( GetStream().InGoodState() ) {
1163  GetStream().EndChars(*this);
1164  m_Ended = true;
1165  }
1166 }
1167 
1169 {
1170  if ( !m_Ended ) {
1171  try {
1172  GetStream().Unended("char block not fully written");
1173  }
1174  catch (...) {
1175  ERR_POST_X(7, "unended char block");
1176  }
1177  }
1178 }
1179 
1180 
1182 {
1183  // flush stream buffer by default
1184  FlushBuffer();
1185 }
1186 
1187 
1189 {
1190  m_Output.SetCanceledCallback(callback);
1191 }
1192 
1194 {
1195  TSerial_Format_Flags accepted =
1197  if (flags & ~accepted) {
1198  ERR_POST_X_ONCE(13, Warning <<
1199  "CObjectOStream::SetFormattingFlags: ignoring unknown formatting flags");
1200  }
1203 }
1204 
1205 
1206 
1207 #ifdef NCBI_STRICT_GI
1209 {
1210  WriteInt8(obj.Get());
1211 }
1212 
1214 {
1215  TGi obj;
1216  in.ReadGi(obj);
1217  WriteGi(obj);
1218 }
1219 #endif
1220 
1221 
CConstObjectInfoCV –.
Definition: objectiter.hpp:557
CConstObjectInfoMI –.
Definition: objectiter.hpp:397
CConstObjectInfo –.
Definition: objectinfo.hpp:421
CDelayBuffer.
Definition: delaybuf.hpp:58
Incapsulate compile time information such as __FILE__, __LINE__, NCBI_MODULE, current function.
Definition: ncbidiag.hpp:65
CNcbiDiag –.
Definition: ncbidiag.hpp:924
CObjectIStream –.
Definition: objistr.hpp:93
CObjectOStream –.
Definition: objostr.hpp:83
CObjectStreamCopier –.
Definition: objcopy.hpp:71
CSafeStatic<>::
T & Get(void)
Create the variable if not created yet, return the reference.
Root class for all serialization exceptions.
Definition: exception.hpp:50
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
Thrown on an attempt to write unassigned data member.
Definition: exception.hpp:84
Write hook for a choice variant (CHOICE)
Definition: objhook.hpp:190
Write hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:175
Write hook for a standalone object.
Definition: objhook.hpp:161
Interface for testing cancellation request in a long lasting operation.
Definition: icanceled.hpp:51
Definition: set.hpp:45
Include a standard set of the NCBI C++ Toolkit most basic headers.
static uch flags
std::ofstream out("events_result.xml")
main entry point for tests
#define false
Definition: bool.h:36
static const char * str(char *buf, int n)
Definition: stats.c:84
char data[12]
Definition: iconv.c:80
TId Get(void) const
Definition: ncbimisc.hpp:921
@ eTakeOwnership
An object can take ownership of another.
Definition: ncbi_types.h:136
@ eNoOwnership
No ownership is assumed.
Definition: ncbi_types.h:135
#define NULL
Definition: ncbistd.hpp:225
#define ERR_POST_X_ONCE(err_subcode, message)
Error posting only once during program execution with default error code and given error subcode.
Definition: ncbidiag.hpp:621
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:550
#define NCBI_ERRCODE_X
Returns currently set default error code.
Definition: ncbidiag.hpp:376
@ eDiag_Trace
Trace message.
Definition: ncbidiag.hpp:657
#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
#define NCBI_CATCH_X(err_subcode, message)
Catch CExceptions as well with default error code and given error subcode placed in diagnostics.
Definition: ncbiexpt.hpp:615
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
const CMemberId & GetId(void) const
bool IsAttlist(void) const
void DefaultWriteVariant(CObjectOStream &out, TConstObjectPtr choicePtr) const
void WriteMember(CObjectOStream &out, TConstObjectPtr classPtr) const
TObjectPtr GetMemberPtr(TObjectPtr classPtr) const
void CopyMissingMember(CObjectStreamCopier &copier) const
void SetPathWriteHook(CObjectOStream *out, const string &path, CWriteClassMemberHook *hook)
Definition: member.cpp:595
void CopyVariant(CObjectStreamCopier &copier) const
void CopyMember(CObjectStreamCopier &copier) const
const CItemInfo * GetItemInfo(TMemberIndex index) const
bool Valid(void) const
void SetIndex(TMemberIndex index)
TTypeInfo GetTypeInfo(void) const
void SetPathWriteHook(CObjectOStream *out, const string &path, CWriteChoiceVariantHook *hook)
Definition: variant.cpp:817
TMemberIndex LastIndex(void) const
Definition: memberlist.hpp:82
EFixNonPrint
How to process non-printing character in the ASN VisibleString.
Definition: serialdef.hpp:173
int TSerialOpenFlags
Definition: serialdef.hpp:135
size_t TMemberIndex
Type used for indexing class members and choice variants.
Definition: serialdef.hpp:230
const TMemberIndex kInvalidMember
Special value returned from FindMember.
Definition: serialdef.hpp:237
ESerialVerifyData
Data verification parameters.
Definition: serialdef.hpp:107
const void * TConstObjectPtr
Definition: serialdef.hpp:59
#define SERIAL_VERIFY_DATA_WRITE
Definition: serialdef.hpp:103
#define XSERIAL_TYPEINFO_WRITELOCK
Definition: serialimpl.hpp:277
unsigned int TSerial_Format_Flags
MSerial_Format –.
Definition: serialbase.hpp:571
ESerialDataFormat
Data file format.
Definition: serialdef.hpp:71
@ fSerial_AsnText_NoEol
do not write end-of-line symbol
Definition: serialdef.hpp:82
@ fSerial_AsnText_NoIndentation
do not use indentation
Definition: serialdef.hpp:81
@ eSerial_StdWhenStd
use std when filename is "stdin"/"stdout"
Definition: serialdef.hpp:130
@ eSerial_StdWhenDash
use std stream when filename is "-"
Definition: serialdef.hpp:129
@ eSerial_StdWhenEmpty
use std stream when filename is empty
Definition: serialdef.hpp:128
@ eFNP_Allow
pass through unchanged, post no error message
Definition: serialdef.hpp:175
@ eFNP_Skip
skip, post no error message
Definition: serialdef.hpp:174
@ eFNP_Throw
replace with '#', throw an exception
Definition: serialdef.hpp:178
@ eFNP_Abort
replace with '#', post an error of severity FATAL
Definition: serialdef.hpp:179
@ eFNP_ReplaceAndWarn
replace with '#', post an error of severity ERROR
Definition: serialdef.hpp:177
@ eFNP_Replace
replace with '#' silently
Definition: serialdef.hpp:176
@ eSerialVerifyData_Never
never verify (even if set to verify later on)
Definition: serialdef.hpp:110
@ eSerialVerifyData_DefValueAlways
initialize field with default
Definition: serialdef.hpp:114
@ eSerialVerifyData_DefValue
initialize field with default
Definition: serialdef.hpp:113
@ eSerialVerifyData_Yes
do verify
Definition: serialdef.hpp:111
@ eSerialVerifyData_Always
always verify (even if set not to later on)
Definition: serialdef.hpp:112
@ eSerialVerifyData_No
do not verify
Definition: serialdef.hpp:109
@ eSerialVerifyData_Default
use current default
Definition: serialdef.hpp:108
@ eSerial_AsnText
ASN.1 text.
Definition: serialdef.hpp:73
@ eSerial_Xml
XML.
Definition: serialdef.hpp:75
@ eSerial_Json
JSON.
Definition: serialdef.hpp:76
@ eSerial_AsnBinary
ASN.1 binary.
Definition: serialdef.hpp:74
bool IsEmpty(void) const
Definition: hookdatakey.hpp:60
static CTypeInfo * FindType(const CObjectStack &stk)
Definition: pathhook.cpp:272
CNcbiStreampos GetStreamOffset(void) const
Definition: objostr.cpp:500
virtual void EndClassMember(void)
Definition: objostr.cpp:888
virtual string GetStackTrace(void) const override
Get current stack trace as string.
Definition: objostr.cpp:495
MLIOVIR void WriteClassMemberSpecialCase(const CMemberId &memberId, TTypeInfo memberType, TConstObjectPtr memberPtr, ESpecialCaseWrite how)
Definition: objostr.cpp:580
void RegisterObject(TTypeInfo typeInfo)
Definition: objlist.cpp:60
TFailFlags SetFailFlagsNoError(TFailFlags flags)
Set fail flags, but do not ERR_POST any messages.
Definition: objostr.cpp:366
virtual void EndClassMember(void)
Definition: objistr.cpp:1372
virtual void BeginClass(const CClassTypeInfo *classInfo)=0
void WriteClassMember(const CConstObjectInfoMI &member)
Definition: objostr.cpp:571
virtual void CopyGi(CObjectIStream &in)
Definition: objostr.cpp:1213
EFixNonPrint x_FixCharsMethod(void) const
Definition: objostr.cpp:287
CStreamPathHook< CVariantInfo *, CWriteChoiceVariantHook * > m_PathWriteVariantHooks
Definition: objostr.hpp:826
virtual void EndBytes(const ByteBlock &block)
Definition: objostr.cpp:1124
virtual void WriteThis(TConstObjectPtr object, TTypeInfo typeInfo)
Definition: objostr.cpp:716
virtual void x_SetPathHooks(bool set) override
Definition: objostr.cpp:421
virtual void WriteFileHeader(TTypeInfo type)
Definition: objostr.cpp:680
virtual void BeginChoice(const CChoiceTypeInfo *choiceType)
Definition: objostr.cpp:1029
void SetHook(const string &path, THook hook)
Definition: pathhook.hpp:102
TObjectIndex GetObjectCount(void) const
#define END_OBJECT_2FRAMES_OF(Stream)
Definition: objstack.hpp:234
virtual void BeginBytes(const ByteBlock &block)
Definition: objostr.cpp:1120
CStreamObjectPathHook< CWriteObjectHook * > m_PathWriteObjectHooks
Definition: objostr.hpp:824
virtual void EndContainerElement(void)
Definition: objistr.cpp:1314
bool fail(void) const
Check if any of fail flags is set.
virtual void WriteOther(TConstObjectPtr object, TTypeInfo typeInfo)
Definition: objostr.cpp:786
virtual void EndChars(const CharBlock &block)
Definition: objostr.cpp:1154
virtual void WriteInt8(Int8 data)=0
virtual void EndClass(void)
Definition: objostr.cpp:884
void WriteExternalObject(TConstObjectPtr object, TTypeInfo typeInfo)
Definition: objostr.cpp:658
void CopyObject(TTypeInfo objectType, CObjectStreamCopier &copier)
void SetUseEol(bool set)
Set up end-of-line symbol usage in text streams.
virtual void WriteSeparator(void)
Definition: objostr.cpp:1181
void Clear(void)
Definition: objlist.cpp:54
static CObjectOStream * OpenObjectOStreamAsn(CNcbiOstream &out, EOwnership deleteOut)
Definition: objostrasn.cpp:58
bool GetAutoSeparator(void)
Get separator auto-output paramater.
#define ThrowError(flag, mess)
Definition: objstack.hpp:113
virtual void EndContainer(void)=0
void Close(void)
Definition: objostr.cpp:338
static void SetVerifyDataThread(ESerialVerifyData verify)
Set up default output data verification for streams created by the current thread.
Definition: objostr.cpp:195
void ResetPathHooks(void)
Definition: objstack.cpp:63
AutoPtr< CWriteObjectList > m_Objects
Definition: objostr.hpp:799
void SetDelayBufferParsingPolicy(EDelayBufferParsing policy)
Definition: objostr.cpp:471
void Unended(const string &msg)
Definition: objostr.cpp:410
virtual void WriteNullPointer(void)=0
virtual void EndContainerElement(void)
Definition: objostr.cpp:806
virtual TMemberIndex BeginClassMember(const CClassTypeInfo *classType)=0
void SetPathWriteObjectHook(const string &path, CWriteObjectHook *hook)
Definition: objostr.cpp:452
friend CObjectOStream & Separator(CObjectOStream &os)
CLocalHookSet< CWriteObjectHook > m_ObjectHookKey
Definition: objostr.hpp:830
const CMemberInfo * GetMemberInfo(void) const
#define BEGIN_OBJECT_FRAME2(Type, Arg)
Definition: objstack.hpp:225
static CObjectOStream * OpenObjectOStreamAsnBinary(CNcbiOstream &out, EOwnership deleteOut)
Definition: objostrasnb.cpp:66
CStreamPathHook< CMemberInfo *, CWriteClassMemberHook * > m_PathWriteMemberHooks
Definition: objostr.hpp:825
const string & GetStackPath(void) const
Definition: objstack.cpp:263
MLIOVIR void WriteContainer(const CContainerTypeInfo *containerType, TConstObjectPtr containerPtr)
Definition: objostr.cpp:810
virtual void BeginNamedType(TTypeInfo namedTypeInfo)
Definition: objistr.cpp:1276
TFlags GetFlags(void) const
EDelayBufferParsing m_ParseDelayBuffers
Definition: objostr.hpp:802
static CObjectOStream * Open(ESerialDataFormat format, CNcbiOstream &outStream, bool deleteOutStream)
Create serial object writer and attach it to an output stream.
Definition: objostr.cpp:126
virtual void BeginNamedType(TTypeInfo namedTypeInfo)
Definition: objostr.cpp:734
void SetPathHooks(CObjectStack &stk, bool set)
Definition: objcopy.cpp:249
CObjectOStream & GetStream(void) const
TFrame & FetchFrameFromTop(size_t index)
virtual void BeginContainer(const CContainerTypeInfo *containerType)=0
virtual ~CObjectOStream(void)
Destructor.
Definition: objostr.cpp:317
virtual void EndNamedType(void)
Definition: objistr.cpp:1280
virtual TMemberIndex BeginChoiceVariant(const CChoiceTypeInfo *choiceType)=0
void WriteObject(const CConstObjectInfo &object)
Definition: objostr.cpp:566
const CConstObjectInfo & GetClassObject(void) const
Get containing class data.
string GetStackTraceASN(void) const
Definition: objstack.cpp:80
virtual void WriteOtherEnd(TTypeInfo typeInfo)
Definition: objostr.cpp:794
void ThrowError1(const CDiagCompileInfo &diag_info, TFailFlags fail, const char *message, CException *exc=0)
Definition: objostr.cpp:515
#define BEGIN_OBJECT_2FRAMES_OF(Stream, Type)
Definition: objstack.hpp:247
void Write(const CConstObjectInfo &object)
Definition: objostr.cpp:593
virtual void BeginContainer(const CContainerTypeInfo *containerType)=0
void ClearStack(void)
Definition: objstack.cpp:75
TTypeInfo GetTypeInfo(void) const
virtual void SkipAnyContentVariant(void)
Definition: objistr.cpp:1837
TTypeInfo m_TypeAlias
Definition: objistr.hpp:1052
#define END_OBJECT_FRAME()
Definition: objstack.hpp:227
#define BEGIN_OBJECT_FRAME_OF2(Stream, Type, Arg)
Definition: objstack.hpp:219
size_t GetStackDepth(void) const
EFixNonPrint x_GetFixCharsMethodDefault(void) const
Definition: objostr.cpp:281
CLocalHookSet< CWriteChoiceVariantHook > m_ChoiceVariantHookKey
Definition: objostr.hpp:832
void WriteContainerElement(const CConstObjectInfo &element)
Definition: objostr.cpp:849
CObjectIStream & In(void) const
virtual void WriteObjectReference(TObjectIndex index)=0
bool InGoodState(void)
Check fail flags and also the state of output stream.
Definition: objostr.cpp:386
void SetUseIndentation(bool set)
Set up indentation usage in text streams.
ESerialDataFormat GetDataFormat(void) const
Get data format.
virtual void BeginChoiceVariant(const CChoiceTypeInfo *choiceType, const CMemberId &id)=0
CNcbiStreampos GetStreamPos(void) const
Get the current stream position.
Definition: objostr.cpp:505
virtual string GetPosition(void) const override
Get current stream position as string.
Definition: objostr.cpp:510
static CObjectOStream * OpenObjectOStreamJson(CNcbiOstream &out, EOwnership deleteOut)
Definition: objostrjson.cpp:60
MLIOVIR void CopyNamedType(TTypeInfo namedTypeInfo, TTypeInfo typeInfo, CObjectStreamCopier &copier)
Definition: objostr.cpp:761
virtual void EndOfWrite(void)
Definition: objostr.cpp:559
MLIOVIR void WriteClass(const CClassTypeInfo *objectType, TConstObjectPtr objectPtr)
Definition: objostr.cpp:892
void ForgetObjects(TObjectIndex from, TObjectIndex to)
Definition: objlist.cpp:146
CObjectOStream & Out(void) const
THook GetHook(CObjectStack &stk) const
Definition: pathhook.hpp:106
COStreamBuffer m_Output
Definition: objostr.hpp:796
void SetHook(const string &path, THook hook)
Definition: pathhook.hpp:121
EErrCode
Error codes.
Definition: exception.hpp:53
void SetTopMemberId(const CMemberId &memberId)
static void SetVerifyDataGlobal(ESerialVerifyData verify)
Set up default output data verification for streams created by the current process.
Definition: objostr.cpp:214
MLIOVIR void CopyClassRandom(const CClassTypeInfo *objectType, CObjectStreamCopier &copier)
Definition: objostr.cpp:935
CLocalHookSet< CWriteClassMemberHook > m_ClassMemberHookKey
Definition: objostr.hpp:831
#define BEGIN_OBJECT_2FRAMES_OF2(Stream, Type, Arg)
Definition: objstack.hpp:249
void FlushBuffer(void)
MLIOVIR void CopyAlias(const CAliasTypeInfo *AliasType, CObjectStreamCopier &copier)
Definition: objostr.cpp:1109
void SetCanceledCallback(const ICanceled *callback)
Set cancellation check callback.
Definition: objostr.cpp:1188
void RegisterObject(TTypeInfo typeInfo)
Definition: objostr.cpp:632
virtual bool BeginContainerElement(TTypeInfo elementType)=0
virtual void ResetState(void)
Definition: objstack.cpp:58
void WatchPathHooks(bool set=true)
bool ShouldParseDelayBuffer(void) const
Definition: objostr.cpp:481
void SetPathWriteMemberHook(const string &path, CWriteClassMemberHook *hook)
Definition: objostr.cpp:458
virtual void WriteFloat(float data)
Definition: objostr.cpp:721
virtual void EndChoice(void)
Definition: objostr.cpp:1032
void HandleEOF(CEofException &)
Definition: objostr.cpp:404
TTypeInfo m_TypeAlias
Definition: objostr.hpp:808
static TInfo FindItem(const CObjectStack &stk)
Definition: pathhook.hpp:110
void WritePointer(TConstObjectPtr object, TTypeInfo typeInfo)
Definition: objostr.cpp:685
virtual void WriteDouble(double data)=0
MLIOVIR void WriteAlias(const CAliasTypeInfo *aliasType, TConstObjectPtr aliasPtr)
Definition: objostr.cpp:1098
TFailFlags m_Fail
Definition: objostr.hpp:797
void PopFrame(void)
CObjectOStream(ESerialDataFormat format, CNcbiOstream &out, EOwnership deleteOut=eNoOwnership)
Definition: objostr.cpp:299
virtual void BeginChars(const CharBlock &block)
Definition: objostr.cpp:1150
virtual void WriteGi(const TGi &obj)
Definition: objostr.cpp:1208
virtual void UnendedFrame(void) override
Definition: objostr.cpp:416
bool CanSkipUnknownVariants(void)
Simple check if it's allowed to skip unknown variants.
MLIOVIR void WriteNamedType(TTypeInfo namedTypeInfo, TTypeInfo typeInfo, TConstObjectPtr object)
Definition: objostr.cpp:742
MLIOVIR void CopyContainer(const CContainerTypeInfo *containerType, CObjectStreamCopier &copier)
Definition: objostr.cpp:858
EDelayBufferParsing GetDelayBufferParsingPolicy(void) const
Definition: objostr.cpp:476
virtual void EndClass(void)
Definition: objistr.cpp:1368
virtual void EndChoiceVariant(void)
Definition: objistr.cpp:1478
TConstObjectPtr GetObjectPtr(void) const
Get pointer to object.
void DefaultFlush(void)
Definition: objostr.cpp:327
virtual void EndNamedType(void)
Definition: objostr.cpp:738
virtual void BeginClass(const CClassTypeInfo *classInfo)=0
void WriteSeparateObject(const CConstObjectInfo &object)
Definition: objostr.cpp:645
static CObjectOStream * OpenObjectOStreamXml(CNcbiOstream &out, EOwnership deleteOut)
Definition: objostrxml.cpp:60
EDelayBufferParsing
DelayBuffer parsing policy.
Definition: objostr.hpp:416
TFailFlags SetFailFlags(TFailFlags flags, const char *message)
Set fail flags.
Definition: objostr.cpp:373
void DuplicatedMember(const CMemberInfo *memberInfo)
Definition: objistr.cpp:1047
virtual void SetFormattingFlags(TSerial_Format_Flags flags)
Set output formatting flags.
Definition: objostr.cpp:1193
#define RethrowError(flag, mess, exc)
Definition: objostr.hpp:578
THook GetHook(CObjectStack &stk) const
Definition: pathhook.hpp:125
MLIOVIR void CopyChoice(const CChoiceTypeInfo *choiceType, CObjectStreamCopier &copier)
Definition: objostr.cpp:1039
#define END_OBJECT_FRAME_OF(Stream)
Definition: objstack.hpp:201
virtual void BeginContainerElement(TTypeInfo elementType)
Definition: objostr.cpp:802
void SetPathWriteVariantHook(const string &path, CWriteChoiceVariantHook *hook)
Definition: objostr.cpp:464
virtual void EndChoice(void)
Definition: objistr.cpp:1475
virtual void BeginClassMember(const CMemberId &id)=0
virtual void WriteOtherBegin(TTypeInfo typeInfo)=0
virtual void EndContainer(void)
Definition: objostr.cpp:798
void ResetLocalHooks(void)
Definition: objostr.cpp:357
static ESerialVerifyData x_GetVerifyDataDefault(void)
Definition: objostr.cpp:233
EFixNonPrint m_FixMethod
Definition: objostr.hpp:822
ESerialVerifyData GetVerifyData(void) const
Get output data verification parameter.
virtual void BeginChoice(const CChoiceTypeInfo *choiceType)
Definition: objistr.cpp:1472
virtual void EndChoiceVariant(void)
Definition: objostr.cpp:1035
void WriteChoiceVariant(const CConstObjectInfoCV &member)
Definition: objostr.cpp:586
MLIOVIR void CopyClassSequential(const CClassTypeInfo *objectType, CObjectStreamCopier &copier)
Definition: objostr.cpp:984
bool IsEmpty(void) const
Definition: pathhook.hpp:82
void Flush(void)
@ fFormatError
Input file formatting does not conform with specification.
Definition: objistr.hpp:377
@ fIllegalCall
Illegal in a given context function call.
Definition: objostr.hpp:324
@ fNoError
No error.
Definition: objostr.hpp:314
@ fInvalidData
Output data is incorrect.
Definition: objostr.hpp:322
@ fNotOpen
No output file.
Definition: objostr.hpp:328
@ fNotImplemented
Method is not implemented.
Definition: objostr.hpp:330
@ fUnassigned
Mandatory object member is unassigned Normally this results in throwing CUnassignedMember exception.
Definition: objostr.hpp:333
@ fOverflow
Internal buffer overflow.
Definition: objostr.hpp:320
@ fWriteError
An unknown error when writing into output file.
Definition: objostr.hpp:317
@ fFail
Internal error, the real reason is unclear.
Definition: objostr.hpp:326
@ eIoError
An unknown error during serialization.
Definition: exception.hpp:56
@ eInvalidData
Data is incorrect.
Definition: exception.hpp:59
@ eOverflow
Data is beyond the allowed limits.
Definition: exception.hpp:58
@ eNotOpen
No input or output file.
Definition: exception.hpp:62
@ eFail
Internal error, the real reason is unclear.
Definition: exception.hpp:61
@ eNotImplemented
Attempt to use unimplemented funtionality.
Definition: exception.hpp:54
@ eIllegalCall
Illegal in a given context function call.
Definition: exception.hpp:60
@ eDelayBufferPolicyAlwaysParse
Parse always.
Definition: objostr.hpp:420
@ eDelayBufferPolicyNotSet
Parse only if local hook are present.
Definition: objostr.hpp:418
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
bool fail(void) const
void Write(const char *data, size_t dataLength)
Definition: strbuffer.cpp:1142
CNcbiStreampos GetStreamPos(void) const
void SetCanceledCallback(const ICanceled *callback)
Definition: strbuffer.cpp:864
const char * GetError(void) const
void Close(void)
Definition: strbuffer.cpp:842
void ResetFail(void)
Int8 NcbiStreamposToInt8(NCBI_NS_STD::char_traits< char >::pos_type stream_pos)
Convert stream position to 64-bit int.
Definition: ncbistre.hpp:771
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
Definition: ncbistre.hpp:500
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define NcbiCout
Definition: ncbistre.hpp:543
IO_PREFIX::streampos CNcbiStreampos
Portable alias for streampos.
Definition: ncbistre.hpp:134
static string Int8ToString(Int8 value, TNumToStringFlags flags=0, int base=10)
Convert Int8 to string.
Definition: ncbistr.hpp:5159
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
Definition: ncbistr.cpp:219
static void PtrToString(string &out_str, const void *ptr)
Convert pointer to string.
Definition: ncbistr.cpp:2771
const string & GetName(void) const
Get name of this type.
Definition: typeinfo.cpp:249
virtual TTypeInfo GetRealTypeInfo(TConstObjectPtr object) const
Definition: typeinfo.cpp:309
TTypeInfo GetPointedType(void) const
const CItemsInfo & GetVariants(void) const
bool MayBeEmpty(void) const
Definition: choice.hpp:129
const CMemberInfo * GetMemberInfo(TMemberIndex index) const
const CVariantInfo * GetVariantInfo(TMemberIndex index) const
TObjectPtr GetDataPtr(TObjectPtr objectPtr) const
Definition: aliasinfo.cpp:178
TConstObjectPtr GetElementPtr(const CConstIterator &it) const
void SetPathWriteHook(CObjectOStream *out, const string &path, CWriteObjectHook *hook)
Set local context-specific write hook.
Definition: typeinfo.cpp:417
bool InitIterator(CConstIterator &it, TConstObjectPtr containerPtr) const
bool NextElement(CConstIterator &it) const
TConstObjectPtr GetObjectPointer(TConstObjectPtr object) const
const CItemsInfo & GetMembers(void) const
bool IsFullAlias(void) const
Definition: aliasinfo.hpp:79
TTypeInfo GetElementType(void) const
enum ENcbiOwnership EOwnership
Ownership relations between objects.
#define ErrCode()
Get the error code for the last failed system function.
Definition: mdb.c:377
Definition of all error codes used in serial libraries (xser.lib, xcser.lib).
int i
static MDB_envinfo info
Definition: mdb_load.c:37
const TYPE & Get(const CNamedParameterList *param)
const struct ncbi::grid::netcache::search::fields::SIZE size
const CharType(& source)[N]
Definition: pointer.h:1149
#define verify(expr)
Definition: ncbi_assert.h:51
Defines MS Windows specifics for our "C++" code.
Static variables safety - create on demand, destroy on application termination.
#define nullptr
Definition: ncbimisc.hpp:45
Multi-threading – mutexes; rw-locks; semaphore.
Multi-threading – classes, functions, and features.
static Format format
Definition: njn_ioutil.cpp:53
std::istream & in(std::istream &in_, double &x_)
NCBI_PARAM_ENUM_DECL(ESerialVerifyData, SERIAL, VERIFY_DATA_WRITE)
NCBI_PARAM_DECL(bool, SERIAL, FastWriteDouble)
NCBI_PARAM_ENUM_DEF(ESerialVerifyData, SERIAL, VERIFY_DATA_WRITE, eSerialVerifyData_Default)
#define _TRACE(arg)
Definition: objostr.cpp:72
static CSafeStatic< TFastWriteDouble > s_FastWriteDouble
Definition: objostr.cpp:81
typedef NCBI_PARAM_TYPE(SERIAL, FastWriteDouble) TFastWriteDouble
NCBI_PARAM_ENUM_ARRAY(ESerialVerifyData, SERIAL, VERIFY_DATA_WRITE)
Definition: objostr.cpp:181
NCBI_PARAM_DEF(bool, SERIAL, FastWriteDouble, true)
#define VIRTUAL_MID_LEVEL_IO
Definition: objstack.hpp:35
static pcre_uint8 * buffer
Definition: pcretest.c:1051
#define NcbiSys_setmode
Definition: ncbisys.hpp:47
#define NcbiSys_fileno
Definition: ncbisys.hpp:43
Definition: type.c:6
#define _ASSERT
Modified on Thu May 30 12:27:56 2024 by modify_doxy.py rev. 669887