56 #define NCBI_USE_ERRCODE_X Serial_OStream
76 m_LastTagAction(eTagClose), m_SpecRef(eSpecRefNotSet), m_EndTag(
true),
77 m_UseDefaultDTDFilePrefix(
true),
80 m_RealFmt( eRealScientificFormat ),
82 m_UseXmlDecl(
true ), m_UseSchemaLoc(
true ),
91 m_LastTagAction(eTagClose), m_SpecRef(eSpecRefNotSet), m_EndTag(
true),
92 m_UseDefaultDTDFilePrefix(
true),
95 m_RealFmt( eRealScientificFormat ),
97 m_UseXmlDecl(
true ), m_UseSchemaLoc(
true ),
180 if (
flags & ~accepted) {
182 "CObjectOStreamXml::SetFormattingFlags: ignoring unknown formatting flags");
201 const string& s =
type->GetModuleName();
203 for ( string::const_iterator
i = s.begin();
i != s.end(); ++
i ) {
205 if ( !
isalnum((
unsigned char) c) )
220 const string& s =
type->GetModuleName();
221 for ( string::const_iterator
i = s.begin();
i != s.end(); ++
i ) {
286 if (
type->GetName().find(
':') != string::npos) {
294 if (ns_name.empty()) {
317 string xs_prefix(
"xs");
347 if (
type->HasNamespaceName()) {
348 string prefix(
type->GetNamespacePrefix());
364 if (
type->HasNamespaceName()) {
372 const string& ns_prefix)
377 string nsPrefix(ns_prefix);
429 const string& valueName)
431 bool skipname = valueName.empty() ||
522 if ((
unsigned int)c < 0x20) {
525 unsigned hi = ch >> 4;
526 unsigned lo = ch & 0xF;
549 return (x < 0x20 && x > 0x0 && x != 0x9 && x != 0xA && x != 0xD);
575 for ( string::const_iterator
t =
tmp.begin();
t !=
tmp.end(); ++
t ) {
689 while (
buffer[width-1] ==
'0') {
692 if (
buffer[width-1] ==
'.') {
700 width = sprintf(
buffer,
"%.*g", (
int)digits,
data);
701 char* dot = strchr(
buffer,
',');
730 string obj_name = obj.
GetName();
731 if (obj_name.empty()) {
736 if (obj_name.empty()) {
755 const vector<CSerialAttribInfoItem>& attlist = obj.
GetAttributes();
756 if (!attlist.empty()) {
758 vector<CSerialAttribInfoItem>::const_iterator it;
759 for ( it = attlist.begin(); it != attlist.end(); ++it) {
760 string ns(it->GetNamespaceName());
766 if (!ns_prefix.empty()) {
778 if (!ns_prefix.empty()) {
803 bool was_open =
true, was_close=
true;
805 char attr_close =
'\0';
806 for (
const char* is =
value.c_str(); *is; ++is) {
807 if (*is ==
'/' && *(is+1) ==
'>') {
812 if (*(is+1) ==
'/') {
814 if (!was_open && was_close) {
817 is_tag = was_open =
false;
823 is_tag = was_open =
true;
826 if (*is !=
'>' && *is !=
'<' && *is != attr_close) {
832 if (*(is+1) ==
'/') {
847 if (is_tag && *is ==
'=' && (*(is+1) ==
'\"' || *(is+1) ==
'\'')) {
848 attr_close = *(is+1);
864 in.ReadAnyContentObject(obj);
870 #if BITSTRING_AS_VECTOR
871 static const char ToHex[] =
"0123456789ABCDEF";
874 for ( CBitString::const_iterator
i = obj.begin(); !
done; ) {
886 CBitString::statistics
st;
898 for (;
i < ilast; ++
i) {
910 in.ReadBitString(obj);
932 for (
const char* src =
str.c_str(); *src; ++src ) {
939 for ( string::const_iterator
i =
str.begin();
i !=
str.end(); ++
i ) {
958 in.ReadStringStore(
str);
959 for ( string::const_iterator
i =
str.begin();
i !=
str.end(); ++
i ) {
968 if (
TopFrame().GetNotag() && !notag) {
992 "must be either sizeof(Int4) or sizeof(Int8)");
1097 if ( !name.empty() ) {
1099 #if defined(NCBI_SERIAL_IO_TRACE)
1118 #if defined(NCBI_SERIAL_IO_TRACE)
1163 if (clType && clType->
Implicit()) {
1185 while ( elementType->
GetName().empty() ) {
1208 #ifdef VIRTUAL_MID_LEVEL_IO
1212 if ( !cType->
GetName().empty() ) {
1270 "NULL element while writing container "+
1294 "NULL element while writing container "+
1361 #ifdef VIRTUAL_MID_LEVEL_IO
1448 if(
id.IsAttlist()) {
1456 bool needTag =
true;
1502 #ifdef VIRTUAL_MID_LEVEL_IO
1607 bool needTag =
true;
1662 static const char*
const HEX =
"0123456789ABCDEF";
1665 const char* bytes,
size_t length)
1676 const size_t chunk_in = 57;
1677 const size_t chunk_out = 80;
1678 if (length > chunk_in) {
1681 char dst_buf[chunk_out];
1682 size_t bytes_left = length;
1683 size_t src_read=0, dst_written=0, line_len=0;
1684 while (bytes_left > 0 && bytes_left <= length) {
1686 dst_buf, chunk_out, &dst_written, &line_len);
1688 bytes_left -= src_read;
1690 if (bytes_left > 0) {
1694 if (length > chunk_in) {
1701 while ( length-- > 0 ) {
1709 const char*
chars,
size_t length)
1711 while ( length-- > 0 ) {
1724 #if defined(NCBI_SERIAL_IO_TRACE)
1726 void CObjectOStreamXml::TraceTag(
const string& name)
1728 cout <<
", Tag=" << name;
Serializable object that stores any combination of parsable data.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
size_type size() const noexcept
Returns bvector's capacity (number of bits it can store)
bvector_size_type size_type
enumerator first() const
Returns enumerator pointing on the first non-zero bit.
enumerator end() const
Returns enumerator pointing on the next bit after the last.
void calc_stat(struct bm::bvector< Alloc >::statistics *st) const noexcept
Calculates bitvector statistics.
const_iterator end() const
const_iterator find(const key_type &key) const
Include a standard set of the NCBI C++ Toolkit most basic headers.
std::ofstream out("events_result.xml")
main entry point for tests
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
static const char * str(char *buf, int n)
@ eTakeOwnership
An object can take ownership of another.
@ eNoOwnership
No ownership is assumed.
#define ERR_POST_X_ONCE(err_subcode, message)
Error posting only once during program execution with default error code and given error subcode.
void Warning(CExceptionArgs_Base &args)
#define finite
Define value of finite (Is Finite).
const CMemberId & GetId(void) const
const string & GetName(void) const
void WriteVariant(CObjectOStream &out, TConstObjectPtr choicePtr) const
bool IsNillable(void) const
void WriteMember(CObjectOStream &out, TConstObjectPtr classPtr) const
const CItemInfo * GetItemInfo(TMemberIndex index) const
static TMemberIndex FirstIndex(void)
bool HasNotag(void) const
const string & GetName(void) const
bool HaveNoPrefix(void) const
TTypeInfo GetTypeInfo(void) const
const string & FindNameEx(TEnumValueType value, bool allowBadValue) const
bool IsInteger(void) const
Check whether the type is defined as INTEGER in ASN.1 spec.
const CStringUTF8 & GetValue(void) const
Get normalized value.
size_t TMemberIndex
Type used for indexing class members and choice variants.
const string & GetNamespaceName(void) const
Get namespace name.
const void * TConstObjectPtr
const string & GetNamespacePrefix(void) const
Get namespace prefix.
static const TObjectType * SafeCast(TTypeInfo type)
unsigned int TSerial_Format_Flags
MSerial_Format –.
const string & GetName(void) const
Get local name.
const vector< CSerialAttribInfoItem > & GetAttributes(void) const
Get object attributes.
@ eSerialVerifyData_Yes
do verify
@ fSerial_Xml_NoEol
do not write end-of-line symbol
@ fSerial_Xml_NoIndentation
do not use indentation
@ fSerial_Xml_NoSchemaLoc
do not write schemaLocation data
@ fSerial_Xml_NoXmlDecl
do not write XMLDecl
@ fSerial_Xml_RefSchema
use reference to a Schema
@ fSerial_Xml_NoRefDTD
do not use reference to a DTD
@ eStringTypeUTF8
UTF8-encoded string.
virtual void WriteString(const string &s, EStringType type=eStringTypeVisible) override
static ETypeFamily GetRealTypeFamily(TTypeInfo typeInfo)
virtual void WriteEnum(const CEnumeratedTypeValues &values, TEnumValueType value) override
virtual void CopyStringStore(CObjectIStream &in) override
void SetDefaultStringEncoding(EEncoding enc)
Set default encoding of 'string' objects If XML data encoding is different, string will be converted ...
void WriteTag(const string &name)
virtual void WriteOther(TConstObjectPtr object, TTypeInfo typeInfo) override
char ReplaceVisibleChar(char c, EFixNonPrint fix_method, const CObjectStack *io, const CTempString &str, char subst)
static string sm_DefaultDTDFilePrefix
virtual void WriteBytes(const ByteBlock &block, const char *bytes, size_t length) override
bool GetReferenceDTD(void) const
Get DTD referencing parameter.
MLIOVIR void WriteClassMemberSpecialCase(const CMemberId &memberId, TTypeInfo memberType, TConstObjectPtr memberPtr, ESpecialCaseWrite how)
void x_WriteClassNamespace(TTypeInfo type)
void WriteClassMember(const CConstObjectInfoMI &member)
ERealValueFormat m_RealFmt
EFixNonPrint x_FixCharsMethod(void) const
void WriteEscapedChar(char c)
bool x_SpecialCaseWrite(void)
virtual void EndContainer(void) override
virtual void EndNamedType(void) override
virtual void BeginClassMember(const CMemberId &id) override
#define END_OBJECT_2FRAMES_OF(Stream)
virtual void BeginChoice(const CChoiceTypeInfo *choiceType) override
bool GetEnforcedStdXml(void)
Get scope prefixes handling parameter.
virtual void SetFormattingFlags(TSerial_Format_Flags flags) override
Set output formatting flags.
virtual void EndClassMember(void) override
static TTypeInfo GetRealTypeInfo(TTypeInfo typeInfo)
void SetUseSchemaLocation(bool use_loc=true)
Put Schema location information into generated XML document.
virtual void WriteAnyContentObject(const CAnyContentObject &obj) override
void CopyObject(TTypeInfo objectType, CObjectStreamCopier &copier)
void SetReferenceSchema(bool use_schema=true)
Make generated XML document reference XML schema.
void OpenStackTag(size_t level)
virtual void WriteDouble(double data) override
#define ThrowError(flag, mess)
bool GetUseSchemaLocation(void) const
Get Schema location output parameter.
map< string, string > m_NsNameToPrefix
void CloseTag(const string &name)
void PrintTagName(size_t level)
virtual void WriteBool(bool data) override
bool IsCompressed(void) const
void SetReferenceDTD(bool use_dtd=true)
Make generated XML document reference DTD.
EEncoding m_StringEncoding
#define BEGIN_OBJECT_FRAME2(Type, Arg)
map< string, string > m_NsPrefixToName
void WriteContainerContents(const CContainerTypeInfo *containerType, TConstObjectPtr containerPtr)
virtual void WriteOtherEnd(TTypeInfo typeInfo) override
virtual void WriteNull(void) override
MLIOVIR void WriteContainer(const CContainerTypeInfo *containerType, TConstObjectPtr containerPtr)
virtual void BeginNamedType(TTypeInfo namedTypeInfo)
void SetNotag(bool set=true)
virtual void WriteBitString(const CBitString &obj) override
virtual void EndChoice(void) override
void WriteDouble2(double data, unsigned digits)
TFrame & FetchFrameFromTop(size_t index)
virtual void EndOfWrite(void) override
virtual void WriteSeparator(void) override
virtual void EndNamedType(void)
void WriteObject(const CConstObjectInfo &object)
deque< string > m_NsPrefixes
string GetDefaultSchemaNamespace(void)
Get default value of namespace name of generated DTD documents.
void CloseTagIfNamed(TTypeInfo type)
virtual void BeginContainerElement(TTypeInfo elementType) override
void Write(const CConstObjectInfo &object)
virtual void CopyString(CObjectIStream &in, EStringType type=eStringTypeVisible) override
ERealValueFormat
formatting of values of type 'real' ('double')
void EndArrayElement(void)
void WriteEncodedChar(const char *&src, EStringType type=eStringTypeVisible)
static TTypeInfo GetContainerElementTypeInfo(TTypeInfo typeInfo)
bool GetReferenceSchema(void) const
Get Schema referencing parameter.
#define END_OBJECT_FRAME()
size_t GetStackDepth(void) const
CObjectIStream & In(void) const
virtual ~CObjectOStreamXml(void)
Destructor.
virtual void CopyAnyContentObject(CObjectIStream &in) override
virtual void BeginClass(const CClassTypeInfo *classInfo) override
virtual void EndChoiceVariant(void) override
bool WillHaveName(TTypeInfo elementType)
string GetModuleName(TTypeInfo type)
void OpenTagIfNamed(TTypeInfo type)
ESpecialCaseWrite m_SpecialCaseWrite
const TFrame & TopFrame(void) const
TTypeInfo GetTypeInfo(void) const
virtual void WriteInt8(Int8 data) override
ERealValueFormat GetRealValueFormat(void) const
Get formatting of values of type real.
char x_FixCharsSubst(void) const
MLIOVIR void CopyNamedType(TTypeInfo namedTypeInfo, TTypeInfo typeInfo, CObjectStreamCopier &copier)
virtual void EndOfWrite(void)
MLIOVIR void WriteClass(const CClassTypeInfo *objectType, TConstObjectPtr objectPtr)
void WriteBase64Bytes(const char *bytes, size_t length)
void BeginArrayElement(TTypeInfo elementType)
virtual void CopyBitString(CObjectIStream &in) override
bool StackIsEmpty(void) const
const CMemberId & GetMemberId(void) const
void WriteChoiceContents(const CChoiceTypeInfo *choiceType, TConstObjectPtr choicePtr)
virtual void WriteChar(char data) override
virtual void CopyEnum(const CEnumeratedTypeValues &values, CObjectIStream &in) override
virtual void WriteFileHeader(TTypeInfo type) override
#define BEGIN_OBJECT_2FRAMES_OF2(Stream, Type, Arg)
void CloseStackTag(size_t level)
virtual void WriteNullPointer(void) override
bool HasMemberId(void) const
virtual void WriteFloat(float data) override
virtual void EndClass(void) override
void x_EndNamespace(const string &ns_name)
EEncoding GetEncoding(void) const
Get XML character encoding.
EEncoding GetDefaultStringEncoding(void) const
Get default encoding of 'string' objects.
virtual void WriteUint8(Uint8 data) override
virtual void WriteChars(const CharBlock &block, const char *chars, size_t length) override
virtual void WriteUint4(Uint4 data) override
void x_EndTypeNamespace(void)
virtual void WriteObjectReference(TObjectIndex index) override
string GetDTDFilePrefix(void) const
Get DTD or schema file prefix.
bool x_ProcessTypeNamespace(TTypeInfo type)
void OpenTag(const string &name)
EFrameType GetFrameType(void) const
string GetSeparator(void) const
Get separator.
virtual void WriteCString(const char *str) override
virtual void WriteInt4(Int4 data) override
bool x_BeginNamespace(const string &ns_name, const string &ns_prefix)
void SetEncoding(EEncoding enc)
Set XML character encoding.
MLIOVIR void WriteNamedType(TTypeInfo namedTypeInfo, TTypeInfo typeInfo, TConstObjectPtr object)
bool m_WriteNamedIntegersByValue
virtual void WriteOtherBegin(TTypeInfo typeInfo) override
virtual void EndContainerElement(void) override
void SetEnforcedStdXml(bool set=true)
Set up scope prefixes handling.
void SetRealValueFormat(ERealValueFormat fmt)
Set formatting of values of type real The method is provided for convenience only.
virtual void BeginNamedType(TTypeInfo namedTypeInfo) override
ETagAction m_LastTagAction
void SelfCloseTagEnd(void)
virtual void WriteStringStore(const string &s) override
static CObjectOStream * OpenObjectOStreamXml(CNcbiOstream &out, EOwnership deleteOut)
virtual void SetFormattingFlags(TSerial_Format_Flags flags)
Set output formatting flags.
void CheckStdXml(TTypeInfo classType)
virtual void BeginContainer(const CContainerTypeInfo *containerType) override
void OpenTagEndBack(void)
CObjectOStreamXml(CNcbiOstream &out, bool deleteOut)
Constructor.
ESerialVerifyData GetVerifyData(void) const
Get output data verification parameter.
void SetSpecialCaseWrite(ESpecialCaseWrite how)
virtual string GetPosition(void) const override
Get current stream position as string.
virtual void BeginChoiceVariant(const CChoiceTypeInfo *choiceType, const CMemberId &id) override
@ fIllegalCall
Illegal in a given context function call.
@ fInvalidData
Output data is incorrect.
@ fUnassigned
Mandatory object member is unassigned Normally this results in throwing CUnassignedMember exception.
@ eRealFixedFormat
use 'f' formatting type
uint8_t Uint1
1-byte (8-bit) unsigned integer
int32_t Int4
4-byte (32-bit) signed integer
uint32_t Uint4
4-byte (32-bit) unsigned integer
int64_t Int8
8-byte (64-bit) signed integer
uint64_t Uint8
8-byte (64-bit) unsigned integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
void IncIndentLevel(size_t step=2)
void SetBackLimit(size_t limit)
size_t GetLine(void) const
void PutString(const char *str, size_t length)
void PutEol(bool indent=true)
void DecIndentLevel(size_t step=2)
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
NCBI_NS_STD::string::size_type SIZE_TYPE
static string SizetToString(size_t value, TNumToStringFlags flags=0, int base=10)
Convert size_t to string.
static string DoubleToString(double value, int precision=-1, TNumToStringFlags flags=0)
Convert double to string.
static SIZE_TYPE DoubleToStringPosix(double value, unsigned int precision, char *buf, SIZE_TYPE buf_size)
Convert double to string with specified precision and put the result into a character buffer,...
static string EncodingToString(EEncoding encoding)
Give Encoding name as string.
char32_t TUnicodeSymbol
Unicode character.
static char SymbolToChar(TUnicodeSymbol sym, EEncoding encoding)
Convert Unicode code point into encoded character.
static CStringUTF8 AsUTF8(const CTempString &src, EEncoding encoding, EValidate validate=eNoValidate)
Convert into UTF8 from a C/C++ string.
static TUnicodeSymbol CharToSymbol(char ch, EEncoding encoding)
Convert encoded character into Unicode.
static TUnicodeSymbol Decode(const char *&src)
Convert sequence of UTF8 code units into Unicode code point.
@ fDoublePosix
DoubleToString*(): Use C locale for double conversions.
const string & GetName(void) const
Get name of this type.
bool HasNamespaceName(void) const
Check if data type has namespace name.
const CItemsInfo & GetItems(void) const
EDataSpec GetDataSpec(void) const
ETypeFamily GetTypeFamily(void) const
const string & GetNamespaceName(void) const
Get namespace name.
TMemberIndex GetIndex(TConstObjectPtr object) const
const CMemberInfo * GetMemberInfo(TMemberIndex index) const
const CVariantInfo * GetVariantInfo(TMemberIndex index) const
const CItemInfo * GetItemInfo(const string &name) const
bool Implicit(void) const
size_t GetCodeVersion(void) const
ENsQualifiedMode IsNsQualified(void) const
Get namespace 'qualified' property.
TConstObjectPtr GetElementPtr(const CConstIterator &it) const
bool InitIterator(CConstIterator &it, TConstObjectPtr containerPtr) const
bool NextElement(CConstIterator &it) const
TConstObjectPtr GetObjectPointer(TConstObjectPtr object) const
bool IsFullAlias(void) const
TTypeInfo GetElementType(void) const
bool IsImplicitNonEmpty(void) const
enum ENcbiOwnership EOwnership
Ownership relations between objects.
size_t serialize(const BV &bv, unsigned char *buf, bm::word_t *temp_block=0, unsigned serialization_flags=0)
Saves bitvector into memory.
unsigned int
A callback function used to compare two keys in a database.
Definition of all error codes used in serial libraries (xser.lib, xcser.lib).
void aligned_free(void *ptr) BMNOEXCEPT
Aligned free.
void * aligned_new_malloc(size_t size)
Aligned malloc (unlike classic malloc it throws bad_alloc exception)
const unsigned set_block_alloc_size
const GenericPointer< typename T::ValueType > T2 value
static const BitmapCharRec *const chars[]
std::istream & in(std::istream &in_, double &x_)
const char * sm_DefaultSchemaNamespace
static string GetPublicModuleName(TTypeInfo type)
const char * sm_DefaultNamespacePrefix
static const char * s_SchemaInstanceNamespace
static const char *const HEX
static SLJIT_INLINE sljit_ins st(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)