1 #ifndef SERIALBASE__HPP
2 #define SERIALBASE__HPP
43 #define BITSTRING_AS_VECTOR 0
45 #if !BITSTRING_AS_VECTOR
60 #if BITSTRING_AS_VECTOR
112 const char* member_names,
117 const char* variant_names,
126 template<
class Class>
132 static_cast<Class*
>(object)->
PreRead();
136 static_cast<Class*
>(object)->
PostRead();
140 static_cast<const Class*
>(object)->
PreWrite();
144 static_cast<const Class*
>(object)->
PostWrite();
166 int file_line)
const;
176 return ms_UnassignedStr;
182 return ms_UnassignedByte;
186 bool HasNamespaceName(
void)
const;
188 const string& GetNamespaceName(
void)
const;
191 bool HasNamespacePrefix(
void)
const;
193 const string& GetNamespacePrefix(
void)
const;
195 template <
typename Enum,
size_t N>
206 for(
const auto&
f : e) {
211 Tparent::flip(x_Arg(e));
215 return Tparent::operator[](x_Arg(e));
218 Tparent::reset(x_Arg(e));
222 Tparent::set(x_Arg(e),
val);
230 return static_cast<size_t>(flag);
248 const string& GetName(
void)
const;
250 const string& GetNamespaceName(
void)
const;
271 return GetTypeInfo();
273 static const CTypeInfo* GetTypeInfo(
void);
280 void SetName(
const string& name);
282 const string& GetName(
void)
const;
289 void SetNamespaceName(
const string& ns_name);
291 const string& GetNamespaceName(
void)
const;
293 void SetNamespacePrefix(
const string& ns_prefix);
295 const string& GetNamespacePrefix(
void)
const;
298 void AddAttribute(
const string& name,
301 const vector<CSerialAttribInfoItem>& GetAttributes(
void)
const;
337 template <
class TPrim>
347 const TPrim&
Get(
void)
const
359 operator TPrim(
void)
const
375 return m_Data <
value;
379 return m_Data >
value;
383 return m_Data ==
value;
387 return m_Data !=
value;
400 template <
class TStd>
413 template <
class TString>
426 template <
class TKey,
class TStorage>
456 (
static_cast<const void*
>(
m_Buffer));
484 if (
typeid(src) !=
typeid(dest) ) {
485 string msg(
"Assignment of incompatible types: ");
486 msg +=
typeid(dest).name();
488 msg +=
typeid(src).name();
491 C::GetTypeInfo()->Assign(&dest, &src, how);
500 if (
typeid(object1) !=
typeid(object2) ) {
501 string msg(
"Cannot compare types: ");
502 msg +=
typeid(object1).name();
504 msg +=
typeid(object2).name();
507 return C::GetTypeInfo()->Equals(&object1, &object2, how);
511 template <
typename C>
516 type->Assign(obj, &src);
517 return static_cast<C*
>(obj);
529 static bool HasSerialFormatting(
CNcbiIos& io);
536 void SetFormatFlags(
unsigned long flags);
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()
702 #define MSerial_FlatAsnText MSerial_AsnText(fSerial_AsnText_NoIndentation | fSerial_AsnText_NoEol)
739 return s +
in.tellg();
748 return s.substr(
in.tellg());
823 return this->
operator CRef<T>();
833 template<
typename T>
operator T ()
const
888 #define ASN_STRING(s) SNcbi_AsnTextProxy(s)
889 #define ASN(...) ASN_STRING(#__VA_ARGS__)
897 template<
class CInfo>
903 template<
class CInfo>
909 template<
class CInfo>
915 template<
class CInfo>
921 template<
class CInfo>
927 template<
class CInfo>
934 #define NCBISER_HAVE_PRE_READ(Class) \
935 template<class CInfo> \
937 void NCBISERSetPreRead(const Class* , CInfo* info) \
939 NCBI_NS_NCBI::SetPreRead \
940 (info, &NCBI_NS_NCBI::CClassPrePostReadWrite<Class>::PreRead);\
943 #define NCBISER_HAVE_POST_READ(Class) \
944 template<class CInfo> \
946 void NCBISERSetPostRead(const Class* , CInfo* info) \
948 NCBI_NS_NCBI::SetPostRead \
949 (info, &NCBI_NS_NCBI::CClassPrePostReadWrite<Class>::PostRead);\
952 #define NCBISER_HAVE_PRE_WRITE(Class) \
953 template<class CInfo> \
955 void NCBISERSetPreWrite(const Class* , CInfo* info) \
957 NCBI_NS_NCBI::SetPreWrite \
958 (info, &NCBI_NS_NCBI::CClassPrePostReadWrite<Class>::PreWrite);\
961 #define NCBISER_HAVE_POST_WRITE(Class) \
962 template<class CInfo> \
964 void NCBISERSetPostWrite(const Class* , CInfo* info) \
966 NCBI_NS_NCBI::SetPostWrite \
967 (info, &NCBI_NS_NCBI::CClassPrePostReadWrite<Class>::PostWrite);\
970 #define NCBISER_HAVE_GLOBAL_READ_MEMBER_HOOK(Class, Name, Hook) \
971 template<class CInfo> \
973 void NCBISERSetGlobalReadMemberHook(const Class* , \
976 NCBI_NS_NCBI::SetGlobalReadMemberHook(info, Name, Hook); \
979 #define NCBISER_HAVE_GLOBAL_READ_VARIANT_HOOK(Class, Name, Hook) \
980 template<class CInfo> \
982 void NCBISERSetGlobalReadVariantHook(const Class* , \
985 NCBI_NS_NCBI::SetGlobalReadVariantHook(info, Name, Hook); \
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)
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)
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)
1008 #define ASN_STRUCT_NAME(AsnStructName) NCBI_NAME2(struct_, AsnStructName)
1009 #define ASN_STRUCT_METHOD_NAME(AsnStructName) \
1010 NCBI_NAME2(GetTypeInfo_struct_,AsnStructName)
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); \
1018 const NCBI_NS_NCBI::CTypeInfo* \
1019 GetAsnStructTypeInfo(const ASN_STRUCT_NAME(AsnStructName)* ) \
1021 return ASN_STRUCT_METHOD_NAME(AsnStructName)(); \
1023 struct ASN_STRUCT_NAME(AsnStructName)
1025 #define DECLARE_ASN_CHOICE_INFO(AsnChoiceName) \
1026 DECLARE_ASN_TYPE_INFO(AsnChoiceName)
Serialization / compression of bvector<>. Set theoretical operations on compressed BLOBs.
Serializable object that stores any combination of parsable data.
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Read hook for a choice variant (CHOICE)
Read hook for data member of a containing object (eg, SEQUENCE)
XML attribute information item.
Root class for all serialization exceptions.
Base class for all serializable objects.
Base class for user-defined serializable classes to allow for objects assignment and comparison.
Template class for strict ID types.
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
MSerialXml_DefaultStringEncoding –.
MSerial_SkipUnknownMembers –.
MSerial_SkipUnknownVariants –.
Include a standard set of the NCBI C++ Toolkit most basic headers.
static unsigned char depth[2 *(256+1+29)+1]
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)
static const char * str(char *buf, int n)
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
ESerialRecursionMode
How to assign and compare child sub-objects of serial objects.
bool operator>(const T &value) const
void SetGlobalReadMemberHook(CTypeInfo *start_info, const char *member_names, CReadClassMemberHook *hook)
void(* TPreReadFunction)(const CTypeInfo *info, void *object)
unsigned int TSerial_Json_Flags
void SetGlobalReadVariantHook(CTypeInfo *start_info, const char *variant_names, CReadChoiceVariantHook *hook)
CAliasBase< CStrictId< TKey, TStorage > > TParent
SNcbi_AsnTextProxy(const SNcbi_AsnTextProxy &)=delete
static CStringUTF8 UnassignedStringUTF8(void)
void NCBISERSetPreRead(const void *, CInfo *)
void SetPostRead(CClassTypeInfo *info, TPostReadFunction function)
static size_t x_Arg(Enum flag)
static char UnassignedByte(void)
CStdAliasBase(const CStrictId< TKey, TStorage > &value)
CNcbiOstream & operator<<(CNcbiOstream &io, const MSerial_Flags &obj)
CMemberIndex & set(Enum e, bool val=true)
bool operator!=(const T &value) const
static void PreWrite(const CTypeInfo *, const void *object)
ESerialSkipUnknown
Skip unknown members parameters.
void NCBISERSetGlobalReadVariantHook(const void *, CInfo *)
CStringAliasBase(const TString &value)
EFixNonPrint
How to process non-printing character in the ASN VisibleString.
TObjectPtr GetChoiceObjectPtr(const CObjectInfoCV &variant)
virtual const CTypeInfo * GetThisTypeInfo(void) const
bool SerialEquals(const C &object1, const C &object2, ESerialRecursionMode how=eRecursive)
Compare serial objects.
CAliasBase(const TPrim &value)
void SetPreWrite(CClassTypeInfo *info, TPreWriteFunction function)
char TBuffer[sizeof(TObject)]
unsigned int TSerial_AsnText_Flags
void(* TPreWriteFunction)(const CTypeInfo *info, const void *object)
size_t TMemberIndex
Type used for indexing class members and choice variants.
static TConstObjectPtr GetDataPtr(const TThis *alias)
TObject & operator*(void)
void NCBISERSetPreWrite(const void *, CInfo *)
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)
virtual void UserOp_Assign(const CSerialUserOp &source)=0
Will be called after copying the datatool-generated members.
bool operator==(const T &value) const
C & SerialAssign(C &dest, const C &src, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
MSerial_Format_AsnBinary(void)
ESerialVerifyData
Data verification parameters.
CNcbiIstream & ReadObject(CNcbiIstream &str, TObjectPtr ptr, TTypeInfo info)
const void * TConstObjectPtr
static void PostRead(const CTypeInfo *, void *object)
bool operator[](Enum e) const
CAliasBase< TPrim > TThis
bm::bvector< > CBitString
CNcbiOstream & WriteObject(CNcbiOstream &str, TConstObjectPtr ptr, TTypeInfo info)
void Set(const TPrim &value)
MSerial_Flags(const MSerial_Flags &o)
const CTypeInfo * TTypeInfo
void SetPreRead(CClassTypeInfo *info, TPreReadFunction function)
SNcbi_AsnTextProxy & operator=(SNcbi_AsnTextProxy &&)=delete
static const char ms_UnassignedByte
void SetFlags(CNcbiIos &io) const
void NCBISERSetPostRead(const void *, CInfo *)
CStdAliasBase(const TStd &value)
CNcbiIos & MSerial_VerifyNo(CNcbiIos &io)
MSerial_Format_Json(void)
void(* TPostWriteFunction)(const CTypeInfo *info, const void *object)
CNcbiIos & MSerial_None(CNcbiIos &io)
Reset all formatting flags for the I/O stream.
void NCBISERSetPostWrite(const void *, CInfo *)
void NCBISERSetGlobalReadMemberHook(const void *, CInfo *)
CAliasBase< TString > TParent
CMemberIndex & flip(Enum e)
SNcbi_AsnTextProxy(const char *s, size_t len)
SNcbi_AsnTextProxy(SNcbi_AsnTextProxy &&)=default
void SetPostWrite(CClassTypeInfo *info, TPostWriteFunction function)
CStringAliasBase< TString > TThis
const TPrim & Get(void) const
CAliasBase< TStd > TParent
bool operator<(const T &value) const
static void PreRead(const CTypeInfo *, void *object)
TObjectPtr GetClassObjectPtr(const CObjectInfoMI &member)
void operator>>(CRef< CSerialObject > dest) const
CStdAliasBase< CStrictId< TKey, TStorage > > TThis
const TObject & operator*(void) const
SNcbi_AsnTextProxy(const char *s)
CMemberIndex(initializer_list< Enum > e)
virtual const CTypeInfo * GetThisTypeInfo(void) const =0
CNcbiIos & MSerial_VerifyDefault(CNcbiIos &io)
Define verification of un-initialized data members.
vector< CSerialAttribInfoItem > m_Attlist
C * SerialClone(const C &src)
Create on heap a clone of the source object.
static const char * ms_UnassignedStr
SNcbi_AsnTextProxy & operator=(const SNcbi_AsnTextProxy &)=delete
unsigned int TSerial_Format_Flags
MSerial_Format –.
#define MSerial_AsnText
I/O stream manipulators –.
static string UnassignedString(void)
unsigned int TSerial_Xml_Flags
CStdAliasBase< TStd > TThis
MSerial_Format_AsnText(void)
CMemberIndex & reset(Enum e)
ESerialDataFormat
Data file format.
static void PostWrite(const CTypeInfo *, const void *object)
CNcbiIos & MSerial_VerifyYes(CNcbiIos &io)
void(* TPostReadFunction)(const CTypeInfo *info, void *object)
CNcbiIos & MSerial_VerifyDefValue(CNcbiIos &io)
@ eSerial_AsnText
ASN.1 text.
@ eSerial_AsnBinary
ASN.1 binary.
virtual void DebugDump(CDebugDumpContext ddc, unsigned int depth) const
Define method for dumping debug information.
void Reset(void)
Reset reference object.
CObject & operator=(const CObject &src) THROWS_NONE
Assignment operator.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
IO_PREFIX::ios CNcbiIos
Portable alias for ios.
static CStringUTF8 AsUTF8(const CTempString &src, EEncoding encoding, EValidate validate=eNoValidate)
Convert into UTF8 from a C/C++ string.
#define NCBI_XSERIAL_EXPORT
Definition of all error codes used in serial libraries (xser.lib, xcser.lib).
const GenericPointer< typename T::ValueType > T2 value
const CharType(& source)[N]
static bool Equals(const CVariation::TPlacements &p1, const CVariation::TPlacements &p2)
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_)
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)