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

Go to the SVN repository for this file.

1 /* $Id: objistr.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/ncbiutil.hpp>
38 #include <corelib/ncbimtx.hpp>
39 #include <corelib/ncbithr.hpp>
40 #include <corelib/ncbi_param.hpp>
41 
42 #include <exception>
43 
44 #include <util/bytesrc.hpp>
45 
46 #include <serial/objistr.hpp>
47 #include <serial/impl/typeref.hpp>
48 #include <serial/impl/member.hpp>
49 #include <serial/impl/variant.hpp>
51 #include <serial/impl/choice.hpp>
53 #include <serial/impl/continfo.hpp>
54 #include <serial/enumvalues.hpp>
56 #include <serial/delaybuf.hpp>
58 #include <serial/objectinfo.hpp>
59 #include <serial/objectiter.hpp>
60 #include <serial/impl/objlist.hpp>
62 #include <serial/serialimpl.hpp>
63 #include <serial/pack_string.hpp>
64 #include <serial/error_codes.hpp>
65 
66 #include <limits.h>
67 #if HAVE_WINDOWS_H
68 // In MSVC limits.h doesn't define FLT_MIN & FLT_MAX
69 # include <float.h>
70 #endif
71 #if defined(NCBI_OS_MSWIN)
72 # include <corelib/ncbi_os_mswin.hpp>
73 # include <io.h>
74 # include <fcntl.h>
75 #endif
76 
77 #undef _TRACE
78 #define _TRACE(arg) ((void)0)
79 
80 #define NCBI_USE_ERRCODE_X Serial_IStream
81 
83 
84 NCBI_PARAM_DECL(bool, SERIAL, READ_MMAPBYTESOURCE);
85 NCBI_PARAM_DEF_EX(bool, SERIAL, READ_MMAPBYTESOURCE, false,
86  eParam_NoThread, SERIAL_READ_MMAPBYTESOURCE);
87 
89  const string& fileName,
90  TSerialOpenFlags openFlags)
91 {
92  if ( ((openFlags & eSerial_StdWhenEmpty) && fileName.empty()) ||
93  ((openFlags & eSerial_StdWhenDash) && fileName == "-") ||
94  ((openFlags & eSerial_StdWhenStd) && fileName == "stdin") ) {
95 #if defined(NCBI_OS_MSWIN)
96  NcbiSys_setmode(NcbiSys_fileno(stdin), (format == eSerial_AsnBinary) ? O_BINARY : O_TEXT);
97 #endif
99  }
100  else {
101  bool binary;
102  switch ( format ) {
103  case eSerial_AsnText:
104  case eSerial_Xml:
105  case eSerial_Json:
106  binary = false;
107  break;
108  case eSerial_AsnBinary:
109  binary = true;
110  break;
111  default:
113  "CObjectIStream::Open: unsupported format");
114  }
115 
116  if ( (openFlags & eSerial_UseFileForReread) ) {
117  // use file as permanent file
118  return CRef<CByteSource>(new CFileByteSource(fileName, binary));
119  }
120  else {
121  static CSafeStatic<NCBI_PARAM_TYPE(SERIAL, READ_MMAPBYTESOURCE)> s_MmapSrc;
122  if (s_MmapSrc->Get()) {
123  // open file as file mapping
124  return CRef<CByteSource>(new CMMapByteSource(fileName));
125  } else {
126  // open file as stream
127  return CRef<CByteSource>(new CFStreamByteSource(fileName, binary));
128  }
129  }
130  }
131 }
132 
134  bool deleteInStream)
135 {
136  if ( deleteInStream ) {
137  return CRef<CByteSource>(new CFStreamByteSource(inStream));
138  }
139  else {
140  return CRef<CByteSource>(new CStreamByteSource(inStream));
141  }
142 }
143 
145 {
146  switch ( format ) {
147  case eSerial_AsnText:
148  return CreateObjectIStreamAsn();
149  case eSerial_AsnBinary:
151  case eSerial_Xml:
152  return CreateObjectIStreamXml();
153  case eSerial_Json:
154  return CreateObjectIStreamJson();
155  default:
156  break;
157  }
159  "CObjectIStream::Open: unsupported format");
160 }
161 
164 {
166  stream->Open(source);
167  return stream.release();
168 }
169 
171  CByteSourceReader& reader)
172 {
174  stream->Open(reader);
175  return stream.release();
176 }
177 
179  const char* buffer,
180  size_t size)
181 {
183  stream->OpenFromBuffer(buffer, size);
184  return stream.release();
185 }
186 
188  CNcbiIstream& inStream,
189  EOwnership deleteInStream)
190 {
191  CRef<CByteSource> src = GetSource(inStream, deleteInStream == eTakeOwnership);
192  return Create(format, *src);
193 }
194 
196  CNcbiIstream& inStream,
197  bool deleteInStream)
198 {
199  CRef<CByteSource> src = GetSource(inStream, deleteInStream);
200  return Create(format, *src);
201 }
202 
204  const string& fileName,
205  TSerialOpenFlags openFlags)
206 {
207  CRef<CByteSource> src = GetSource(format, fileName, openFlags);
208  return Create(format, *src);
209 }
210 
211 /////////////////////////////////////////////////////////////////////////////
212 // data verification setup
213 
214 
215 NCBI_PARAM_ENUM_ARRAY(ESerialVerifyData, SERIAL, VERIFY_DATA_READ)
216 {
217  {"NO", eSerialVerifyData_No},
218  {"NEVER", eSerialVerifyData_Never},
219  {"YES", eSerialVerifyData_Yes},
220  {"ALWAYS", eSerialVerifyData_Always},
221  {"DEFVALUE", eSerialVerifyData_DefValue},
222  {"DEFVALUE_ALWAYS", eSerialVerifyData_DefValueAlways}
223 };
224 NCBI_PARAM_ENUM_DECL(ESerialVerifyData, SERIAL, VERIFY_DATA_READ);
226 typedef NCBI_PARAM_TYPE(SERIAL, VERIFY_DATA_READ) TSerialVerifyData;
227 
228 
230 {
231  ESerialVerifyData now = TSerialVerifyData::GetThreadDefault();
232  if (now != eSerialVerifyData_Never &&
233  now != eSerialVerifyData_Always &&
236  TSerialVerifyData::ResetThreadDefault();
237  } else {
238  TSerialVerifyData::SetThreadDefault(verify);
239  }
240  }
241 }
242 
244 {
245  ESerialVerifyData now = TSerialVerifyData::GetDefault();
246  if (now != eSerialVerifyData_Never &&
247  now != eSerialVerifyData_Always &&
250  TSerialVerifyData::ResetDefault();
251  } else {
252  TSerialVerifyData::SetDefault(verify);
253  }
254  }
255 }
256 
258 {
259  ESerialVerifyData now = TSerialVerifyData::GetThreadDefault();
260  if (now == eSerialVerifyData_Default) {
261  now = TSerialVerifyData::GetDefault();
262  if (now == eSerialVerifyData_Default) {
263 // this is to provide compatibility with old implementation
264  const char* str = getenv(SERIAL_VERIFY_DATA_READ);
265  if (str) {
266  if (NStr::CompareNocase(str,"YES") == 0) {
267  now = eSerialVerifyData_Yes;
268  } else if (NStr::CompareNocase(str,"NO") == 0) {
269  now = eSerialVerifyData_No;
270  } else if (NStr::CompareNocase(str,"NEVER") == 0) {
272  } else if (NStr::CompareNocase(str,"ALWAYS") == 0) {
274  } else if (NStr::CompareNocase(str,"DEFVALUE") == 0) {
276  } else if (NStr::CompareNocase(str,"DEFVALUE_ALWAYS") == 0) {
278  }
279  }
280  }
281  }
282  if (now != eSerialVerifyData_Default) {
283  return now;
284  }
285  // change the default here, if you like
286  return eSerialVerifyData_Yes;
287 }
288 
289 /////////////////////////////////////////////////////////////////////////////
290 // FixWrongChars setup
291 
292 NCBI_PARAM_ENUM_ARRAY(EFixNonPrint, SERIAL, WRONG_CHARS_READ)
293 {
294  {"SKIP", eFNP_Skip},
295  {"ALLOW", eFNP_Allow},
296  {"REPLACE", eFNP_Replace},
297  {"REPLACE_AND_WARN", eFNP_ReplaceAndWarn},
298  {"THROW", eFNP_Throw},
299  {"ABORT", eFNP_Abort}
300 };
301 NCBI_PARAM_ENUM_DECL(EFixNonPrint, SERIAL, WRONG_CHARS_READ);
303 typedef NCBI_PARAM_TYPE(SERIAL, WRONG_CHARS_READ) TSerialFixChars;
304 
306 {
307  static CSafeStatic<TSerialFixChars> s_SerialFixChars;
308  return s_SerialFixChars->Get();
309 }
310 
313  if (GetStackDepth() > 1 && FetchFrameFromTop(1).HasTypeInfo() &&
314  FetchFrameFromTop(1).GetTypeInfo()->GetDataSpec() != EDataSpec::eASN) {
315  return eFNP_Allow;
316  }
317  }
318  return m_FixMethod;
319 }
320 
321 /////////////////////////////////////////////////////////////////////////////
322 // skip unknown members setup
323 
324 // same as ESerialSkipUnknown
325 // maybe, with some tweaks in NCBI_PARAM, it will not be needed later...
332 };
333 
334 NCBI_PARAM_ENUM_ARRAY(ESerialSkipUnknownMembers, SERIAL, SKIP_UNKNOWN_MEMBERS)
335 {
336  {"NO", eSerialSkipUnknownM_No},
337  {"NEVER", eSerialSkipUnknownM_Never},
338  {"YES", eSerialSkipUnknownM_Yes},
339  {"ALWAYS", eSerialSkipUnknownM_Always}
340 };
341 NCBI_PARAM_ENUM_DECL(ESerialSkipUnknownMembers, SERIAL, SKIP_UNKNOWN_MEMBERS);
343 typedef NCBI_PARAM_TYPE(SERIAL, SKIP_UNKNOWN_MEMBERS) TSkipUnknownMembersDefault;
344 
346 {
347  ESerialSkipUnknown now = (ESerialSkipUnknown)TSkipUnknownMembersDefault::GetThreadDefault();
348  if (now != eSerialSkipUnknown_Never &&
349  now != eSerialSkipUnknown_Always) {
350  if (skip == eSerialSkipUnknown_Default) {
351  TSkipUnknownMembersDefault::ResetThreadDefault();
352  } else {
353  TSkipUnknownMembersDefault::SetThreadDefault((ESerialSkipUnknownMembers)skip);
354  }
355  }
356 }
357 
359 {
360  ESerialSkipUnknown now = (ESerialSkipUnknown)TSkipUnknownMembersDefault::GetDefault();
361  if (now != eSerialSkipUnknown_Never &&
362  now != eSerialSkipUnknown_Always) {
363  if (skip == eSerialSkipUnknown_Default) {
364  TSkipUnknownMembersDefault::ResetDefault();
365  } else {
366  TSkipUnknownMembersDefault::SetDefault((ESerialSkipUnknownMembers)skip);
367  }
368  }
369 }
370 
372 {
373  ESerialSkipUnknown now = (ESerialSkipUnknown)TSkipUnknownMembersDefault::GetThreadDefault();
374  if (now == eSerialSkipUnknown_Default) {
375  now = (ESerialSkipUnknown)TSkipUnknownMembersDefault::GetDefault();
376  }
377  return now;
378 }
379 
380 
381 NCBI_PARAM_ENUM_ARRAY(ESerialSkipUnknown, SERIAL, SKIP_UNKNOWN_VARIANTS)
382 {
383  {"NO", eSerialSkipUnknown_No},
384  {"NEVER", eSerialSkipUnknown_Never},
385  {"YES", eSerialSkipUnknown_Yes},
386  {"ALWAYS", eSerialSkipUnknown_Always}
387 };
388 NCBI_PARAM_ENUM_DECL(ESerialSkipUnknown, SERIAL, SKIP_UNKNOWN_VARIANTS);
390 typedef NCBI_PARAM_TYPE(SERIAL, SKIP_UNKNOWN_VARIANTS) TSkipUnknownVariantsDefault;
391 
393 {
394  ESerialSkipUnknown now = TSkipUnknownVariantsDefault::GetThreadDefault();
395  if (now != eSerialSkipUnknown_Never &&
396  now != eSerialSkipUnknown_Always) {
397  if (skip == eSerialSkipUnknown_Default) {
398  TSkipUnknownVariantsDefault::ResetThreadDefault();
399  } else {
400  TSkipUnknownVariantsDefault::SetThreadDefault(skip);
401  }
402  }
403 }
404 
406 {
407  ESerialSkipUnknown now = TSkipUnknownVariantsDefault::GetDefault();
408  if (now != eSerialSkipUnknown_Never &&
409  now != eSerialSkipUnknown_Always) {
410  if (skip == eSerialSkipUnknown_Default) {
411  TSkipUnknownVariantsDefault::ResetDefault();
412  } else {
413  TSkipUnknownVariantsDefault::SetDefault(skip);
414  }
415  }
416 }
417 
419 {
420  ESerialSkipUnknown now = TSkipUnknownVariantsDefault::GetThreadDefault();
421  if (now == eSerialSkipUnknown_Default) {
422  now = TSkipUnknownVariantsDefault::GetDefault();
423  }
424  return now;
425 }
426 
427 
429 {
431  if ( skip == eSerialSkipUnknown_Default ) {
432  skip = x_GetSkipUnknownDefault();
433  if ( skip == eSerialSkipUnknown_Default ) {
434  skip = eSerialSkipUnknown_No;
435  }
436  m_SkipUnknown = skip;
437  }
438  return skip;
439 }
440 
441 
443 {
445  if ( skip == eSerialSkipUnknown_Default ) {
447  if ( skip == eSerialSkipUnknown_Default ) {
448  skip = eSerialSkipUnknown_No;
449  }
450  m_SkipUnknownVariants = skip;
451  }
452  return skip;
453 }
454 
455 
456 /////////////////////////////////////////////////////////////////////////////
457 
459  : m_DiscardCurrObject(false),
460  m_DataFormat(format),
461  m_ParseDelayBuffers(eDelayBufferPolicyNotSet),
462  m_TypeAlias(nullptr),
463  m_NonPrintSubst('#'),
464  m_FixMethod(x_GetFixCharsMethodDefault()),
465  m_VerifyData(x_GetVerifyDataDefault()),
466  m_SkipUnknown(eSerialSkipUnknown_Default),
467  m_SkipUnknownVariants(eSerialSkipUnknown_Default),
468  m_Fail(fNotOpen),
469  m_Flags(fFlagNone),
470  m_MonitorType(0),
471  m_MemberDefault(0), m_SpecialCaseToExpect(0), m_SpecialCaseUsed(eReadAsNormal)
472 {
473 }
474 
476 {
477  try {
478  Close();
479  ResetLocalHooks();
480  }
481  catch (...) {
482  ERR_POST_X(1, "Cannot close input stream");
483  }
484 }
485 
487 {
489  m_DiscardCurrObject = false;
491 }
492 
494 {
495  Close();
496  _ASSERT(m_Fail == fNotOpen);
497  m_Input.Open(reader);
498  m_Fail = 0;
499 }
500 
501 void CObjectIStream::OpenFromBuffer(const char* buffer, size_t size)
502 {
503  Close();
504  _ASSERT(m_Fail == fNotOpen);
506  m_Fail = 0;
507 }
508 
510 {
511  CRef<CByteSourceReader> reader = source.Open();
512  Open(*reader);
513 }
514 
515 void CObjectIStream::Open(CNcbiIstream& inStream, bool deleteInStream)
516 {
517  CRef<CByteSource> src = GetSource(inStream, deleteInStream);
518  Open(*src);
519 }
520 
521 void CObjectIStream::Open(CNcbiIstream& inStream, EOwnership deleteInStream)
522 {
523  CRef<CByteSource> src = GetSource(inStream, deleteInStream == eTakeOwnership);
524  Open(*src);
525 }
526 
528 {
530  ResetPathHooks();
537 }
538 
540 {
541  if (m_Fail != fNotOpen) {
542  m_Input.Close();
543  if ( m_Objects )
544  m_Objects->Clear();
545  ClearStack();
546  m_Fail = fNotOpen;
547  ResetState();
548  }
549 }
550 
553  const char* /* message */)
554 {
555  TFailFlags old = m_Fail;
556  if (flags == fNoError) {
557  m_Fail = flags;
558  } else {
559  m_Fail |= flags;
560  if ( !old && flags ) {
561  // first fail
562 // redundant
563 // ERR_POST_X(2, Error << "CObjectIStream: error at "<<
564 // GetPosition()<<": "<<GetStackTrace() << ": " << message);
565  }
566  }
567  return old;
568 }
569 
571 {
572  if ( fail() ) {
573  // fail flag already set
574  return false;
575  }
576  else if ( m_Input.fail() ) {
577  // IO exception thrown without setting fail flag
579  m_Input.ResetFail();
580  return false;
581  }
582  else {
583  // ok
584  return true;
585  }
586 }
587 
589 {
590  const TFailFlags failure =
593  if (GetFailFlags() & failure || m_Input.EndOfData()) {
594  return true;
595  }
596  return !m_Input.HasMore();
597 }
598 
600 {
601  string msg(TopFrame().GetFrameInfo());
602  PopFrame();
603  if (GetStackDepth() < 2) {
604  NCBI_RETHROW_SAME(expt,msg);
605  } else {
606  ThrowError(fEOF, msg);
607  }
608 }
609 
610 void CObjectIStream::Unended(const string& msg)
611 {
612  if ( InGoodState() )
613  ThrowError(fFail, msg);
614 }
615 
617 {
618  Unended("internal error: unended object stack frame");
619 }
620 
622 {
624 }
625 
627 {
628  if (find(m_ReqMonitorType.begin(), m_ReqMonitorType.end(), type) ==
629  m_ReqMonitorType.end()) {
630  m_ReqMonitorType.push_back(type);
631  }
632 }
633 
635 {
636  m_ReqMonitorType.clear();
637  m_MonitorType = 0;
638 }
639 
641 {
644  if (hook) {
646  if (item) {
647  item->SetPathReadHook(this, GetStackPath(), set ? hook : NULL);
648  }
649  }
650  }
653  if (hook) {
655  if (item) {
656  item->SetPathSkipHook(this, GetStackPath(), set ? hook : NULL);
657  }
658  }
659  }
662  if (hook) {
664  if (item) {
665  item->SetPathReadHook(this, GetStackPath(), set ? hook : NULL);
666  }
667  }
668  }
671  if (hook) {
673  if (item) {
674  item->SetPathSkipHook(this, GetStackPath(), set ? hook : NULL);
675  }
676  }
677  }
680  if (hook) {
682  if (item) {
683  item->SetPathReadHook(this, GetStackPath(), set ? hook : NULL);
684  }
685  }
686  }
689  if (hook) {
691  if (item) {
692  item->SetPathSkipHook(this, GetStackPath(), set ? hook : NULL);
693  }
694  }
695  }
696 }
697 
699  CReadObjectHook* hook)
700 {
701  m_PathReadObjectHooks.SetHook(path,hook);
702  WatchPathHooks();
703 }
705  CSkipObjectHook* hook)
706 {
707  m_PathSkipObjectHooks.SetHook(path,hook);
708  WatchPathHooks();
709 }
711  CReadClassMemberHook* hook)
712 {
713  m_PathReadMemberHooks.SetHook(path,hook);
714  WatchPathHooks();
715 }
717  CSkipClassMemberHook* hook)
718 {
719  m_PathSkipMemberHooks.SetHook(path,hook);
720  WatchPathHooks();
721 }
724 {
725  m_PathReadVariantHooks.SetHook(path,hook);
726  WatchPathHooks();
727 }
730 {
731  m_PathSkipVariantHooks.SetHook(path,hook);
732  WatchPathHooks();
733 }
734 
736 {
737  m_ParseDelayBuffers = policy;
738 }
741 {
742  return m_ParseDelayBuffers;
743 }
744 
746 {
749  }
750  return
763 }
764 
766 {
767  return (!m_PathReadObjectHooks.IsEmpty() ||
773 }
774 
776 {
778 }
779 
781 {
782  return GetStackTraceASN();
783 }
784 
786 {
787  return m_Input.GetStreamPos();
788 }
789 
791 {
792  return m_Input.GetStreamPos();
793 }
794 
796 {
797  m_Input.SetStreamPos(pos);
798 }
799 
801 {
803  ResetState();
804  m_Input.SetStreamPos(pos);
805 }
806 
807 string CObjectIStream::GetPosition(void) const
808 {
809  string loc_type;
810  size_t loc_pos;
811  Location(loc_type, loc_pos);
812  return loc_type+" "+NStr::Int8ToString(NcbiStreamposToInt8(loc_pos));
813 }
814 
815 void CObjectIStream::Location(string& loc_type, size_t& loc) const
816 {
817  loc_type = "byte";
819 }
820 
821 
823  TFailFlags flags, const char* message)
824 {
825  ThrowError1(diag_info, flags, string(message));
826 }
827 
829  TFailFlags flags, const string& message)
830 {
832  SetFailFlags(flags, message.c_str());
833  switch (flags)
834  {
835  case fNoError:
836  CNcbiDiag(diag_info, eDiag_Trace) << ErrCode(NCBI_ERRCODE_X, 6)
837  << message;
838  return;
839  case fEOF: err = CSerialException::eEOF; break;
840  default:
841  case fReadError: err = CSerialException::eIoError; break;
842  case fFormatError: err = CSerialException::eFormatError; break;
843  case fOverflow: err = CSerialException::eOverflow; break;
844  case fInvalidData: err = CSerialException::eInvalidData; break;
845  case fIllegalCall: err = CSerialException::eIllegalCall; break;
846  case fFail: err = CSerialException::eFail; break;
847  case fNotOpen: err = CSerialException::eNotOpen; break;
850  case fNullValue: err = CSerialException::eNullValue; break;
851  }
852  throw CSerialException(diag_info,0,err,GetPosition()+": "+message);
853 }
854 
855 static inline
856 TTypeInfo MapType(const string& name)
857 {
859 }
860 
862 {
863  if ( m_Objects )
864  m_Objects->RegisterObject(typeInfo);
865 }
866 
868 {
869  if ( m_Objects )
870  m_Objects->RegisterObject(objectPtr, typeInfo);
871 }
872 
873 const CReadObjectInfo&
875 {
876  if ( !m_Objects ) {
877  ThrowError(fFormatError,"invalid object index: NO_COLLECT defined");
878  }
879  return m_Objects->GetRegisteredObject(index);
880 }
881 
882 // root reader
884 {
885  ResetState();
886  if (!m_MonitorType) {
887  m_MonitorType = (!x_HavePathHooks() && m_ReqMonitorType.size()==1) ?
888  m_ReqMonitorType.front() : 0;
889  }
890 
891  BEGIN_OBJECT_FRAME2(eFrameNamed, typeInfo);
892 
893  string name = ReadFileHeader();
894  const string& tname = typeInfo->GetName();
895  if ( !name.empty() && !tname.empty() && name != tname ) {
897  "incompatible type "+name+"<>"+typeInfo->GetName());
898  }
899 
901 }
902 
904 {
905  ResetState();
906  m_MonitorType = 0;
907  if ( m_Objects )
908  m_Objects->Clear();
909 }
910 
912  size_t /*max_length*/,
913  size_t max_bytes)
914 {
915  set<TTypeInfo> matching_types;
916  string name;
917 
918  // save state
919  size_t pos0 = m_Input.SetBufferLock(max_bytes);
920 
921  try {
922  name = ReadFileHeader();
923  }
924  catch ( ... ) {
925  // restore state
926  m_Input.ResetBufferLock(pos0);
927  throw;
928  }
929  // restore state
930  m_Input.ResetBufferLock(pos0);
931 
932  ITERATE( set<TTypeInfo>, t, known_types) {
933  if ((*t)->GetName() == name) {
934  matching_types.insert(*t);
935  }
936  }
937  return matching_types;
938 }
939 
941 {
942  // root object
943  BEGIN_OBJECT_FRAME2(eFrameNamed, object.GetTypeInfo());
944 
945  ReadObject(object);
946 
947  EndOfRead();
948 
950 }
951 
953 {
954  // root object
955  SkipFileHeader(object.GetTypeInfo());
956  Read(object, eNoFileHeader);
957 }
958 
960 {
961  // root object
962  BEGIN_OBJECT_FRAME2(eFrameNamed, typeInfo);
963 
964  ReadObject(object, typeInfo);
965 
966  EndOfRead();
967 
969 }
970 
972 {
973  // root object
974  SkipFileHeader(typeInfo);
975  Read(object, typeInfo, eNoFileHeader);
976 }
977 
979 {
980  // root object
981  SkipFileHeader(typeInfo);
982  CObjectInfo info(typeInfo->Create(), typeInfo);
984  return info;
985 }
986 
988 {
989  return Read(type.GetTypeInfo());
990 }
991 
993 {
994  BEGIN_OBJECT_FRAME2(eFrameNamed, typeInfo);
995 
996  SkipObject(typeInfo);
997 
998  EndOfRead();
999 
1000  END_OBJECT_FRAME();
1001 }
1002 
1004 {
1005  SkipFileHeader(typeInfo);
1006  Skip(typeInfo, eNoFileHeader);
1007 }
1008 
1010 {
1011  Skip(type.GetTypeInfo());
1012 }
1013 
1015 {
1017 }
1018 
1020 {
1021  return m_Input.EndSubSource();
1022 }
1023 
1025  const CItemInfo* itemInfo,
1026  TObjectPtr objectPtr)
1027 {
1029  buffer.SetData(itemInfo, objectPtr, GetDataFormat(), GetFlags(), *src);
1030 }
1031 
1033 {
1034  const CItemInfo* info = CItemsInfo::FindNextMandatory(memberInfo);
1035  if (info) {
1038  "member "+info->GetId().ToString()+" expected");
1039  } else {
1041  ERR_POST_X(3, "member "+info->GetId().ToString()+" is missing");
1042  }
1043  }
1044  return (info != 0);
1045 }
1046 
1048 {
1050  "duplicate member: "+memberInfo->GetId().ToString());
1051 }
1052 
1054 {
1055  if ( m_Objects ) {
1056  size_t firstObject = m_Objects->GetObjectCount();
1057  ReadObject(object);
1058  size_t lastObject = m_Objects->GetObjectCount();
1059  m_Objects->ForgetObjects(firstObject, lastObject);
1060  }
1061  else {
1062  ReadObject(object);
1063  }
1064 }
1065 
1067  TTypeInfo typeInfo)
1068 {
1069  _TRACE("CObjectIStream::Read("<<NStr::PtrToString(objectPtr)<<", "<<
1070  typeInfo->GetName()<<")");
1071  RegisterObject(objectPtr, typeInfo);
1072  ReadObject(objectPtr, typeInfo);
1073 }
1074 
1076 {
1077  TTypeInfo typeInfo = MapType(ReadFileHeader());
1078  TObjectPtr objectPtr = 0;
1079  BEGIN_OBJECT_FRAME2(eFrameNamed, typeInfo);
1080 
1081  CRef<CObject> ref;
1082  if ( typeInfo->IsCObject() ) {
1083  objectPtr = typeInfo->Create(GetMemoryPool());
1084  ref.Reset(static_cast<CObject*>(objectPtr));
1085  }
1086  else {
1087  objectPtr = typeInfo->Create();
1088  }
1089  RegisterObject(objectPtr, typeInfo);
1090  ReadObject(objectPtr, typeInfo);
1091  if ( typeInfo->IsCObject() )
1092  ref.Release();
1093  END_OBJECT_FRAME();
1094  return make_pair(objectPtr, typeInfo);
1095 }
1096 
1098 {
1099  ReadObject(object.GetObjectPtr(), object.GetTypeInfo());
1100 }
1101 
1103 {
1104  SkipObject(objectType.GetTypeInfo());
1105 }
1106 
1108 {
1109  const CMemberInfo* memberInfo = member.GetMemberInfo();
1110  TObjectPtr classPtr = member.GetClassObject().GetObjectPtr();
1111  memberInfo->DefaultReadMember(*this, classPtr);
1112 }
1113 
1115 {
1116  const CVariantInfo* variantInfo = object.GetVariantInfo();
1117  TObjectPtr choicePtr = object.GetChoiceObject().GetObjectPtr();
1118  variantInfo->DefaultReadVariant(*this, choicePtr);
1119 }
1120 
1122 {
1123  // this is to check if the file is empty or not
1124  m_Input.PeekChar();
1125  return NcbiEmptyString;
1126 }
1127 
1129 {
1130  return NcbiEmptyString;
1131 }
1132 
1133 pair<TObjectPtr, TTypeInfo> CObjectIStream::ReadPointer(TTypeInfo declaredType)
1134 {
1135  _TRACE("CObjectIStream::ReadPointer("<<declaredType->GetName()<<")");
1136  TObjectPtr objectPtr = 0;
1137  TTypeInfo objectType = 0;
1138  switch ( ReadPointerType() ) {
1139  case eNullPointer:
1140  _TRACE("CObjectIStream::ReadPointer: null");
1141  return pair<TObjectPtr, TTypeInfo>((TObjectPtr)0, declaredType);
1142  case eObjectPointer:
1143  {
1144  _TRACE("CObjectIStream::ReadPointer: @...");
1145  TObjectIndex index = ReadObjectPointer();
1146  _TRACE("CObjectIStream::ReadPointer: @" << index);
1147  const CReadObjectInfo& info = GetRegisteredObject(index);
1148  objectType = info.GetTypeInfo();
1149  objectPtr = info.GetObjectPtr();
1150  if ( !objectPtr ) {
1152  "invalid reference to skipped object: object ptr is NULL");
1153  }
1154  break;
1155  }
1156  case eThisPointer:
1157  {
1158  _TRACE("CObjectIStream::ReadPointer: new");
1159  CRef<CObject> ref;
1160  if ( declaredType->IsCObject() ) {
1161  objectPtr = declaredType->Create(GetMemoryPool());
1162  ref.Reset(static_cast<CObject*>(objectPtr));
1163  }
1164  else {
1165  objectPtr = declaredType->Create();
1166  }
1167  RegisterObject(objectPtr, declaredType);
1168  ReadObject(objectPtr, declaredType);
1169  if ( declaredType->IsCObject() )
1170  ref.Release();
1171  return make_pair(objectPtr, declaredType);
1172  }
1173  case eOtherPointer:
1174  {
1175  _TRACE("CObjectIStream::ReadPointer: new...");
1176  string className = ReadOtherPointer();
1177  _TRACE("CObjectIStream::ReadPointer: new " << className);
1178  objectType = MapType(className);
1179 
1180  BEGIN_OBJECT_FRAME2(eFrameNamed, objectType);
1181 
1182  CRef<CObject> ref;
1183  if ( objectType->IsCObject() ) {
1184  objectPtr = objectType->Create(GetMemoryPool());
1185  ref.Reset(static_cast<CObject*>(objectPtr));
1186  }
1187  else {
1188  objectPtr = objectType->Create();
1189  }
1190  RegisterObject(objectPtr, objectType);
1191  ReadObject(objectPtr, objectType);
1192  if ( objectType->IsCObject() )
1193  ref.Release();
1194 
1195  END_OBJECT_FRAME();
1196 
1198  break;
1199  }
1200  default:
1201  ThrowError(fFormatError,"illegal pointer type");
1202  objectPtr = 0;
1203  objectType = 0;
1204  break;
1205  }
1206  while ( objectType != declaredType ) {
1207  // try to check parent class pointer
1208  if ( objectType->GetTypeFamily() != eTypeFamilyClass ) {
1209  ThrowError(fFormatError,"incompatible member type");
1210  }
1211  const CClassTypeInfo* parentClass =
1212  CTypeConverter<CClassTypeInfo>::SafeCast(objectType)->GetParentClassInfo();
1213  if ( parentClass ) {
1214  objectType = parentClass;
1215  }
1216  else {
1217  ThrowError(fFormatError,"incompatible member type");
1218  }
1219  }
1220  return make_pair(objectPtr, objectType);
1221 }
1222 
1224 {
1225 }
1226 
1228 {
1229  _TRACE("CObjectIStream::SkipExternalObject("<<typeInfo->GetName()<<")");
1230  RegisterObject(typeInfo);
1231  SkipObject(typeInfo);
1232 }
1233 
1235 {
1236  _TRACE("CObjectIStream::SkipPointer("<<declaredType->GetName()<<")");
1237  switch ( ReadPointerType() ) {
1238  case eNullPointer:
1239  _TRACE("CObjectIStream::SkipPointer: null");
1240  return;
1241  case eObjectPointer:
1242  {
1243  _TRACE("CObjectIStream::SkipPointer: @...");
1244  TObjectIndex index = ReadObjectPointer();
1245  _TRACE("CObjectIStream::SkipPointer: @" << index);
1246  GetRegisteredObject(index);
1247  break;
1248  }
1249  case eThisPointer:
1250  {
1251  _TRACE("CObjectIStream::ReadPointer: new");
1252  RegisterObject(declaredType);
1253  SkipObject(declaredType);
1254  break;
1255  }
1256  case eOtherPointer:
1257  {
1258  _TRACE("CObjectIStream::ReadPointer: new...");
1259  string className = ReadOtherPointer();
1260  _TRACE("CObjectIStream::ReadPointer: new " << className);
1261  TTypeInfo typeInfo = MapType(className);
1262  BEGIN_OBJECT_FRAME2(eFrameNamed, typeInfo);
1263 
1264  RegisterObject(typeInfo);
1265  SkipObject(typeInfo);
1266 
1267  END_OBJECT_FRAME();
1269  break;
1270  }
1271  default:
1272  ThrowError(fFormatError,"illegal pointer type");
1273  }
1274 }
1275 
1277 {
1278 }
1279 
1281 {
1282 }
1283 
1285 #ifndef VIRTUAL_MID_LEVEL_IO
1286  namedTypeInfo
1287 #endif
1288  ,
1289  TTypeInfo typeInfo, TObjectPtr object)
1290 {
1291 #ifndef VIRTUAL_MID_LEVEL_IO
1292  BEGIN_OBJECT_FRAME2(eFrameNamed, namedTypeInfo);
1293  BeginNamedType(namedTypeInfo);
1294 #endif
1295  ReadObject(object, typeInfo);
1296 #ifndef VIRTUAL_MID_LEVEL_IO
1297  EndNamedType();
1298  END_OBJECT_FRAME();
1299 #endif
1300 }
1301 
1303  TTypeInfo typeInfo)
1304 {
1305  BEGIN_OBJECT_FRAME2(eFrameNamed, namedTypeInfo);
1306  BeginNamedType(namedTypeInfo);
1307 
1308  SkipObject(typeInfo);
1309 
1310  EndNamedType();
1311  END_OBJECT_FRAME();
1312 }
1313 
1315 {
1316 }
1317 
1319  TObjectPtr containerPtr)
1320 {
1321  BEGIN_OBJECT_FRAME2(eFrameArray, containerType);
1322  BeginContainer(containerType);
1323 
1324  TTypeInfo elementType = containerType->GetElementType();
1325  BEGIN_OBJECT_FRAME2(eFrameArrayElement, elementType);
1326 
1328  bool old_element = containerType->InitIterator(iter, containerPtr);
1329  while ( BeginContainerElement(elementType) ) {
1330  if ( old_element ) {
1331  elementType->ReadData(*this, containerType->GetElementPtr(iter));
1332  old_element = containerType->NextElement(iter);
1333  }
1334  else {
1335  containerType->AddElement(containerPtr, *this);
1336  }
1338  }
1339  if ( old_element ) {
1340  containerType->EraseAllElements(iter);
1341  }
1342 
1343  END_OBJECT_FRAME();
1344 
1345  EndContainer();
1346  END_OBJECT_FRAME();
1347 }
1348 
1350 {
1351  BEGIN_OBJECT_FRAME2(eFrameArray, containerType);
1352  BeginContainer(containerType);
1353 
1354  TTypeInfo elementType = containerType->GetElementType();
1355  BEGIN_OBJECT_FRAME2(eFrameArrayElement, elementType);
1356 
1357  while ( BeginContainerElement(elementType) ) {
1358  SkipObject(elementType);
1360  }
1361 
1362  END_OBJECT_FRAME();
1363 
1364  EndContainer();
1365  END_OBJECT_FRAME();
1366 }
1367 
1369 {
1370 }
1371 
1373 {
1374 }
1375 
1377  TObjectPtr classPtr)
1378 {
1379  BEGIN_OBJECT_FRAME3(eFrameClass, classType, classPtr);
1380  BeginClass(classType);
1381 
1382  ReadClassRandomContentsBegin(classType);
1383 
1384  TMemberIndex index;
1385  while ( (index = BeginClassMember(classType)) != kInvalidMember ) {
1386 
1388 
1389  EndClassMember();
1390  }
1391 
1393 
1394  EndClass();
1395  END_OBJECT_FRAME();
1396 }
1397 
1399  TObjectPtr classPtr)
1400 {
1401  TMemberIndex prevIndex = kInvalidMember;
1402  BEGIN_OBJECT_FRAME3(eFrameClass, classType, classPtr);
1403  BeginClass(classType);
1404 
1406 
1407  TMemberIndex index;
1408  while ( (index = BeginClassMember(classType, *pos)) != kInvalidMember ) {
1409 
1410  if ((prevIndex != kInvalidMember) && (prevIndex >= index)) {
1411  const CMemberInfo *mem_info = classType->GetMemberInfo(index);
1412  if (mem_info->GetId().HaveNoPrefix()) {
1413  UndoClassMember();
1414  break;
1415  }
1416  }
1417  prevIndex = index;
1418 
1420 
1421  EndClassMember();
1422  }
1423 
1425 
1426  EndClass();
1427  END_OBJECT_FRAME();
1428 }
1429 
1431 {
1432  BEGIN_OBJECT_FRAME2(eFrameClass, classType);
1433  BeginClass(classType);
1434 
1435  SkipClassRandomContentsBegin(classType);
1436 
1437  TMemberIndex index;
1438  while ( (index = BeginClassMember(classType)) != kInvalidMember ) {
1439 
1441 
1442  EndClassMember();
1443  }
1444 
1446 
1447  EndClass();
1448  END_OBJECT_FRAME();
1449 }
1450 
1452 {
1453  BEGIN_OBJECT_FRAME2(eFrameClass, classType);
1454  BeginClass(classType);
1455 
1457 
1458  TMemberIndex index;
1459  while ( (index = BeginClassMember(classType, *pos)) != kInvalidMember ) {
1460 
1462 
1463  EndClassMember();
1464  }
1465 
1467 
1468  EndClass();
1469  END_OBJECT_FRAME();
1470 }
1471 
1473 {
1474 }
1476 {
1477 }
1479 {
1480 }
1481 
1483  TObjectPtr choicePtr)
1484 {
1485  BEGIN_OBJECT_FRAME3(eFrameChoice, choiceType, choicePtr);
1486  BeginChoice(choiceType);
1487  BEGIN_OBJECT_FRAME(eFrameChoiceVariant);
1488  TMemberIndex index = BeginChoiceVariant(choiceType);
1489  if ( index == kInvalidMember ) {
1490  ThrowError(fFormatError,"choice variant id expected");
1491  }
1492  const CVariantInfo* variantInfo = choiceType->GetVariantInfo(index);
1493  SetTopMemberId(variantInfo->GetId());
1494 
1495  variantInfo->ReadVariant(*this, choicePtr);
1496 
1497  EndChoiceVariant();
1498  END_OBJECT_FRAME();
1499  EndChoice();
1500  END_OBJECT_FRAME();
1501 }
1502 
1504 {
1505  BEGIN_OBJECT_FRAME2(eFrameChoice, choiceType);
1506  BeginChoice(choiceType);
1507  BEGIN_OBJECT_FRAME(eFrameChoiceVariant);
1508  TMemberIndex index = BeginChoiceVariant(choiceType);
1509  if ( index == kInvalidMember ) {
1510  ThrowError(fFormatError,"choice variant id expected");
1511  }
1512 
1513  const CVariantInfo* variantInfo = choiceType->GetVariantInfo(index);
1514  SetTopMemberId(variantInfo->GetId());
1515 
1516  variantInfo->SkipVariant(*this);
1517 
1518  EndChoiceVariant();
1519  END_OBJECT_FRAME();
1520  EndChoice();
1521  END_OBJECT_FRAME();
1522 }
1523 
1525  TObjectPtr aliasPtr)
1526 {
1527  if (aliasType->IsFullAlias()) {
1528  m_TypeAlias = aliasType;
1529  }
1530  ReadNamedType(aliasType, aliasType->GetPointedType(),
1531  aliasType->GetDataPtr(aliasPtr));
1532  m_TypeAlias = nullptr;
1533 }
1534 
1536 {
1537  if (aliasType->IsFullAlias()) {
1538  m_TypeAlias = aliasType;
1539  }
1540  SkipNamedType(aliasType, aliasType->GetPointedType());
1541  m_TypeAlias = nullptr;
1542 }
1543 
1544 ///////////////////////////////////////////////////////////////////////
1545 //
1546 // CObjectIStream::ByteBlock
1547 //
1548 
1550  : m_Stream(in), m_KnownLength(false), m_Ended(false), m_Length(1)
1551 {
1552  in.BeginBytes(*this);
1553 }
1554 
1556 {
1557  if ( !m_Ended ) {
1558  try {
1559  GetStream().Unended("byte block not fully read");
1560  }
1561  catch (...) {
1562  ERR_POST_X(4, "unended byte block");
1563  }
1564  }
1565 }
1566 
1568 {
1569  _ASSERT(!m_Ended);
1570  if ( m_Length == 0 ) {
1571  GetStream().EndBytes(*this);
1572  m_Ended = true;
1573  }
1574 }
1575 
1576 size_t CObjectIStream::ByteBlock::Read(void* dst, size_t needLength,
1577  bool forceLength)
1578 {
1579  size_t length;
1580  if ( KnownLength() ) {
1581  if ( m_Length < needLength )
1582  length = m_Length;
1583  else
1584  length = needLength;
1585  }
1586  else {
1587  if ( m_Length == 0 )
1588  length = 0;
1589  else
1590  length = needLength;
1591  }
1592 
1593  if ( length == 0 ) {
1594  if ( forceLength && needLength != 0 )
1595  GetStream().ThrowError(fReadError, "read fault");
1596  return 0;
1597  }
1598 
1599  length = GetStream().ReadBytes(*this, static_cast<char*>(dst), length);
1600  if ( KnownLength() )
1601  m_Length -= length;
1602  if ( forceLength && needLength != length )
1603  GetStream().ThrowError(fReadError, "read fault");
1604  return length;
1605 }
1606 
1607 ///////////////////////////////////////////////////////////////////////
1608 //
1609 // CObjectIStream::CharBlock
1610 //
1611 
1613  : m_Stream(in), m_KnownLength(false), m_Ended(false), m_Length(1)
1614 {
1615  in.BeginChars(*this);
1616 }
1617 
1619 {
1620  if ( !m_Ended ) {
1621  try {
1622  GetStream().Unended("char block not fully read");
1623  }
1624  catch (...) {
1625  ERR_POST_X(5, "unended char block");
1626  }
1627  }
1628 }
1629 
1631 {
1632  _ASSERT(!m_Ended);
1633  if ( m_Length == 0 ) {
1634  GetStream().EndChars(*this);
1635  m_Ended = true;
1636  }
1637 }
1638 
1639 size_t CObjectIStream::CharBlock::Read(char* dst, size_t needLength,
1640  bool forceLength)
1641 {
1642  size_t length;
1643  if ( KnownLength() ) {
1644  if ( m_Length < needLength )
1645  length = m_Length;
1646  else
1647  length = needLength;
1648  }
1649  else {
1650  if ( m_Length == 0 )
1651  length = 0;
1652  else
1653  length = needLength;
1654  }
1655 
1656  if ( length == 0 ) {
1657  if ( forceLength && needLength != 0 )
1658  GetStream().ThrowError(fReadError, "read fault");
1659  return 0;
1660  }
1661 
1662  length = GetStream().ReadChars(*this, dst, length);
1663  if ( KnownLength() )
1664  m_Length -= length;
1665  if ( forceLength && needLength != length )
1666  GetStream().ThrowError(fReadError, "read fault");
1667  return length;
1668 }
1669 
1670 
1672 {
1673 }
1674 
1676 {
1677 }
1678 
1680 {
1681  Int4 data = ReadInt4();
1682  Int1 ret = Int1(data);
1683  if ( ret != data )
1684  ThrowError(fOverflow, "integer overflow");
1685  return ret;
1686 }
1687 
1689 {
1690  Uint4 data = ReadUint4();
1691  Uint1 ret = Uint1(data);
1692  if ( ret != data )
1693  ThrowError(fOverflow, "integer overflow");
1694  return ret;
1695 }
1696 
1698 {
1699  Int4 data = ReadInt4();
1700  Int2 ret = Int2(data);
1701  if ( ret != data )
1702  ThrowError(fOverflow, "integer overflow");
1703  return ret;
1704 }
1705 
1707 {
1708  Uint4 data = ReadUint4();
1709  Uint2 ret = Uint2(data);
1710  if ( ret != data )
1711  ThrowError(fOverflow, "integer overflow");
1712  return ret;
1713 }
1714 
1716 {
1717  Int8 data = ReadInt8();
1718  Int4 ret = Int4(data);
1719  if ( ret != data )
1720  ThrowError(fOverflow, "integer overflow");
1721  return ret;
1722 }
1723 
1725 {
1726  Uint8 data = ReadUint8();
1727  Uint4 ret = Uint4(data);
1728  if ( ret != data )
1729  ThrowError(fOverflow, "integer overflow");
1730  return ret;
1731 }
1732 
1734 {
1735  double data = ReadDouble();
1736 #if defined(FLT_MIN) && defined(FLT_MAX)
1737  if ( data < FLT_MIN || data > FLT_MAX )
1738  ThrowError(fOverflow, "float overflow");
1739 #endif
1740  return float(data);
1741 }
1742 
1743 #if SIZEOF_LONG_DOUBLE != 0
1744 long double CObjectIStream::ReadLDouble(void)
1745 {
1746  return ReadDouble();
1747 }
1748 #endif
1749 
1751 {
1752  string s;
1753  ReadString(s);
1754  return NcbiSysChar_strdup(s.c_str());
1755 }
1756 
1758 {
1759  ReadString(s);
1760 }
1761 
1763  CPackString& pack_string,
1764  EStringType type)
1765 {
1766  ReadString(s, type);
1767  pack_string.Pack(s);
1768 }
1769 
1771 {
1772  SkipSNumber();
1773 }
1774 
1776 {
1777  SkipUNumber();
1778 }
1779 
1781 {
1782  SkipSNumber();
1783 }
1784 
1786 {
1787  SkipUNumber();
1788 }
1789 
1791 {
1792  SkipSNumber();
1793 }
1794 
1796 {
1797  SkipUNumber();
1798 }
1799 
1801 {
1802  SkipSNumber();
1803 }
1804 
1806 {
1807  SkipUNumber();
1808 }
1809 
1811 {
1812  SkipFNumber();
1813 }
1814 
1816 {
1817  SkipFNumber();
1818 }
1819 
1820 #if SIZEOF_LONG_DOUBLE != 0
1821 void CObjectIStream::SkipLDouble(void)
1822 {
1823  SkipFNumber();
1824 }
1825 #endif
1826 
1828 {
1829  SkipString();
1830 }
1831 
1833 {
1834  SkipString();
1835 }
1836 
1838 {
1840 }
1841 
1843 {
1844  ByteBlock bl(*this);
1845  vector<unsigned char> v;
1846  unsigned char buf[2048];
1847  size_t count;
1848  while ( (count = bl.Read(buf, sizeof(buf))) != 0 ) {
1849  v.insert(v.end(), buf, buf + count);
1850  }
1851  bm::deserialize(obj, reinterpret_cast<const unsigned char*>(&v.front()));
1852  bl.End();
1853 }
1854 
1855 char ReplaceVisibleChar(char c, EFixNonPrint fix_method,
1856  const CObjectStack* io, const CTempString& str, char subst)
1857 {
1858  if ( fix_method == eFNP_Skip ) {
1859  return '\0';
1860  }
1861  if ( fix_method == eFNP_Allow ) {
1862  return c;
1863  }
1864  if ( fix_method != eFNP_Replace ) {
1865  string message;
1866  if (io != NULL) {
1867  message += io->GetStackTrace() + "\n";
1868  }
1869  message += "Bad char [0x" +
1870  NStr::NumericToString((unsigned char)c,0,16)+
1871  "] in string";
1872  if (io != NULL) {
1873  message += " at " + io->GetPosition();
1874  }
1875  if (!str.empty()) {
1876  message += "\n" + str;
1877  }
1878  switch (fix_method) {
1879  case eFNP_ReplaceAndWarn:
1880 #if 0
1882  << ErrCode(NCBI_ERRCODE_X, 7) << message << Endm;
1883 #else
1884  ERR_POST_X(7, message);
1885 #endif
1886  break;
1887  case eFNP_Throw:
1889  case eFNP_Abort:
1891  << ErrCode(NCBI_ERRCODE_X, 8) << message << Endm;
1892  break;
1893  default:
1894  break;
1895  }
1896  }
1897  return subst;
1898 }
1899 
1901 {
1902  m_Input.SetCanceledCallback(callback);
1903 }
1904 
1905 
1907  size_t max_depth,
1908  size_t min_depth) const
1909 {
1910  for ( size_t i = 1, depth = 0, size = GetStackDepth(); i < size; ++i ) {
1911  const TFrame& frame = FetchFrameFromTop(i);
1912  if ( frame.GetFrameType() == TFrame::eFrameClass ||
1913  frame.GetFrameType() == TFrame::eFrameChoice ) {
1914  if ( depth >= min_depth && frame.HasTypeInfo(type) ) {
1915  return const_cast<TObjectPtr>(frame.GetObjectPtr());
1916  }
1917  if ( ++depth > max_depth ) {
1918  break;
1919  }
1920  }
1921  }
1922  return 0;
1923 }
1924 
1925 
1926 #ifdef NCBI_STRICT_GI
1928 {
1929  obj.Set() = ReadInt8();
1930 }
1931 
1932 
1934 {
1935  SkipInt8();
1936 }
1937 #endif
1938 
1939 
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
CObjectInfoCV –.
Definition: objectiter.hpp:588
CObjectInfoMI –.
Definition: objectiter.hpp:432
CObjectInfo –.
Definition: objectinfo.hpp:597
CObjectTypeInfo –.
Definition: objectinfo.hpp:94
CObject –.
Definition: ncbiobj.hpp:180
bool Pack(string &s)
Read hook for a choice variant (CHOICE)
Definition: objhook.hpp:117
Read hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:78
Read hook for a standalone object.
Definition: objhook.hpp:59
CSafeStatic<>::
T & Get(void)
Create the variable if not created yet, return the reference.
Root class for all serialization exceptions.
Definition: exception.hpp:50
Skip hook for a choice variant (CHOICE)
Definition: objhook.hpp:239
Skip hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:223
Skip hook for a standalone object.
Definition: objhook.hpp:205
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
Interface for testing cancellation request in a long lasting operation.
Definition: icanceled.hpp:51
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
Include a standard set of the NCBI C++ Toolkit most basic headers.
static uch flags
static unsigned char depth[2 *(256+1+29)+1]
static int failure
Definition: t0019.c:11
#define false
Definition: bool.h:36
static int type
Definition: getdata.c:31
static const char * str(char *buf, int n)
Definition: stats.c:84
char data[12]
Definition: iconv.c:80
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
element_type * release(void)
Release will release ownership of pointer to caller.
Definition: ncbimisc.hpp:472
void Set(TId id)
Definition: ncbimisc.hpp:922
@ eTakeOwnership
An object can take ownership of another.
Definition: ncbi_types.h:136
#define NULL
Definition: ncbistd.hpp:225
#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
@ eDPF_Default
Use global default flags (merge with).
Definition: ncbidiag.hpp:771
@ eDiag_Trace
Trace message.
Definition: ncbidiag.hpp:657
@ eDiag_Error
Error message.
Definition: ncbidiag.hpp:653
@ eDiag_Fatal
Fatal error – guarantees exit(or abort)
Definition: ncbidiag.hpp:655
#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_RETHROW_SAME(prev_exception, message)
Generic macro to re-throw the same exception.
Definition: ncbiexpt.hpp:749
static const CItemInfo * FindNextMandatory(const CItemInfo *info)
Definition: memberlist.cpp:338
void SetPathReadHook(CObjectIStream *in, const string &path, CReadClassMemberHook *hook)
Definition: member.cpp:563
const CMemberId & GetId(void) const
void SetPathSkipHook(CObjectIStream *in, const string &path, CSkipChoiceVariantHook *hook)
Definition: variant.cpp:837
void SetPathReadHook(CObjectIStream *in, const string &path, CReadChoiceVariantHook *hook)
Definition: variant.cpp:785
void ReadVariant(CObjectIStream &in, TObjectPtr choicePtr) const
void SkipVariant(CObjectIStream &in) const
bool HaveNoPrefix(void) const
void DefaultReadVariant(CObjectIStream &in, TObjectPtr choicePtr) const
void DefaultReadMember(CObjectIStream &in, TObjectPtr classPtr) const
void SetPathSkipHook(CObjectIStream *in, const string &path, CSkipClassMemberHook *hook)
Definition: member.cpp:615
string ToString(void) const
Definition: memberid.cpp:113
ESerialSkipUnknown
Skip unknown members parameters.
Definition: serialdef.hpp:118
EFixNonPrint
How to process non-printing character in the ASN VisibleString.
Definition: serialdef.hpp:173
int TSerialOpenFlags
Definition: serialdef.hpp:135
void * TObjectPtr
Definition: serialdef.hpp:55
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
EStringType
String type.
Definition: serialdef.hpp:185
#define XSERIAL_TYPEINFO_WRITELOCK
Definition: serialimpl.hpp:277
static const TObjectType * SafeCast(TTypeInfo type)
Definition: serialutil.hpp:76
ESerialDataFormat
Data file format.
Definition: serialdef.hpp:71
#define SERIAL_VERIFY_DATA_READ
Definition: serialdef.hpp:104
@ 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
@ eSerial_UseFileForReread
Definition: serialdef.hpp:133
@ eSerialSkipUnknown_Never
never skip (even if set to skip later on)
Definition: serialdef.hpp:121
@ eSerialSkipUnknown_No
do not skip (throw exception)
Definition: serialdef.hpp:120
@ eSerialSkipUnknown_Yes
do skip
Definition: serialdef.hpp:122
@ eSerialSkipUnknown_Always
always skip (even if set not to later on)
Definition: serialdef.hpp:123
@ eSerialSkipUnknown_Default
use current default
Definition: serialdef.hpp:119
@ 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
@ eTypeFamilyClass
Definition: serialdef.hpp:140
@ 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
CIStreamBuffer m_Input
Definition: objistr.hpp:1048
ESerialDataFormat GetDataFormat(void) const
Get data format.
void SetPathSkipMemberHook(const string &path, CSkipClassMemberHook *hook)
Definition: objistr.cpp:716
void ThrowError1(const CDiagCompileInfo &diag_info, TFailFlags fail, const char *message)
Definition: objistr.cpp:822
virtual void ReadStringStore(string &s)
Definition: objistr.cpp:1757
static CTypeInfo * FindType(const CObjectStack &stk)
Definition: pathhook.cpp:272
virtual void SkipGi(void)
Definition: objistr.cpp:1933
vector< TTypeInfo > m_ReqMonitorType
Definition: objistr.hpp:1089
void SetCanceledCallback(const ICanceled *callback)
Set cancellation check callback.
Definition: objistr.cpp:1900
static ESerialSkipUnknown x_GetSkipUnknownVariantsDefault(void)
Definition: objistr.cpp:418
virtual void ReadString(string &s, EStringType type=eStringTypeVisible)=0
virtual EPointerType ReadPointerType(void)=0
CStreamPathHook< CMemberInfo *, CSkipClassMemberHook * > m_PathSkipMemberHooks
Definition: objistr.hpp:1082
virtual void ReadGi(TGi &obj)
Definition: objistr.cpp:1927
ESerialVerifyData GetVerifyData(void) const
Get input data verification parameter.
char ReplaceVisibleChar(char c, EFixNonPrint fix_method, const CObjectStack *io, const CTempString &str, char subst)
Definition: objistr.cpp:1855
void Read(const CObjectInfo &object)
Read object of know type.
Definition: objistr.cpp:952
CharBlock(CObjectIStream &in)
Definition: objistr.cpp:1612
virtual void x_SetPathHooks(bool set) override
Definition: objistr.cpp:640
ByteBlock(CObjectIStream &in)
Definition: objistr.cpp:1549
virtual void EndClassMember(void)
Definition: objistr.cpp:1372
MLIOVIR void ReadAlias(const CAliasTypeInfo *aliasType, TObjectPtr aliasPtr)
Definition: objistr.cpp:1524
void SkipFileHeader(TTypeInfo typeInfo)
Read file header and compare the type name with the expected one.
Definition: objistr.cpp:883
virtual void Location(string &, size_t &) const
Get current stream location as tuple (positiontype:string, size_t).
Definition: objistr.cpp:815
EDelayBufferParsing GetDelayBufferParsingPolicy(void) const
Definition: objistr.cpp:740
virtual set< TTypeInfo > GuessDataType(const set< TTypeInfo > &known_types, size_t max_length=16, size_t max_bytes=1024 *1024)
Identify the type of data in the stream.
Definition: objistr.cpp:911
virtual void SkipInt4(void)
Definition: objistr.cpp:1790
void SetHook(const string &path, THook hook)
Definition: pathhook.hpp:102
MLIOVIR void ReadClassSequential(const CClassTypeInfo *classType, TObjectPtr classPtr)
Definition: objistr.cpp:1398
static CObjectIStream * CreateObjectIStreamXml(void)
Definition: objistrxml.cpp:52
CLocalHookSet< CSkipObjectHook > m_ObjectSkipHookKey
Definition: objistr.hpp:1149
virtual void EndContainerElement(void)
Definition: objistr.cpp:1314
static void SetSkipUnknownGlobal(ESerialSkipUnknown skip)
Set up default skipping unknown members for streams created by the current process.
Definition: objistr.cpp:358
MLIOVIR void SkipChoiceSimple(const CChoiceTypeInfo *choiceType)
Definition: objistr.cpp:1503
virtual Int1 ReadInt1(void)
Definition: objistr.cpp:1679
#define BEGIN_OBJECT_FRAME(Type)
Definition: objstack.hpp:224
virtual void UndoClassMember(void)
Definition: objistr.hpp:996
#define ThrowError(flag, mess)
Definition: objstack.hpp:113
virtual void EndContainer(void)=0
bool fail(void) const
Check if any of fail flags is set.
void RegisterObject(TTypeInfo typeInfo)
Definition: objistr.cpp:861
ESerialSkipUnknown UpdateSkipUnknownMembers(void)
Update skip unknown members option to non-default value.
Definition: objistr.cpp:428
bool HasTypeInfo(void) const
const CReadObjectInfo & GetRegisteredObject(TObjectIndex index) const
Definition: objlist.cpp:184
virtual void EndBytes(const ByteBlock &block)
Definition: objistr.cpp:1671
void ResetPathHooks(void)
Definition: objstack.cpp:63
static CObjectIStream * Create(ESerialDataFormat format)
Create serial object reader.
Definition: objistr.cpp:144
CStreamObjectPathHook< CSkipObjectHook * > m_PathSkipObjectHooks
Definition: objistr.hpp:1080
EFixNonPrint x_GetFixCharsMethodDefault(void) const
Definition: objistr.cpp:305
virtual bool EndOfData(void)
Check if there is still some meaningful data that can be read; in text streams this function will ski...
Definition: objistr.cpp:588
virtual void SkipInt1(void)
Definition: objistr.cpp:1770
virtual TMemberIndex BeginClassMember(const CClassTypeInfo *classType)=0
CStreamObjectPathHook< CReadObjectHook * > m_PathReadObjectHooks
Definition: objistr.hpp:1079
void SetMonitorType(TTypeInfo type)
Definition: objistr.cpp:621
void AddMonitorType(TTypeInfo type)
Definition: objistr.cpp:626
virtual Uint1 ReadUint1(void)
Definition: objistr.cpp:1688
virtual string ReadOtherPointer(void)=0
virtual void SkipString(EStringType type=eStringTypeVisible)=0
const CMemberInfo * GetMemberInfo(void) const
#define BEGIN_OBJECT_FRAME2(Type, Arg)
Definition: objstack.hpp:225
static CObjectIStream * CreateObjectIStreamAsn(void)
Definition: objistrasn.cpp:52
MLIOVIR void ReadContainer(const CContainerTypeInfo *containerType, TObjectPtr containerPtr)
Definition: objistr.cpp:1318
virtual string GetStackTrace(void) const =0
void Unended(const string &msg)
Definition: objistr.cpp:610
const CReadObjectInfo & GetRegisteredObject(TObjectIndex index)
Definition: objistr.cpp:874
void SkipObject(const CObjectTypeInfo &objectType)
Skip child object.
Definition: objistr.cpp:1102
virtual void SkipFNumber(void)=0
virtual void ReadOtherPointerEnd(void)
Definition: objistr.cpp:1223
CStreamPathHook< CVariantInfo *, CReadChoiceVariantHook * > m_PathReadVariantHooks
Definition: objistr.hpp:1083
static ESerialVerifyData x_GetVerifyDataDefault(void)
Definition: objistr.cpp:257
const string & GetStackPath(void) const
Definition: objstack.cpp:263
MLIOVIR void SkipAlias(const CAliasTypeInfo *aliasType)
Definition: objistr.cpp:1535
TObjectPtr GetObjectPtr(void) const
Get pointer to object.
virtual void BeginNamedType(TTypeInfo namedTypeInfo)
Definition: objistr.cpp:1276
TFlags GetFlags(void) const
virtual double ReadDouble(void)=0
virtual string ReadFileHeader(void)
Read file header.
Definition: objistr.cpp:1121
CObjectInfo ReadObject(void)
Definition: objistr.cpp:1075
virtual void ResetState(void) override
Definition: objistr.cpp:486
void ReadChoiceVariant(const CObjectInfoCV &object)
Definition: objistr.cpp:1114
const CObjectInfo & GetClassObject(void) const
Get containing class data.
virtual Uint2 ReadUint2(void)
Definition: objistr.cpp:1706
bool ExpectedMember(const CMemberInfo *memberInfo)
Definition: objistr.cpp:1032
virtual string GetStackTrace(void) const override
Get current stack trace as string.
Definition: objistr.cpp:780
void ResetLocalHooks(void)
Definition: objistr.cpp:527
TTypeInfo m_MonitorType
Definition: objistr.hpp:1088
TFrame & FetchFrameFromTop(size_t index)
void SetStreamPos(CNcbiStreampos pos)
Set the current read position in underlying input stream This is the same as istream::seekg()
Definition: objistr.cpp:800
TObjectIndex GetObjectCount(void) const
virtual void EndNamedType(void)
Definition: objistr.cpp:1280
virtual TMemberIndex BeginChoiceVariant(const CChoiceTypeInfo *choiceType)=0
static void SetSkipUnknownVariantsGlobal(ESerialSkipUnknown skip)
Set up default skipping unknown choice variants for streams created by the current process.
Definition: objistr.cpp:405
string GetStackTraceASN(void) const
Definition: objstack.cpp:80
virtual void SkipSNumber(void)=0
void Skip(const CObjectTypeInfo &type)
Skip object of know type.
Definition: objistr.cpp:1009
ESerialSkipUnknown UpdateSkipUnknownVariants(void)
Update skip unknown variants option to non-default value.
Definition: objistr.cpp:442
CLocalHookSet< CReadObjectHook > m_ObjectHookKey
Definition: objistr.hpp:1146
void SetPathReadMemberHook(const string &path, CReadClassMemberHook *hook)
Definition: objistr.cpp:710
virtual void BeginContainer(const CContainerTypeInfo *containerType)=0
virtual void SkipUNumber(void)=0
void ResetMonitorType(void)
Definition: objistr.cpp:634
size_t TObjectIndex
Definition: objlist.hpp:58
void ClearStack(void)
Definition: objstack.cpp:75
AutoPtr< CReadObjectList > m_Objects
Definition: objistr.hpp:1075
virtual Uint4 ReadUint4(void)
Definition: objistr.cpp:1724
virtual char * ReadCString(void)
Definition: objistr.cpp:1750
TFailFlags m_Fail
Definition: objistr.hpp:1077
CNcbiStreampos GetStreamPos(void) const
Get the current stream position.
Definition: objistr.cpp:790
bool ShouldParseDelayBuffer(void) const
Definition: objistr.cpp:745
TTypeInfo GetTypeInfo(void) const
virtual void UnendedFrame(void) override
Definition: objistr.cpp:616
virtual void SkipUint8(void)
Definition: objistr.cpp:1805
virtual void SkipAnyContentVariant(void)
Definition: objistr.cpp:1837
TTypeInfo m_TypeAlias
Definition: objistr.hpp:1052
CLocalHookSet< CReadClassMemberHook > m_ClassMemberHookKey
Definition: objistr.hpp:1147
void SetMemoryPool(CObjectMemoryPool *memory_pool)
Definition: objistr.hpp:806
virtual void SkipStringStore(void)
Definition: objistr.cpp:1832
virtual Int2 ReadInt2(void)
Definition: objistr.cpp:1697
virtual string GetPosition(void) const override
Get current stream position as string.
Definition: objistr.cpp:807
#define END_OBJECT_FRAME()
Definition: objstack.hpp:227
virtual void SkipCString(void)
Definition: objistr.cpp:1827
void SetPathSkipVariantHook(const string &path, CSkipChoiceVariantHook *hook)
Definition: objistr.cpp:728
size_t GetStackDepth(void) const
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:195
bool InGoodState(void)
Check fail flags and also the state of input data source.
Definition: objistr.cpp:570
virtual void ReadPackedString(string &s, CPackString &pack_string, EStringType type=eStringTypeVisible)
Definition: objistr.cpp:1762
TConstObjectPtr GetObjectPtr(void) const
void ReadClassMember(const CObjectInfoMI &member)
Definition: objistr.cpp:1107
static ESerialSkipUnknown x_GetSkipUnknownDefault(void)
Definition: objistr.cpp:371
void ForgetObjects(TObjectIndex from, TObjectIndex to)
Definition: objlist.cpp:191
virtual string PeekNextTypeName(void)
Peek next data type name in XML stream.
Definition: objistr.cpp:1128
const TFrame & TopFrame(void) const
virtual float ReadFloat(void)
Definition: objistr.cpp:1733
static CRef< CByteSource > GetSource(ESerialDataFormat format, const string &fileName, TSerialOpenFlags openFlags=0)
Definition: objistr.cpp:88
ESerialSkipUnknown m_SkipUnknown
Definition: objistr.hpp:1073
static void SetSkipUnknownThread(ESerialSkipUnknown skip)
Set up default skipping unknown members for streams created by the current thread.
Definition: objistr.cpp:345
virtual void SkipPointer(TTypeInfo declaredType)
Definition: objistr.cpp:1234
void UnsetMemberSpecialCase(void)
Definition: objistr.hpp:1111
ESerialSkipUnknown m_SkipUnknownVariants
Definition: objistr.hpp:1074
TObjectPtr GetParentObjectPtr(TTypeInfo type, size_t max_depth=1, size_t min_depth=1) const
Definition: objistr.cpp:1906
EDelayBufferParsing
DelayBuffer parsing policy.
Definition: objistr.hpp:518
CStreamPathHook< CMemberInfo *, CReadClassMemberHook * > m_PathReadMemberHooks
Definition: objistr.hpp:1081
EFixNonPrint x_FixCharsMethod(void) const
Definition: objistr.cpp:311
bool x_HavePathHooks() const
Definition: objistr.cpp:765
THook GetHook(CObjectStack &stk) const
Definition: pathhook.hpp:106
TFailFlags SetFailFlags(TFailFlags flags, const char *message=0)
Set fail flags.
Definition: objistr.cpp:552
MLIOVIR void ReadChoiceSimple(const CChoiceTypeInfo *choiceType, TObjectPtr choicePtr)
Definition: objistr.cpp:1482
virtual pair< TObjectPtr, TTypeInfo > ReadPointer(TTypeInfo declaredType)
Definition: objistr.cpp:1133
void SetHook(const string &path, THook hook)
Definition: pathhook.hpp:121
EErrCode
Error codes.
Definition: exception.hpp:53
void SetTopMemberId(const CMemberId &memberId)
TFailFlags GetFailFlags(void) const
Get fail flags.
void SetPathSkipObjectHook(const string &path, CSkipObjectHook *hook)
Definition: objistr.cpp:704
void RegisterObject(TTypeInfo typeInfo)
Definition: objlist.cpp:173
void UseMemoryPool(void)
Definition: objistr.cpp:775
void ReadExternalObject(TObjectPtr object, TTypeInfo typeInfo)
Definition: objistr.cpp:1066
void SetPathReadVariantHook(const string &path, CReadChoiceVariantHook *hook)
Definition: objistr.cpp:722
MLIOVIR void ReadNamedType(TTypeInfo namedTypeInfo, TTypeInfo typeInfo, TObjectPtr object)
Definition: objistr.cpp:1284
size_t TObjectIndex
Definition: objistr.hpp:1029
void SkipExternalObject(TTypeInfo typeInfo)
Definition: objistr.cpp:1227
virtual bool BeginContainerElement(TTypeInfo elementType)=0
virtual void ResetState(void)
Definition: objstack.cpp:58
virtual Int8 ReadInt8(void)=0
virtual TObjectIndex ReadObjectPointer(void)=0
void WatchPathHooks(bool set=true)
MLIOVIR void SkipContainer(const CContainerTypeInfo *containerType)
Definition: objistr.cpp:1349
MLIOVIR void SkipClassSequential(const CClassTypeInfo *classType)
Definition: objistr.cpp:1451
virtual Int4 ReadInt4(void)
Definition: objistr.cpp:1715
CStreamPathHook< CVariantInfo *, CSkipChoiceVariantHook * > m_PathSkipVariantHooks
Definition: objistr.hpp:1084
static TInfo FindItem(const CObjectStack &stk)
Definition: pathhook.hpp:110
EFixNonPrint m_FixMethod
Definition: objistr.hpp:1071
virtual void SkipUint2(void)
Definition: objistr.cpp:1785
virtual void SkipAnyContentObject(void)=0
void SetPathReadObjectHook(const string &path, CReadObjectHook *hook)
Definition: objistr.cpp:698
static CObjectIStream * CreateFromBuffer(ESerialDataFormat format, const char *buffer, size_t size)
Create serial object reader and attach it to a data source.
Definition: objistr.cpp:178
void PopFrame(void)
static CObjectIStream * CreateObjectIStreamAsnBinary(void)
Definition: objistrasnb.cpp:61
EFrameType GetFrameType(void) const
virtual void SkipInt2(void)
Definition: objistr.cpp:1780
void ReadSeparateObject(const CObjectInfo &object)
Temporary reader.
Definition: objistr.cpp:1053
virtual Uint8 ReadUint8(void)=0
static void SetVerifyDataThread(ESerialVerifyData verify)
Set up default input data verification for streams created by the current thread.
Definition: objistr.cpp:229
void Close(void)
Detach reader from a data source.
Definition: objistr.cpp:539
bool m_DiscardCurrObject
Definition: objistr.hpp:1049
void SetStreamOffset(CNcbiStreampos pos)
Definition: objistr.cpp:795
CLocalHookSet< CSkipClassMemberHook > m_ClassMemberSkipHookKey
Definition: objistr.hpp:1150
CLocalHookSet< CSkipChoiceVariantHook > m_ChoiceVariantSkipHookKey
Definition: objistr.hpp:1151
static CObjectIStream * CreateObjectIStreamJson(void)
Definition: objistrjson.cpp:43
void SetDelayBufferParsingPolicy(EDelayBufferParsing policy)
Definition: objistr.cpp:735
#define BEGIN_OBJECT_FRAME3(Type, Arg1, Arg2)
Definition: objstack.hpp:226
virtual void SkipFloat(void)
Definition: objistr.cpp:1810
virtual void EndClass(void)
Definition: objistr.cpp:1368
virtual void StartDelayBuffer(void)
Definition: objistr.cpp:1014
virtual void SkipDouble(void)
Definition: objistr.cpp:1815
virtual void EndChoiceVariant(void)
Definition: objistr.cpp:1478
virtual void BeginClass(const CClassTypeInfo *classInfo)=0
virtual ~CObjectIStream(void)
Destructor.
Definition: objistr.cpp:475
CObjectMemoryPool * GetMemoryPool(void)
Definition: objistr.hpp:810
void HandleEOF(CEofException &)
Definition: objistr.cpp:599
virtual void EndChars(const CharBlock &block)
Definition: objistr.cpp:1675
void DuplicatedMember(const CMemberInfo *memberInfo)
Definition: objistr.cpp:1047
virtual void SkipInt8(void)
Definition: objistr.cpp:1800
virtual void SkipUint4(void)
Definition: objistr.cpp:1795
THook GetHook(CObjectStack &stk) const
Definition: pathhook.hpp:125
void Clear(void)
Definition: objlist.cpp:168
CLocalHookSet< CReadChoiceVariantHook > m_ChoiceVariantHookKey
Definition: objistr.hpp:1148
void OpenFromBuffer(const char *buffer, size_t size)
Attach reader to a data source.
Definition: objistr.cpp:501
CObjectIStream(ESerialDataFormat format)
Definition: objistr.cpp:458
virtual void EndChoice(void)
Definition: objistr.cpp:1475
MLIOVIR void SkipClassRandom(const CClassTypeInfo *classType)
Definition: objistr.cpp:1430
virtual void SkipUint1(void)
Definition: objistr.cpp:1775
static void SetSkipUnknownVariantsThread(ESerialSkipUnknown skip)
Set up default skipping unknown choice variants for streams created by the current thread.
Definition: objistr.cpp:392
CNcbiStreampos GetStreamOffset(void) const
Definition: objistr.cpp:785
MLIOVIR void SkipNamedType(TTypeInfo namedTypeInfo, TTypeInfo typeInfo)
Definition: objistr.cpp:1302
virtual CRef< CByteSource > EndDelayBuffer(void)
Definition: objistr.cpp:1019
void ReadCompressedBitString(CBitString &data)
Definition: objistr.cpp:1842
static void SetVerifyDataGlobal(ESerialVerifyData verify)
Set up default input data verification for streams created by the current process.
Definition: objistr.cpp:243
virtual void BeginChoice(const CChoiceTypeInfo *choiceType)
Definition: objistr.cpp:1472
MLIOVIR void ReadClassRandom(const CClassTypeInfo *classType, TObjectPtr classPtr)
Definition: objistr.cpp:1376
virtual void EndOfRead(void)
Definition: objistr.cpp:903
size_t Read(char *dst, size_t length, bool forceLength=false)
Definition: objistr.cpp:1639
size_t Read(void *dst, size_t length, bool forceLength=false)
Definition: objistr.cpp:1576
virtual string GetPosition(void) const =0
EDelayBufferParsing m_ParseDelayBuffers
Definition: objistr.hpp:1051
bool IsEmpty(void) const
Definition: pathhook.hpp:82
@ fEOF
End of file in the middle of reading an object.
Definition: objistr.hpp:373
@ fOverflow
Data read is beyond the allowed limits.
Definition: objistr.hpp:379
@ fNullValue
Input value is 'null'.
Definition: objistr.hpp:401
@ fReadError
An unknown error when reading the input file.
Definition: objistr.hpp:375
@ fIllegalCall
Illegal in a given context function call.
Definition: objistr.hpp:383
@ fNotImplemented
Method is not implemented.
Definition: objistr.hpp:389
@ fMissingValue
Mandatory value was missing in the input.
Definition: objistr.hpp:394
@ fNotOpen
No input file.
Definition: objistr.hpp:387
@ fInvalidData
Input data is incorrect (e.g. invalid enum)
Definition: objistr.hpp:381
@ fFail
Internal error, the real reason is unclear.
Definition: objistr.hpp:385
@ fFormatError
Input file formatting does not conform with specification.
Definition: objistr.hpp:377
@ fNoError
No error.
Definition: objistr.hpp:371
@ eDelayBufferPolicyNotSet
Parse only if local hook are present.
Definition: objistr.hpp:520
@ eDelayBufferPolicyAlwaysParse
Parse always.
Definition: objistr.hpp:522
@ eFormatError
Malformed input data.
Definition: exception.hpp:57
@ eIoError
An unknown error during serialization.
Definition: exception.hpp:56
@ eInvalidData
Data is incorrect.
Definition: exception.hpp:59
@ eMissingValue
Mandatory value was missing in the input.
Definition: exception.hpp:63
@ eOverflow
Data is beyond the allowed limits.
Definition: exception.hpp:58
@ eNotOpen
No input or output file.
Definition: exception.hpp:62
@ eNullValue
Data value is null.
Definition: exception.hpp:64
@ eFail
Internal error, the real reason is unclear.
Definition: exception.hpp:61
@ eEOF
Unexpected end-of-file.
Definition: exception.hpp:55
@ eNotImplemented
Attempt to use unimplemented funtionality.
Definition: exception.hpp:54
@ eIllegalCall
Illegal in a given context function call.
Definition: exception.hpp:60
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
TObjectType * Release(void)
Release a reference to the object and return a pointer to the object.
Definition: ncbiobj.hpp:846
@ eParam_NoThread
Do not use per-thread values.
Definition: ncbi_param.hpp:418
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
int16_t Int2
2-byte (16-bit) signed integer
Definition: ncbitype.h:100
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
uint16_t Uint2
2-byte (16-bit) unsigned integer
Definition: ncbitype.h:101
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
int8_t Int1
1-byte (8-bit) signed integer
Definition: ncbitype.h:98
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
char PeekChar(size_t offset=0)
void ResetBufferLock(size_t pos)
Definition: strbuffer.cpp:157
void Open(CByteSourceReader &reader)
Definition: strbuffer.cpp:92
void Close(void)
Definition: strbuffer.cpp:125
bool EndOfData(void) const
Definition: strbuffer.hpp:166
void StartSubSource(void)
Definition: strbuffer.cpp:165
void SetStreamPos(CNcbiStreampos pos)
Definition: strbuffer.cpp:593
CNcbiStreampos GetStreamPos(void) const
void SetCanceledCallback(const ICanceled *callback)
Definition: strbuffer.cpp:142
size_t SetBufferLock(size_t size)
Definition: strbuffer.cpp:148
const char * GetError(void) const
CRef< CByteSource > EndSubSource(void)
Definition: strbuffer.cpp:186
bool fail(void) const
void ResetFail(void)
bool HasMore(void)
Int8 NcbiStreamposToInt8(NCBI_NS_STD::char_traits< char >::pos_type stream_pos)
Convert stream position to 64-bit int.
Definition: ncbistre.hpp:771
#define NcbiCin
Definition: ncbistre.hpp:542
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
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:5153
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:2762
#define NcbiEmptyString
Definition: ncbistr.hpp:122
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
const string & GetName(void) const
Get name of this type.
Definition: typeinfo.cpp:249
ETypeFamily GetTypeFamily(void) const
TObjectPtr AddElement(TObjectPtr containerPtr, TConstObjectPtr elementPtr, ESerialRecursionMode how=eRecursive) const
TTypeInfo GetPointedType(void) const
const CMemberInfo * GetMemberInfo(TMemberIndex index) const
static TTypeInfo GetClassInfoByName(const string &name)
Definition: classinfob.cpp:244
bool IsCObject(void) const
Check is this TypeInfo object is kind of CClassTypeInfoBase.
const CVariantInfo * GetVariantInfo(TMemberIndex index) const
void ReadData(CObjectIStream &in, TObjectPtr object) const
TObjectPtr GetDataPtr(TObjectPtr objectPtr) const
Definition: aliasinfo.cpp:178
TConstObjectPtr GetElementPtr(const CConstIterator &it) const
void SetPathReadHook(CObjectIStream *in, const string &path, CReadObjectHook *hook)
Set local context-specific read hook.
Definition: typeinfo.cpp:385
bool InitIterator(CConstIterator &it, TConstObjectPtr containerPtr) const
bool NextElement(CConstIterator &it) const
void EraseAllElements(CIterator &it) const
void SetPathSkipHook(CObjectIStream *in, const string &path, CSkipObjectHook *hook)
Set local context-specific skip hook.
Definition: typeinfo.cpp:438
bool IsFullAlias(void) const
Definition: aliasinfo.hpp:79
TTypeInfo GetElementType(void) const
TObjectPtr Create(CObjectMemoryPool *memoryPool=0) const
Create object of this type on heap (can be deleted by operator delete)
enum ENcbiOwnership EOwnership
Ownership relations between objects.
size_t deserialize(BV &bv, const unsigned char *buf, bm::word_t *temp_block=0, const bm::bv_ref_vector< BV > *ref_vect=0)
Bitvector deserialization from a memory BLOB.
Definition: bmserial.h:3137
#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).
char * buf
int i
static MDB_envinfo info
Definition: mdb_load.c:37
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
EIPRangeType t
Definition: ncbi_localip.c:101
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.
Useful/utility classes and methods.
static Format format
Definition: njn_ioutil.cpp:53
std::istream & in(std::istream &in_, double &x_)
NCBI_PARAM_ENUM_DECL(ESerialVerifyData, SERIAL, VERIFY_DATA_READ)
NCBI_PARAM_ENUM_DEF(ESerialVerifyData, SERIAL, VERIFY_DATA_READ, eSerialVerifyData_Default)
typedef NCBI_PARAM_TYPE(SERIAL, VERIFY_DATA_READ) TSerialVerifyData
NCBI_PARAM_DECL(bool, SERIAL, READ_MMAPBYTESOURCE)
NCBI_PARAM_DEF_EX(bool, SERIAL, READ_MMAPBYTESOURCE, false, eParam_NoThread, SERIAL_READ_MMAPBYTESOURCE)
#define _TRACE(arg)
Definition: objistr.cpp:78
NCBI_PARAM_ENUM_ARRAY(ESerialVerifyData, SERIAL, VERIFY_DATA_READ)
Definition: objistr.cpp:215
static TTypeInfo MapType(const string &name)
Definition: objistr.cpp:856
ESerialSkipUnknownMembers
Definition: objistr.cpp:326
@ eSerialSkipUnknownM_No
Definition: objistr.cpp:328
@ eSerialSkipUnknownM_Yes
Definition: objistr.cpp:330
@ eSerialSkipUnknownM_Always
Definition: objistr.cpp:331
@ eSerialSkipUnknownM_Never
Definition: objistr.cpp:329
@ eSerialSkipUnknownM_Default
Definition: objistr.cpp:327
#define SkipClassSequentialContentsEnd()
#define SkipClassRandomContentsMember()
Definition: objistrimpl.hpp:81
#define ReadClassSequentialContentsEnd(classPtr)
#define SkipClassSequentialContentsBegin(classType)
#define ReadClassRandomContentsBegin(classType)
Definition: objistrimpl.hpp:72
#define ReadClassSequentialContentsMember(classPtr)
#define ReadClassSequentialContentsBegin(classType)
#define ReadClassRandomContentsMember(classPtr)
Definition: objistrimpl.hpp:74
#define SkipClassSequentialContentsMember()
#define SkipClassRandomContentsEnd()
Definition: objistrimpl.hpp:83
#define SkipClassRandomContentsBegin(classType)
Definition: objistrimpl.hpp:79
#define ReadClassRandomContentsEnd()
Definition: objistrimpl.hpp:76
#define VIRTUAL_MID_LEVEL_IO
Definition: objstack.hpp:35
#define count
static uint8_t * buffer
Definition: pcre2test.c:1016
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
#define NcbiSys_setmode
Definition: ncbisys.hpp:47
#define NcbiSys_fileno
Definition: ncbisys.hpp:43
#define NcbiSysChar_strdup
Definition: ncbisys.hpp:178
Definition: type.c:6
#define _ASSERT
Modified on Fri Sep 20 14:57:44 2024 by modify_doxy.py rev. 669887