NCBI C++ ToolKit
serialbase.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef SERIALBASE__HPP
2 #define SERIALBASE__HPP
3 
4 /* $Id: serialbase.hpp 96994 2022-06-06 15:24:21Z grichenk $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Eugene Vasilchenko
30 *
31 * File Description:
32 * File to be included in all headers generated by datatool
33 */
34 
35 #include <corelib/ncbistd.hpp>
36 #include <corelib/ncbiobj.hpp>
37 #include <serial/exception.hpp>
38 #include <serial/serialdef.hpp>
39 #include <serial/error_codes.hpp>
40 #include <typeinfo>
41 #include <bitset>
42 
43 #define BITSTRING_AS_VECTOR 0
44 
45 #if !BITSTRING_AS_VECTOR
47 #include <util/bitset/bmserial.h>
48 #endif
49 
50 
51 /** @addtogroup GenClassSupport
52  *
53  * @{
54  */
55 
56 
58 
59 // CBitString
60 #if BITSTRING_AS_VECTOR
61 typedef std::vector< bool > CBitString;
62 #else
64 #endif
65 
66 class CTypeInfo;
67 class CClassTypeInfo;
68 class CChoiceTypeInfo;
70 class CObjectInfoCV;
71 class CObjectInfoMI;
74 
75 // enum for choice classes generated by datatool
79 };
80 
81 typedef void (*TPreReadFunction)(const CTypeInfo* info, void* object);
82 typedef void (*TPostReadFunction)(const CTypeInfo* info, void* object);
83 typedef void (*TPreWriteFunction)(const CTypeInfo* info, const void* object);
84 typedef void (*TPostWriteFunction)(const CTypeInfo* info, const void* object);
85 
88 
91 
94 
97 
100 
103 
106 
109 
111 void SetGlobalReadMemberHook(CTypeInfo* start_info,
112  const char* member_names,
113  CReadClassMemberHook* hook);
114 
116 void SetGlobalReadVariantHook(CTypeInfo* start_info,
117  const char* variant_names,
118  CReadChoiceVariantHook* hook);
119 
122 
125 
126 template<class Class>
128 {
129 public:
130  static void PreRead(const CTypeInfo* /*info*/, void* object)
131  {
132  static_cast<Class*>(object)->PreRead();
133  }
134  static void PostRead(const CTypeInfo* /*info*/, void* object)
135  {
136  static_cast<Class*>(object)->PostRead();
137  }
138  static void PreWrite(const CTypeInfo* /*info*/, const void* object)
139  {
140  static_cast<const Class*>(object)->PreWrite();
141  }
142  static void PostWrite(const CTypeInfo* /*info*/, const void* object)
143  {
144  static_cast<const Class*>(object)->PostWrite();
145  }
146 };
147 
148 /// Base class for all serializable objects
150 {
151 public:
152  CSerialObject(void);
153  virtual ~CSerialObject(void);
154  virtual const CTypeInfo* GetThisTypeInfo(void) const = 0;
155  /// Set object to copy of another one
156  virtual void Assign(const CSerialObject& source,
158  /// Check if both objects contain the same values
159  virtual bool Equals(const CSerialObject& object,
160  ESerialRecursionMode how = eRecursive) const;
161  virtual void DebugDump(CDebugDumpContext ddc, unsigned int depth) const;
162 
163  void ThrowUnassigned(TMemberIndex index) const;
164  void ThrowUnassigned(TMemberIndex index,
165  const char* file_name,
166  int file_line) const;
167  // for all GetX() methods called in the current thread
168  static void SetVerifyDataThread(ESerialVerifyData verify);
169  // for all GetX() methods called in the current process
170  static void SetVerifyDataGlobal(ESerialVerifyData verify);
171 
172  static const char* ms_UnassignedStr;
173  static const char ms_UnassignedByte;
174 
175  static string UnassignedString(void) {
176  return ms_UnassignedStr;
177  }
179  return CUtf8::AsUTF8(UnassignedString(),eEncoding_UTF8);
180  }
181  static char UnassignedByte(void) {
182  return ms_UnassignedByte;
183  }
184 
185  /// Check if object data type has namespace name
186  bool HasNamespaceName(void) const;
187  /// Get namespace name
188  const string& GetNamespaceName(void) const;
189 
190  /// Check if data type has namespace prefix
191  bool HasNamespacePrefix(void) const;
192  /// Get namespace prefix
193  const string& GetNamespacePrefix(void) const;
194 
195  template <typename Enum, size_t N>
196  class CMemberIndex : public bitset<N>
197  {
198  public:
199  typedef bitset<N> Tparent;
200  CMemberIndex(void) {
201  }
202  CMemberIndex(Enum e) {
203  set(e);
204  }
205  CMemberIndex(initializer_list<Enum> e) {
206  for(const auto& f : e) {
207  set(f);
208  }
209  }
210  CMemberIndex& flip(Enum e) {
211  Tparent::flip(x_Arg(e));
212  return *this;
213  }
214  bool operator[](Enum e) const {
215  return Tparent::operator[](x_Arg(e));
216  }
217  CMemberIndex& reset(Enum e) {
218  Tparent::reset(x_Arg(e));
219  return *this;
220  }
221  CMemberIndex& set(Enum e, bool val = true) {
222  Tparent::set(x_Arg(e), val);
223  return *this;
224  }
225  bool test(Enum e) const {
226  return Tparent::test(x_Arg(e));
227  }
228  protected:
229  static size_t x_Arg(Enum flag) {
230  return static_cast<size_t>(flag);
231  }
232  };
233 
234 private:
235  static ESerialVerifyData x_GetVerifyData(void);
236 };
237 
238 /// XML attribute information item
240 {
241 public:
242  CSerialAttribInfoItem(const string& name,
243  const string& ns_name, const CStringUTF8& value);
245  virtual ~CSerialAttribInfoItem(void);
246 
247  /// Get local name of the information item
248  const string& GetName(void) const;
249  /// Get namespace name of the information item
250  const string& GetNamespaceName(void) const;
251  /// Get normalized value of the information item
252  const CStringUTF8& GetValue(void) const;
253 private:
254  string m_Name;
255  string m_NsName;
257 };
258 
259 /// Serializable object that stores any combination of parsable data
260 ///
261 /// In DTD - elements with category ANY
262 /// In XML schema - element of an unspecified type ('any')
264 {
265 public:
266  CAnyContentObject(void);
267  CAnyContentObject(const CAnyContentObject& other);
268  virtual ~CAnyContentObject(void);
269 
270  virtual const CTypeInfo* GetThisTypeInfo(void) const {
271  return GetTypeInfo();
272  }
273  static const CTypeInfo* GetTypeInfo(void);
274 
275  void Reset(void);
277  bool operator== (const CAnyContentObject& other) const;
278 
279  /// Set local name
280  void SetName(const string& name);
281  /// Get local name
282  const string& GetName(void) const;
283  /// Set normalized value
284  void SetValue(const CStringUTF8& value);
285  /// Get normalized value
286  const CStringUTF8& GetValue(void) const;
287 
288  /// Set namespace name
289  void SetNamespaceName(const string& ns_name);
290  /// Get namespace name
291  const string& GetNamespaceName(void) const;
292  /// Set namespace prefix
293  void SetNamespacePrefix(const string& ns_prefix);
294  /// Get namespace prefix
295  const string& GetNamespacePrefix(void) const;
296 
297  /// Add attribute
298  void AddAttribute(const string& name,
299  const string& ns_name, const CStringUTF8& value);
300  /// Get object attributes
301  const vector<CSerialAttribInfoItem>& GetAttributes(void) const;
302 
303 private:
304  void x_Copy(const CAnyContentObject& other);
305  void x_Decode(const CStringUTF8& value);
306  string m_Name;
308  string m_NsName;
309  string m_NsPrefix;
310  vector<CSerialAttribInfoItem> m_Attlist;
311 };
312 
313 /// Base class for user-defined serializable classes
314 /// to allow for objects assignment and comparison.
315 ///
316 /// EXAMPLE:
317 /// class CSeq_entry : public CSeq_entry_Base, CSerialUserOp
319 {
320  friend class CClassTypeInfo;
321  friend class CChoiceTypeInfo;
322 public:
323  virtual ~CSerialUserOp() { }
324 protected:
325  /// Will be called after copying the datatool-generated members
326  virtual void UserOp_Assign(const CSerialUserOp& source) = 0;
327  /// Will be called after comparing the datatool-generated members
328  virtual bool UserOp_Equals(const CSerialUserOp& object) const = 0;
329 };
330 
331 
332 /////////////////////////////////////////////////////////////////////
333 ///
334 /// Alias wrapper templates
335 ///
336 
337 template <class TPrim>
339 {
340 public:
342 
343  CAliasBase(void) {}
344  explicit CAliasBase(const TPrim& value)
345  : m_Data(value) {}
346 
347  const TPrim& Get(void) const
348  {
349  return m_Data;
350  }
351  TPrim& Set(void)
352  {
353  return m_Data;
354  }
355  void Set(const TPrim& value)
356  {
357  m_Data = value;
358  }
359  operator TPrim(void) const
360  {
361  return m_Data;
362  }
363 
365  {
366  return *this;
367  }
369  {
370  return this;
371  }
372 
373  template<class T> bool operator<(const T& value) const
374  {
375  return m_Data < value;
376  }
377  template<class T> bool operator>(const T& value) const
378  {
379  return m_Data > value;
380  }
381  template<class T> bool operator==(const T& value) const
382  {
383  return m_Data == value;
384  }
385  template<class T> bool operator!=(const T& value) const
386  {
387  return m_Data != value;
388  }
389 
390  static TConstObjectPtr GetDataPtr(const TThis* alias)
391  {
392  return &alias->m_Data;
393  }
394 
395 protected:
396  TPrim m_Data;
397 };
398 
399 
400 template <class TStd>
402 {
405 public:
407  : TParent((TStd)0) {}
408  explicit CStdAliasBase(const TStd& value)
409  : TParent(value) {}
410 };
411 
412 
413 template <class TString>
415 {
418 public:
420  : TParent() {}
421  explicit CStringAliasBase(const TString& value)
422  : TParent(value) {}
423 };
424 
425 
426 template <class TKey, class TStorage>
427 class NCBI_XSERIAL_EXPORT CStdAliasBase<CStrictId<TKey, TStorage>> : public CAliasBase<CStrictId<TKey, TStorage>>
428 {
431 public:
433  : TParent(CStrictId<TKey, TStorage>()) {}
435  : TParent(value) {}
436 };
437 
438 
439 template<typename T>
441 { // char buffer support, used in choices
442 public:
443  typedef T TObject; // object type
444  typedef char TBuffer[sizeof(TObject)]; // char buffer type
445 
446  // cast to object type
448  {
449  TObject* ptr = static_cast<TObject*>
450  (static_cast<void*>(m_Buffer));
451  return *ptr;
452  }
453  const TObject& operator*(void) const
454  {
455  const TObject* ptr = static_cast<const TObject*>
456  (static_cast<const void*>(m_Buffer));
457  return *ptr;
458  }
459 
460  // construct/destruct object
461  void Construct(void)
462  {
463  ::new(static_cast<void*>(m_Buffer)) TObject();
464  }
465  void Destruct(void)
466  {
467  (**this).~TObject();
468  }
469 
470 private:
472 };
473 
474 
475 /////////////////////////////////////////////////////////////////////
476 //
477 // Assignment and comparison for serializable objects
478 //
479 
480 /// Set object to copy of another one
481 template <class C>
482 C& SerialAssign(C& dest, const C& src, ESerialRecursionMode how = eRecursive)
483 {
484  if ( typeid(src) != typeid(dest) ) {
485  string msg("Assignment of incompatible types: ");
486  msg += typeid(dest).name();
487  msg += " = ";
488  msg += typeid(src).name();
489  NCBI_THROW(CSerialException,eIllegalCall, msg);
490  }
491  C::GetTypeInfo()->Assign(&dest, &src, how);
492  return dest;
493 }
494 
495 /// Compare serial objects
496 template <class C>
497 bool SerialEquals(const C& object1, const C& object2,
499 {
500  if ( typeid(object1) != typeid(object2) ) {
501  string msg("Cannot compare types: ");
502  msg += typeid(object1).name();
503  msg += " == ";
504  msg += typeid(object2).name();
505  NCBI_THROW(CSerialException,eIllegalCall, msg);
506  }
507  return C::GetTypeInfo()->Equals(&object1, &object2, how);
508 }
509 
510 /// Create on heap a clone of the source object
511 template <typename C>
512 C* SerialClone(const C& src)
513 {
514  typename C::TTypeInfo type = C::GetTypeInfo();
515  TObjectPtr obj = type->Create();
516  type->Assign(obj, &src);
517  return static_cast<C*>(obj);
518 }
519 
520 /////////////////////////////////////////////////////////////////////////////
521 //
522 // I/O stream manipulators and helpers for serializable objects
523 //
524 
525 // Helper base class
527 {
528 public:
529  static bool HasSerialFormatting(CNcbiIos& io);
530 
531 protected:
532  MSerial_Flags(unsigned long all, unsigned long flags, int idx);
533  MSerial_Flags(const MSerial_Flags& o) { m_Index = o.m_Index; m_All = o.m_All; m_Flags = o.m_Flags; }
534 
535  void SetFlags(CNcbiIos& io) const;
536  void SetFormatFlags(unsigned long flags);
537 
538  friend CNcbiOstream& operator<< (CNcbiOstream& io, const MSerial_Flags& obj);
539  friend CNcbiIstream& operator>> (CNcbiIstream& io, const MSerial_Flags& obj);
540 
541 private:
544 
545  int m_Index;
546  unsigned long m_All;
547  unsigned long m_Flags;
548 };
549 
550 inline
552 {
553  obj.SetFlags(io);
554  return io;
555 }
556 inline
558 {
559  obj.SetFlags(io);
560  return io;
561 }
562 
563 /// MSerial_Format --
564 ///
565 /// I/O stream manipulator. Set the format of output or input.
566 /// Makes it possible to insert or extract serializable objects directly
567 /// into standard I/O streams, hiding the creation of object streams.
568 /// For example:
569 /// cout << MSerial_Format(eSerial_Xml) << obj;
570 /// @sa ESerialDataFormat
571 typedef unsigned int TSerial_Format_Flags;
573 {
574 public:
576 };
577 
579 {
580 public:
583 };
584 
586 {
587 public:
589 };
590 
592 {
593 public:
596 };
597 
599 {
600 public:
603 };
604 
605 /// MSerial_VerifyData --
606 ///
607 /// I/O stream manipulator. Defines verification of un-initialized data members.
608 /// For example:
609 /// cout << MSerial_Format(eSerial_Xml)
610 /// << MSerial_VerifyData(eSerialVerifyData_No) << obj;
611 /// @sa ESerialVerifyData
613 {
614 public:
616 };
617 
618 /// MSerial_SkipUnknownMembers --
619 ///
620 /// I/O stream manipulator. Set up skipping unknown members policy.
621 /// For example:
622 /// cin >> MSerial_Format(eSerial_Xml)
623 /// >> MSerial_SkipUnknownMembers(eSerialSkipUnknown_Yes) >> obj;
624 /// @sa ESerialSkipUnknown
626 {
627 public:
630 };
631 inline
633 {
634  obj.SetFlags(io);
635  return io;
636 }
637 
638 /// MSerial_SkipUnknownVariants --
639 ///
640 /// I/O stream manipulator. Set up skipping unknown choice variants policy.
641 /// For example:
642 /// cin >> MSerial_Format(eSerial_Xml)
643 /// >> MSerial_SkipUnknownVariants(eSerialSkipUnknown_Yes) >> obj;
644 /// @sa ESerialSkipUnknown
646 {
647 public:
650 };
651 inline
653 {
654  obj.SetFlags(io);
655  return io;
656 }
657 
658 /// MSerialXml_DefaultStringEncoding --
659 ///
660 /// I/O stream manipulator. Defines default string encoding in XML stream.
661 /// For example:
662 /// cout << MSerial_Format(eSerial_Xml)
663 /// << MSerialXml_DefaultStringEncoding(eEncoding_UTF8) << obj;
664 /// @sa EEncoding, CObjectOStreamXml, CObjectIStreamXml
666 {
667 public:
669 };
670 
671 /// MSerial_FixNonPrint --
672 ///
673 /// I/O stream manipulators. Defines processing of non-printing characters in the ASN VisibleString.
674 /// For example:
675 /// cout << MSerial_Format(eSerial_AsnText)
676 /// << MSerial_FixNonPrint(eFNP_Replace)
677 /// << obj;
678 /// @sa EFixNonPrint
680 {
681 public:
682  explicit MSerial_FixNonPrint(EFixNonPrint fnp);
683 };
684 
685 
686 /// I/O stream manipulators --
687 ///
688 /// Set the format of output or input.
689 /// Make it possible to insert or extract serializable objects directly
690 /// into standard I/O streams, hiding the creation of object streams.
691 /// For example:
692 /// cout << MSerial_Xml << obj;
693 /// cout << MSerial_Xml(fSerial_Xml_NoXmlDecl) << obj;
694 /// cin >> MSerial_AsnText >> obj;
695 
696 #define MSerial_AsnText MSerial_Format_AsnText()
697 #define MSerial_AsnBinary MSerial_Format_AsnBinary()
698 #define MSerial_Xml MSerial_Format_Xml()
699 #define MSerial_Json MSerial_Format_Json()
700 
701 /// Flat ASN text output - no indentation or line breaks.
702 #define MSerial_FlatAsnText MSerial_AsnText(fSerial_AsnText_NoIndentation | fSerial_AsnText_NoEol)
703 
704 /// Reset all formatting flags for the I/O stream
706 
707 /// Define verification of un-initialized data members.
712 
713 class CConstObjectInfo;
714 class CObjectInfo;
715 // Input/output
720 
723 
724 
725 /// Read data from a stream to a CRef<CSerialObject>. The CRef is reset before reading.
727 istream& operator>>(istream& in, CRef<T>& obj)
728 {
729  obj.Reset(new T);
730  return in >> *obj;
731 }
732 
733 /// Read text ASN.1 from a c-string to a serial object. Return the unread part of the string.
734 inline
735 const char* operator>>(const char* s, CSerialObject& obj)
736 {
737  CNcbiIstrstream in(s);
738  in >> MSerial_AsnText >> obj;
739  return s + in.tellg();
740 }
741 
742 /// Read text ASN.1 from an std::string to a serial object. Return the unread part of the string.
743 inline
744 string operator>>(const string& s, CSerialObject& obj)
745 {
746  CNcbiIstrstream in(s);
747  in >> MSerial_AsnText >> obj;
748  return s.substr(in.tellg());
749 }
750 
751 /// Read data from a c-string to a CRef<CSerialObject>. The CRef is reset before reading.
752 /// Return the unread part of the string.
754 const char* operator>>(const char* s, CRef<T>& obj)
755 {
756  obj.Reset(new T);
757  return s >> *obj;
758 }
759 
760 /// Read data from an std::string to a CRef<CSerialObject>. The CRef is reset before reading.
761 /// Return the unread part of the string.
763 string operator>>(const string& s, CRef<T>& obj)
764 {
765  obj.Reset(new T);
766  return s >> *obj;
767 }
768 
769 
770 /// Write a CRef<CSerialObject> to a stream.
772 ostream& operator<<(ostream& out, const CRef<T>& obj)
773 {
774  return out << *obj;
775 }
776 
777 /// Write a CConstRef<CSerialObject> to a stream.
779 ostream& operator<<(ostream& out, const CConstRef<T>& obj)
780 {
781  return out << *obj;
782 }
783 
784 /// Write a serial object> to an std::string.
785 inline
786 string& operator<<(string& s, const CSerialObject& obj)
787 {
789  out << MSerial_AsnText << obj;
790  s.append(CNcbiOstrstreamToString(out));
791  return s;
792 }
793 
794 /// Write a CRef<CSerialObject> to an std::string.
796 string& operator<<(string& s, const CRef<T>& obj)
797 {
798  return s << *obj;
799 }
800 
801 /// Write a CConstRef<CSerialObject> to an std::string.
803 string& operator<<(string& s, const CConstRef<T>& obj)
804 {
805  return s << *obj;
806 }
807 
808 
809 // Proxy class for converting string literals to serial objects.
811 {
812 public:
813  SNcbi_AsnTextProxy(const char* s, size_t len)
814  : m_Data(s), m_Size(len)
815  {}
816 
817  SNcbi_AsnTextProxy(const char* s)
818  : m_Data(s), m_Size(strlen(s))
819  {}
820 
821  template<typename T> operator CConstRef<T>() const
822  {
823  return this->operator CRef<T>();
824  }
825 
826  template<typename T> operator CRef<T>() const
827  {
828  CRef<T> x(new T);
829  this->operator >> (*x);
830  return x;
831  }
832 
833  template<typename T> operator T () const
834  {
835  T x;
836  this->operator >> (x);
837  return std::move(x);
838  }
839 
841  {
842  this->operator >> (*dest);
843  }
844 
845  void operator >> (CSerialObject* dest) const
846  {
847  _ASSERT(dest != nullptr);
848  this->operator >> (*dest);
849  }
850 
851  void operator >> (CSerialObject& dest) const
852  {
853  string data(m_Data, m_Size);
854  CNcbiIstrstream istr(data);
855  istr >> MSerial_AsnText >> dest;
856  }
857 
858 private:
859  friend SNcbi_AsnTextProxy operator "" _asn(const char* s, size_t len);
860 
861  const char* const m_Data;
862  const size_t m_Size;
863 
868 };
869 
870 
871 /// User literal allowing to initialize CRef<> with an ASN.1 string.
872 /// Examples:
873 /// CRef<CSeq_id> id = "Seq-id ::= gi 12345"_asn;
874 /// CRef<CSeq_id> id = R"~~(Seq-id ::= local str "foobar")~~"_asn;
875 inline
876 SNcbi_AsnTextProxy operator "" _asn(const char* s, size_t len)
877 {
878  return SNcbi_AsnTextProxy(s, len);
879 }
880 
881 /// Macro simplifying usage of ASN.1 strings - no quoting or escaping is required.
882 /// Examples:
883 /// CRef<CSeq_id> id = ASN(Seq-id ::= local str "foobar");
884 /// ASN(
885 /// Seq-id ::= local
886 /// str "foobar"
887 /// ) >> *id;
888 #define ASN_STRING(s) SNcbi_AsnTextProxy(s)
889 #define ASN(...) ASN_STRING(#__VA_ARGS__)
890 
891 
893 
894 // these methods must be defined in root namespace so they have prefix NCBISER
895 
896 // default functions do nothing
897 template<class CInfo>
898 inline
899 void NCBISERSetPreRead(const void* /*object*/, CInfo* /*info*/)
900 {
901 }
902 
903 template<class CInfo>
904 inline
905 void NCBISERSetPostRead(const void* /*object*/, CInfo* /*info*/)
906 {
907 }
908 
909 template<class CInfo>
910 inline
911 void NCBISERSetPreWrite(const void* /*object*/, CInfo* /*info*/)
912 {
913 }
914 
915 template<class CInfo>
916 inline
917 void NCBISERSetPostWrite(const void* /*object*/, CInfo* /*info*/)
918 {
919 }
920 
921 template<class CInfo>
922 inline
923 void NCBISERSetGlobalReadMemberHook(const void* /*object*/, CInfo* /*info*/)
924 {
925 }
926 
927 template<class CInfo>
928 inline
929 void NCBISERSetGlobalReadVariantHook(const void* /*object*/, CInfo* /*info*/)
930 {
931 }
932 
933 // define for declaring specific function
934 #define NCBISER_HAVE_PRE_READ(Class) \
935 template<class CInfo> \
936 inline \
937 void NCBISERSetPreRead(const Class* /*object*/, CInfo* info) \
938 { \
939  NCBI_NS_NCBI::SetPreRead \
940  (info, &NCBI_NS_NCBI::CClassPrePostReadWrite<Class>::PreRead);\
941 }
942 
943 #define NCBISER_HAVE_POST_READ(Class) \
944 template<class CInfo> \
945 inline \
946 void NCBISERSetPostRead(const Class* /*object*/, CInfo* info) \
947 { \
948  NCBI_NS_NCBI::SetPostRead \
949  (info, &NCBI_NS_NCBI::CClassPrePostReadWrite<Class>::PostRead);\
950 }
951 
952 #define NCBISER_HAVE_PRE_WRITE(Class) \
953 template<class CInfo> \
954 inline \
955 void NCBISERSetPreWrite(const Class* /*object*/, CInfo* info) \
956 { \
957  NCBI_NS_NCBI::SetPreWrite \
958  (info, &NCBI_NS_NCBI::CClassPrePostReadWrite<Class>::PreWrite);\
959 }
960 
961 #define NCBISER_HAVE_POST_WRITE(Class) \
962 template<class CInfo> \
963 inline \
964 void NCBISERSetPostWrite(const Class* /*object*/, CInfo* info) \
965 { \
966  NCBI_NS_NCBI::SetPostWrite \
967  (info, &NCBI_NS_NCBI::CClassPrePostReadWrite<Class>::PostWrite);\
968 }
969 
970 #define NCBISER_HAVE_GLOBAL_READ_MEMBER_HOOK(Class, Name, Hook) \
971  template<class CInfo> \
972  inline \
973  void NCBISERSetGlobalReadMemberHook(const Class* /*obj*/, \
974  CInfo* info) \
975  { \
976  NCBI_NS_NCBI::SetGlobalReadMemberHook(info, Name, Hook); \
977  }
978 
979 #define NCBISER_HAVE_GLOBAL_READ_VARIANT_HOOK(Class, Name, Hook) \
980  template<class CInfo> \
981  inline \
982  void NCBISERSetGlobalReadVariantHook(const Class* /*obj*/, \
983  CInfo* info) \
984  { \
985  NCBI_NS_NCBI::SetGlobalReadVariantHook(info, Name, Hook); \
986  }
987 
988 // define for declaring specific function
989 #define DECLARE_INTERNAL_TYPE_INFO() \
990  typedef const NCBI_NS_NCBI::CTypeInfo* TTypeInfo; \
991  virtual TTypeInfo GetThisTypeInfo(void) const { return GetTypeInfo(); } \
992  static TTypeInfo GetTypeInfo(void)
993 
994 #define ENUM_METHOD_NAME(EnumName) \
995  NCBI_NAME2(GetTypeInfo_enum_,EnumName)
996 #define DECLARE_ENUM_INFO(EnumName) \
997  const NCBI_NS_NCBI::CEnumeratedTypeValues* ENUM_METHOD_NAME(EnumName)(void)
998 #define DECLARE_INTERNAL_ENUM_INFO(EnumName) \
999  static DECLARE_ENUM_INFO(EnumName)
1000 
1001 //#define DECLARE_STD_ALIAS_TYPE_INFO() DECLARE_INTERNAL_TYPE_INFO()
1002 #define DECLARE_STD_ALIAS_TYPE_INFO() \
1003  const NCBI_NS_NCBI::CTypeInfo* GetThisTypeInfo(void) const { return GetTypeInfo(); } \
1004  static const NCBI_NS_NCBI::CTypeInfo* GetTypeInfo(void)
1005 
1006 #if HAVE_NCBI_C
1007 
1008 #define ASN_STRUCT_NAME(AsnStructName) NCBI_NAME2(struct_, AsnStructName)
1009 #define ASN_STRUCT_METHOD_NAME(AsnStructName) \
1010  NCBI_NAME2(GetTypeInfo_struct_,AsnStructName)
1011 
1012 #define DECLARE_ASN_TYPE_INFO(AsnStructName) \
1013  const NCBI_NS_NCBI::CTypeInfo* ASN_STRUCT_METHOD_NAME(AsnStructName)(void)
1014 #define DECLARE_ASN_STRUCT_INFO(AsnStructName) \
1015  struct ASN_STRUCT_NAME(AsnStructName); \
1016  DECLARE_ASN_TYPE_INFO(AsnStructName); \
1017  inline \
1018  const NCBI_NS_NCBI::CTypeInfo* \
1019  GetAsnStructTypeInfo(const ASN_STRUCT_NAME(AsnStructName)* ) \
1020  { \
1021  return ASN_STRUCT_METHOD_NAME(AsnStructName)(); \
1022  } \
1023  struct ASN_STRUCT_NAME(AsnStructName)
1024 
1025 #define DECLARE_ASN_CHOICE_INFO(AsnChoiceName) \
1026  DECLARE_ASN_TYPE_INFO(AsnChoiceName)
1027 
1028 #endif
1029 
1030 /* @} */
1031 
1032 #endif /* SERIALBASE__HPP */
Serialization / compression of bvector<>. Set theoretical operations on compressed BLOBs.
Alias wrapper templates.
Definition: serialbase.hpp:339
Serializable object that stores any combination of parsable data.
Definition: serialbase.hpp:264
CConstObjectInfo –.
Definition: objectinfo.hpp:421
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
CObjectInfoCV –.
Definition: objectiter.hpp:588
CObjectInfoMI –.
Definition: objectiter.hpp:432
CObjectInfo –.
Definition: objectinfo.hpp:597
CObject –.
Definition: ncbiobj.hpp:180
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
XML attribute information item.
Definition: serialbase.hpp:240
Root class for all serialization exceptions.
Definition: exception.hpp:50
Base class for all serializable objects.
Definition: serialbase.hpp:150
Base class for user-defined serializable classes to allow for objects assignment and comparison.
Definition: serialbase.hpp:319
Template class for strict ID types.
Definition: ncbimisc.hpp:893
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
MSerialXml_DefaultStringEncoding –.
Definition: serialbase.hpp:666
MSerial_FixNonPrint –.
Definition: serialbase.hpp:680
MSerial_SkipUnknownMembers –.
Definition: serialbase.hpp:626
MSerial_SkipUnknownVariants –.
Definition: serialbase.hpp:646
MSerial_VerifyData –.
Definition: serialbase.hpp:613
Definition: set.hpp:45
Include a standard set of the NCBI C++ Toolkit most basic headers.
static uch flags
static unsigned char depth[2 *(256+1+29)+1]
#define C(s)
Definition: common.h:231
#define T(s)
Definition: common.h:230
const char * file_name[]
bool operator==(const CEquivRange &A, const CEquivRange &B)
std::ofstream out("events_result.xml")
main entry point for tests
#define test(a, b, c, d, e)
Definition: numeric.c:170
static const char * str(char *buf, int n)
Definition: stats.c:84
char data[12]
Definition: iconv.c:80
#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
ESerialRecursionMode
How to assign and compare child sub-objects of serial objects.
Definition: serialdef.hpp:191
bool operator>(const T &value) const
Definition: serialbase.hpp:377
void SetGlobalReadMemberHook(CTypeInfo *start_info, const char *member_names, CReadClassMemberHook *hook)
Definition: serial.cpp:524
void(* TPreReadFunction)(const CTypeInfo *info, void *object)
Definition: serialbase.hpp:81
unsigned int TSerial_Json_Flags
Definition: serialdef.hpp:100
void SetGlobalReadVariantHook(CTypeInfo *start_info, const char *variant_names, CReadChoiceVariantHook *hook)
Definition: serial.cpp:534
CAliasBase< CStrictId< TKey, TStorage > > TParent
Definition: serialbase.hpp:429
SNcbi_AsnTextProxy(const SNcbi_AsnTextProxy &)=delete
const char *const m_Data
Definition: serialbase.hpp:861
static CStringUTF8 UnassignedStringUTF8(void)
Definition: serialbase.hpp:178
void NCBISERSetPreRead(const void *, CInfo *)
Definition: serialbase.hpp:899
void SetPostRead(CClassTypeInfo *info, TPostReadFunction function)
Definition: serial.cpp:451
static size_t x_Arg(Enum flag)
Definition: serialbase.hpp:229
static char UnassignedByte(void)
Definition: serialbase.hpp:181
CStdAliasBase(const CStrictId< TKey, TStorage > &value)
Definition: serialbase.hpp:434
CNcbiOstream & operator<<(CNcbiOstream &io, const MSerial_Flags &obj)
Definition: serialbase.hpp:551
CMemberIndex & set(Enum e, bool val=true)
Definition: serialbase.hpp:221
bool operator!=(const T &value) const
Definition: serialbase.hpp:385
static void PreWrite(const CTypeInfo *, const void *object)
Definition: serialbase.hpp:138
ESerialSkipUnknown
Skip unknown members parameters.
Definition: serialdef.hpp:118
void NCBISERSetGlobalReadVariantHook(const void *, CInfo *)
Definition: serialbase.hpp:929
CStringAliasBase(const TString &value)
Definition: serialbase.hpp:421
EFixNonPrint
How to process non-printing character in the ASN VisibleString.
Definition: serialdef.hpp:173
TObjectPtr GetChoiceObjectPtr(const CObjectInfoCV &variant)
Definition: serial.cpp:549
void * TObjectPtr
Definition: serialdef.hpp:55
virtual const CTypeInfo * GetThisTypeInfo(void) const
Definition: serialbase.hpp:270
bool SerialEquals(const C &object1, const C &object2, ESerialRecursionMode how=eRecursive)
Compare serial objects.
Definition: serialbase.hpp:497
CAliasBase(const TPrim &value)
Definition: serialbase.hpp:344
void SetPreWrite(CClassTypeInfo *info, TPreWriteFunction function)
Definition: serial.cpp:436
TBuffer m_Buffer
Definition: serialbase.hpp:471
void Destruct(void)
Definition: serialbase.hpp:465
char TBuffer[sizeof(TObject)]
Definition: serialbase.hpp:444
unsigned int TSerial_AsnText_Flags
Definition: serialdef.hpp:84
void(* TPreWriteFunction)(const CTypeInfo *info, const void *object)
Definition: serialbase.hpp:83
TPrim & Set(void)
Definition: serialbase.hpp:351
size_t TMemberIndex
Type used for indexing class members and choice variants.
Definition: serialdef.hpp:230
static TConstObjectPtr GetDataPtr(const TThis *alias)
Definition: serialbase.hpp:390
TObject & operator*(void)
Definition: serialbase.hpp:447
void NCBISERSetPreWrite(const void *, CInfo *)
Definition: serialbase.hpp:911
virtual bool UserOp_Equals(const CSerialUserOp &object) const =0
Will be called after comparing the datatool-generated members.
CNcbiIstream & operator>>(CNcbiIstream &io, const MSerial_Flags &obj)
Definition: serialbase.hpp:557
virtual void UserOp_Assign(const CSerialUserOp &source)=0
Will be called after copying the datatool-generated members.
CStdAliasBase(void)
Definition: serialbase.hpp:406
bool operator==(const T &value) const
Definition: serialbase.hpp:381
C & SerialAssign(C &dest, const C &src, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
Definition: serialbase.hpp:482
ESerialVerifyData
Data verification parameters.
Definition: serialdef.hpp:107
CNcbiIstream & ReadObject(CNcbiIstream &str, TObjectPtr ptr, TTypeInfo info)
const void * TConstObjectPtr
Definition: serialdef.hpp:59
static void PostRead(const CTypeInfo *, void *object)
Definition: serialbase.hpp:134
bool operator[](Enum e) const
Definition: serialbase.hpp:214
CAliasBase< TPrim > TThis
Definition: serialbase.hpp:341
bm::bvector< > CBitString
Definition: serialbase.hpp:63
CNcbiOstream & WriteObject(CNcbiOstream &str, TConstObjectPtr ptr, TTypeInfo info)
void Set(const TPrim &value)
Definition: serialbase.hpp:355
MSerial_Flags(const MSerial_Flags &o)
Definition: serialbase.hpp:533
const CTypeInfo * TTypeInfo
Definition: serialdef.hpp:62
void SetPreRead(CClassTypeInfo *info, TPreReadFunction function)
Definition: serial.cpp:446
SNcbi_AsnTextProxy & operator=(SNcbi_AsnTextProxy &&)=delete
virtual ~CSerialUserOp()
Definition: serialbase.hpp:323
static const char ms_UnassignedByte
Definition: serialbase.hpp:173
TThis * operator->(void)
Definition: serialbase.hpp:368
void SetFlags(CNcbiIos &io) const
void NCBISERSetPostRead(const void *, CInfo *)
Definition: serialbase.hpp:905
CStdAliasBase(const TStd &value)
Definition: serialbase.hpp:408
CNcbiIos & MSerial_VerifyNo(CNcbiIos &io)
void(* TPostWriteFunction)(const CTypeInfo *info, const void *object)
Definition: serialbase.hpp:84
CNcbiIos & MSerial_None(CNcbiIos &io)
Reset all formatting flags for the I/O stream.
EResetVariant
Definition: serialbase.hpp:76
void NCBISERSetPostWrite(const void *, CInfo *)
Definition: serialbase.hpp:917
TThis & operator*(void)
Definition: serialbase.hpp:364
void NCBISERSetGlobalReadMemberHook(const void *, CInfo *)
Definition: serialbase.hpp:923
CAliasBase< TString > TParent
Definition: serialbase.hpp:416
CMemberIndex & flip(Enum e)
Definition: serialbase.hpp:210
SNcbi_AsnTextProxy(const char *s, size_t len)
Definition: serialbase.hpp:813
SNcbi_AsnTextProxy(SNcbi_AsnTextProxy &&)=default
void Construct(void)
Definition: serialbase.hpp:461
unsigned long m_Flags
Definition: serialbase.hpp:547
CAliasBase(void)
Definition: serialbase.hpp:343
void SetPostWrite(CClassTypeInfo *info, TPostWriteFunction function)
Definition: serial.cpp:441
unsigned long m_All
Definition: serialbase.hpp:546
CStringAliasBase< TString > TThis
Definition: serialbase.hpp:417
MSerial_Flags(void)
const TPrim & Get(void) const
Definition: serialbase.hpp:347
CAliasBase< TStd > TParent
Definition: serialbase.hpp:403
bool operator<(const T &value) const
Definition: serialbase.hpp:373
static void PreRead(const CTypeInfo *, void *object)
Definition: serialbase.hpp:130
TObjectPtr GetClassObjectPtr(const CObjectInfoMI &member)
Definition: serial.cpp:544
const size_t m_Size
Definition: serialbase.hpp:862
void operator>>(CRef< CSerialObject > dest) const
Definition: serialbase.hpp:840
CStdAliasBase< CStrictId< TKey, TStorage > > TThis
Definition: serialbase.hpp:430
const TObject & operator*(void) const
Definition: serialbase.hpp:453
SNcbi_AsnTextProxy(const char *s)
Definition: serialbase.hpp:817
CMemberIndex(initializer_list< Enum > e)
Definition: serialbase.hpp:205
virtual const CTypeInfo * GetThisTypeInfo(void) const =0
CNcbiIos & MSerial_VerifyDefault(CNcbiIos &io)
Define verification of un-initialized data members.
vector< CSerialAttribInfoItem > m_Attlist
Definition: serialbase.hpp:310
C * SerialClone(const C &src)
Create on heap a clone of the source object.
Definition: serialbase.hpp:512
CStringUTF8 m_Value
Definition: serialbase.hpp:307
static const char * ms_UnassignedStr
Definition: serialbase.hpp:172
SNcbi_AsnTextProxy & operator=(const SNcbi_AsnTextProxy &)=delete
unsigned int TSerial_Format_Flags
MSerial_Format –.
Definition: serialbase.hpp:571
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
static string UnassignedString(void)
Definition: serialbase.hpp:175
unsigned int TSerial_Xml_Flags
Definition: serialdef.hpp:94
CStdAliasBase< TStd > TThis
Definition: serialbase.hpp:404
CMemberIndex & reset(Enum e)
Definition: serialbase.hpp:217
ESerialDataFormat
Data file format.
Definition: serialdef.hpp:71
static void PostWrite(const CTypeInfo *, const void *object)
Definition: serialbase.hpp:142
CNcbiIos & MSerial_VerifyYes(CNcbiIos &io)
TPrim m_Data
Definition: serialbase.hpp:396
void(* TPostReadFunction)(const CTypeInfo *info, void *object)
Definition: serialbase.hpp:82
CNcbiIos & MSerial_VerifyDefValue(CNcbiIos &io)
bool test(Enum e) const
Definition: serialbase.hpp:225
@ eRecursive
Recursively.
Definition: serialdef.hpp:192
@ eDoResetVariant
Definition: serialbase.hpp:77
@ eDoNotResetVariant
Definition: serialbase.hpp:78
@ 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
virtual void DebugDump(CDebugDumpContext ddc, unsigned int depth) const
Define method for dumping debug information.
Definition: ncbiobj.cpp:988
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
CObject & operator=(const CObject &src) THROWS_NONE
Assignment operator.
Definition: ncbiobj.hpp:482
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
std::string CStringUTF8
Definition: ncbistl.hpp:254
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
IO_PREFIX::ios CNcbiIos
Portable alias for ios.
Definition: ncbistre.hpp:140
EEncoding
Definition: ncbistr.hpp:199
static CStringUTF8 AsUTF8(const CTempString &src, EEncoding encoding, EValidate validate=eNoValidate)
Convert into UTF8 from a C/C++ string.
Definition: ncbistr.hpp:3889
@ eEncoding_UTF8
Definition: ncbistr.hpp:201
#define NCBI_XSERIAL_EXPORT
Definition: ncbi_export.h:1435
Definition of all error codes used in serial libraries (xser.lib, xcser.lib).
int len
static MDB_envinfo info
Definition: mdb_load.c:37
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
const CharType(& source)[N]
Definition: pointer.h:1149
static bool Equals(const CVariation::TPlacements &p1, const CVariation::TPlacements &p2)
#define verify(expr)
Definition: ncbi_assert.h:51
Compressed bitset (entry point to bm.h)
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
std::istream & in(std::istream &in_, double &x_)
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
Definition: type.c:6
#define _ASSERT
Modified on Sun Apr 14 05:26:16 2024 by modify_doxy.py rev. 669887