NCBI C++ Toolkit Cross Reference

  C++/include/serial/objostrxml.hpp


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
#ifndef OBJOSTRXML__HPP #define OBJOSTRXML__HPP /* $Id: objostrxml.hpp 64195 2014-08-25 17:29:04Z vasilche $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Author: Eugene Vasilchenko * * File Description: * Encode data object using XML format */ #include <corelib/ncbistd.hpp> #include <serial/objostr.hpp> #include <deque> /** @addtogroup ObjStreamSupport * * @{ */ BEGIN_NCBI_SCOPE ///////////////////////////////////////////////////////////////////////////// /// /// CObjectOStreamXml -- /// /// Encode serial data object using XML format class NCBI_XSERIAL_EXPORT CObjectOStreamXml : public CObjectOStream { public: /// Constructor. /// /// @param out /// Output stream /// @param deleteOut /// when TRUE, the output stream will be deleted automatically /// when the writer is deleted CObjectOStreamXml(CNcbiOstream& out, bool deleteOut); /// Destructor. virtual ~CObjectOStreamXml(void); /// Get current stream position as string. /// Useful for diagnostic and information messages. /// /// @return /// string virtual string GetPosition(void) const; /// Set XML character encoding /// /// @return /// Encoding void SetEncoding(EEncoding enc); /// Get XML character encoding /// /// @return /// Encoding EEncoding GetEncoding(void) const; /// Set default encoding of 'string' objects /// If XML data encoding is different, string will be converted to /// this encoding /// /// @param enc /// Encoding void SetDefaultStringEncoding(EEncoding enc); /// Get default encoding of 'string' objects /// /// @return /// Encoding EEncoding GetDefaultStringEncoding(void) const; /// Set up scope prefixes handling. /// Historically, using scope prefixes is the default for C++ data objects /// generated by ASN.1 specification. /// For objects generated by DTD, the default is NOT using prefixes. /// /// @param set /// When TRUE, the stream omits 'scope prefixes'. void SetEnforcedStdXml(bool set = true); /// Get scope prefixes handling parameter. /// /// @return /// TRUE (omit scope prefixes) or FALSE bool GetEnforcedStdXml(void) {return m_StdXml ? false : m_EnforcedStdXml;} /// Make generated XML document reference XML schema /// /// @param use_schema /// When TRUE, the generated document will reference Schema void SetReferenceSchema(bool use_schema = true); /// Get Schema referencing parameter /// /// @return /// TRUE or FALSE bool GetReferenceSchema(void) const; /// Make generated XML document reference DTD /// /// @param use_dtd /// When TRUE, the generated document will reference DTD void SetReferenceDTD(bool use_dtd = true); /// Get DTD referencing parameter /// /// @return /// TRUE or FALSE bool GetReferenceDTD(void) const; /// Put Schema location information into generated XML document /// /// @param use_loc /// When TRUE, the generated document will have schemaLocation attribute void SetUseSchemaLocation(bool use_loc = true); /// Get Schema location output parameter /// /// @return /// TRUE or FALSE bool GetUseSchemaLocation(void) const; /// Set default value of namespace name of generated DTD documents /// /// @param schema_ns /// namespace name void SetDefaultSchemaNamespace(const string& schema_ns); /// Get default value of namespace name of generated DTD documents /// /// @return /// namespace name string GetDefaultSchemaNamespace(void); /// Set DTD or schema file prefix. /// Reference to DTD or schema in XML document has the form /// [DTDFilePrefix][DTDFileName].[dtd|xsd] /// If "DTDFilePrefix" has never been set for this stream, then /// the global "DefaultDTDFilePrefix" will be used. /// If it has been set to any value (including empty string), then /// that value will be used. /// /// @param prefix /// File prefix void SetDTDFilePrefix(const string& prefix); /// Get DTD or schema file prefix. /// /// @return /// File prefix string GetDTDFilePrefix(void) const; /// Set default (global) DTD file prefix. /// /// @param prefix /// File prefix static void SetDefaultDTDFilePrefix(const string& prefix); /// Get default (global) DTD file prefix. /// /// @param prefix /// File prefix static string GetDefaultDTDFilePrefix(void); /// Set DTD or schema file name. /// Reference to DTD or schema in XML document has the form /// [DTDFilePrefix][DTDFileName].[dtd|xsd] /// If "DTDFileName" is not set or set to empty string for this stream, /// then module name (in ASN.1 sense) will be used as the file name. /// /// @param filename /// File name void SetDTDFileName(const string& filename); /// Get DTD or schema file name. /// /// @return /// File name string GetDTDFileName(void) const; /// Enable DTD public identifier. /// If disabled (it is ENABLED by default), only system identifier /// will be written in the output XML stream void EnableDTDPublicId(void); /// Disable DTD public identifier. /// If disabled (it is ENABLED by default), only system identifier /// will be written in the output XML stream void DisableDTDPublicId(void); /// Set DTD public identifier. /// If set to a non-empty string, the stream will write this into the /// output XML file. Otherwise the "default" public id /// will be generated /// /// @param publicId /// Public ID void SetDTDPublicId(const string& publicId); /// Get DTD public identifier. /// /// @return /// Public ID string GetDTDPublicId(void) const; /// formatting of values of type 'real' ('double') enum ERealValueFormat { eRealFixedFormat, ///< use 'f' formatting type eRealScientificFormat ///< use 'g' formatting type }; /// Get formatting of values of type real /// /// @return /// Formatting flag ERealValueFormat GetRealValueFormat(void) const; /// Set formatting of values of type real /// The method is provided for convenience only. /// /// @param fmt /// Formatting flag void SetRealValueFormat(ERealValueFormat fmt); /// Set output formatting flags /// /// @param flags /// Formatting flag virtual void SetFormattingFlags(TSerial_Format_Flags flags); virtual void WriteFileHeader(TTypeInfo type); virtual void EndOfWrite(void); protected: virtual void WriteBool(bool data); virtual void WriteChar(char data); virtual void WriteInt4(Int4 data); virtual void WriteUint4(Uint4 data); virtual void WriteInt8(Int8 data); virtual void WriteUint8(Uint8 data); virtual void WriteFloat(float data); virtual void WriteDouble(double data); void WriteDouble2(double data, unsigned digits); virtual void WriteCString(const char* str); virtual void WriteString(const string& s, EStringType type = eStringTypeVisible); virtual void WriteStringStore(const string& s); virtual void CopyString(CObjectIStream& in, EStringType type = eStringTypeVisible); virtual void CopyStringStore(CObjectIStream& in); virtual void WriteNullPointer(void); virtual void WriteObjectReference(TObjectIndex index); virtual void WriteOtherBegin(TTypeInfo typeInfo); virtual void WriteOtherEnd(TTypeInfo typeInfo); virtual void WriteOther(TConstObjectPtr object, TTypeInfo typeInfo); void WriteId(const string& str); void WriteNull(void); virtual void WriteAnyContentObject(const CAnyContentObject& obj); virtual void CopyAnyContentObject(CObjectIStream& in); virtual void WriteBitString(const CBitString& obj); virtual void CopyBitString(CObjectIStream& in); void WriteEscapedChar(char c); void WriteEncodedChar(const char*& src, EStringType type = eStringTypeVisible); virtual void WriteEnum(const CEnumeratedTypeValues& values, TEnumValueType value); virtual void CopyEnum(const CEnumeratedTypeValues& values, CObjectIStream& in); void WriteEnum(const CEnumeratedTypeValues& values, TEnumValueType value, const string& valueName); #ifdef VIRTUAL_MID_LEVEL_IO virtual void WriteNamedType(TTypeInfo namedTypeInfo, TTypeInfo typeInfo, TConstObjectPtr object); virtual void CopyNamedType(TTypeInfo namedTypeInfo, TTypeInfo typeInfo, CObjectStreamCopier& copier); virtual void WriteContainer(const CContainerTypeInfo* containerType, TConstObjectPtr containerPtr); virtual void WriteClass(const CClassTypeInfo* objectType, TConstObjectPtr objectPtr); virtual void WriteClassMember(const CMemberId& memberId, TTypeInfo memberType, TConstObjectPtr memberPtr); virtual bool WriteClassMember(const CMemberId& memberId, const CDelayBuffer& buffer); virtual void WriteClassMemberSpecialCase( const CMemberId& memberId, TTypeInfo memberType, TConstObjectPtr memberPtr, ESpecialCaseWrite how); #endif void WriteContainerContents(const CContainerTypeInfo* containerType, TConstObjectPtr containerPtr); void WriteChoiceContents(const CChoiceTypeInfo* choiceType, TConstObjectPtr choicePtr); // low level I/O virtual void BeginNamedType(TTypeInfo namedTypeInfo); virtual void EndNamedType(void); virtual void BeginContainer(const CContainerTypeInfo* containerType); virtual void EndContainer(void); virtual void BeginContainerElement(TTypeInfo elementType); virtual void EndContainerElement(void); void BeginArrayElement(TTypeInfo elementType); void EndArrayElement(void); void CheckStdXml(const CClassTypeInfoBase* classType); TTypeInfo GetRealTypeInfo(TTypeInfo typeInfo); ETypeFamily GetRealTypeFamily(TTypeInfo typeInfo); TTypeInfo GetContainerElementTypeInfo(TTypeInfo typeInfo); ETypeFamily GetContainerElementTypeFamily(TTypeInfo typeInfo); virtual void BeginClass(const CClassTypeInfo* classInfo); virtual void EndClass(void); virtual void BeginClassMember(const CMemberId& id); void BeginClassMember(TTypeInfo memberType, const CMemberId& id); virtual void EndClassMember(void); virtual void BeginChoice(const CChoiceTypeInfo* choiceType); virtual void EndChoice(void); virtual void BeginChoiceVariant(const CChoiceTypeInfo* choiceType, const CMemberId& id); virtual void EndChoiceVariant(void); virtual void WriteBytes(const ByteBlock& block, const char* bytes, size_t length); virtual void WriteChars(const CharBlock& block, const char* chars, size_t length); // Write current separator to the stream virtual void WriteSeparator(void); #if defined(NCBI_SERIAL_IO_TRACE) void TraceTag(const string& name); #endif private: void WriteBase64Bytes(const char* bytes, size_t length); void WriteBytes(const char* bytes, size_t length); void WriteString(const char* str, size_t length); void OpenTagStart(void); void OpenTagEnd(void); void OpenTagEndBack(void); void SelfCloseTagEnd(void); void CloseTagStart(void); void CloseTagEnd(void); void WriteTag(const string& name); void OpenTag(const string& name); void EolIfEmptyTag(void); void CloseTag(const string& name); void OpenStackTag(size_t level); void CloseStackTag(size_t level); void OpenTag(TTypeInfo type); void CloseTag(TTypeInfo type); void OpenTagIfNamed(TTypeInfo type); void CloseTagIfNamed(TTypeInfo type); void PrintTagName(size_t level); bool WillHaveName(TTypeInfo elementType); string GetModuleName(TTypeInfo type); bool x_IsStdXml(void) {return m_StdXml || m_EnforcedStdXml;} void x_WriteClassNamespace(TTypeInfo type); bool x_ProcessTypeNamespace(TTypeInfo type); void x_EndTypeNamespace(void); bool x_BeginNamespace(const string& ns_name, const string& ns_prefix); void x_EndNamespace(const string& ns_name); void x_SpecialCaseWrite(void); char x_VerifyChar(char); enum ETagAction { eTagOpen, eTagClose, eTagSelfClosed, eAttlistTag }; ETagAction m_LastTagAction; bool m_EndTag; // DTD file name and prefix bool m_UseDefaultDTDFilePrefix; string m_DTDFilePrefix; string m_DTDFileName; bool m_UsePublicId; string m_PublicId; static string sm_DefaultDTDFilePrefix; bool m_Attlist; bool m_StdXml; bool m_EnforcedStdXml; ERealValueFormat m_RealFmt; EEncoding m_Encoding; EEncoding m_StringEncoding; bool m_UseXmlDecl; bool m_UseSchemaRef; bool m_UseSchemaLoc; bool m_UseDTDRef; string m_DefaultSchemaNamespace; string m_CurrNsPrefix; map<string,string> m_NsNameToPrefix; map<string,string> m_NsPrefixToName; deque<string> m_NsPrefixes; bool m_SkipIndent; bool m_SkipNextTag; }; /* @} */ #include <serial/impl/objostrxml.inl> END_NCBI_SCOPE #endif

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.