📄 objistrxml.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: objistrxml.cpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 19:41:03 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.61 * PRODUCTION * =========================================================================== *//* $Id: objistrxml.cpp,v 1000.3 2004/06/01 19:41:03 gouriano Exp $* ===========================================================================** 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:* !!! PUT YOUR DESCRIPTION HERE !!!** ---------------------------------------------------------------------------* $Log: objistrxml.cpp,v $* Revision 1000.3 2004/06/01 19:41:03 gouriano* PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.61** Revision 1.61 2004/05/19 17:26:19 gouriano* Corrected serialization of containers when the code was generated by DTD** Revision 1.60 2004/05/17 21:03:03 gorelenk* Added include of PCH ncbi_pch.hpp** Revision 1.59 2004/04/28 19:24:29 gouriano* Corrected reading of containers** Revision 1.58 2004/03/23 15:39:23 gouriano* Added setup options for skipping unknown data members** Revision 1.57 2004/03/05 20:29:38 gouriano* make it possible to skip unknown data fields** Revision 1.56 2004/01/30 20:29:56 gouriano* Corrected reading white spaces** Revision 1.55 2004/01/29 20:48:07 gouriano* Corrected handling of white spaces in XML tags: preserve insignificant* white spaces inside the tag.* Corrected reading of AnyContent object attributes and tags with empty content** Revision 1.54 2004/01/22 20:50:17 gouriano* corrected reading of undefined attributes, of boolean values, of tags with empty content** Revision 1.53 2004/01/12 16:52:58 gouriano* Corrected reading EMPTY tag value. Added skipping undescribed class member attributes.** Revision 1.52 2004/01/08 18:16:53 gouriano* correction when skipping end of line** Revision 1.51 2004/01/08 17:40:53 gouriano* Added encoding Windows-1252.* Corrected reading of containers.* Made it possible to read a choice variant, which is am empty container.** Revision 1.50 2003/11/26 19:59:40 vasilche* GetPosition() and GetDataFormat() methods now are implemented* in parent classes CObjectIStream and CObjectOStream to avoid* pure virtual method call in destructors.** Revision 1.49 2003/09/25 19:44:08 gouriano* Corrected serialization of AnyContent object's attributes** Revision 1.48 2003/09/16 14:48:36 gouriano* Enhanced AnyContent objects to support XML namespaces and attribute info items.** Revision 1.47 2003/08/25 15:59:09 gouriano* added possibility to use namespaces in XML i/o streams** Revision 1.46 2003/08/14 20:03:58 vasilche* Avoid memory reallocation when reading over preallocated object.* Simplified CContainerTypeInfo iterators interface.** Revision 1.45 2003/08/13 15:47:45 gouriano* implemented serialization of AnyContent objects** Revision 1.44 2003/07/02 13:01:29 gouriano* added ability to read/write XML files with reference to schema** Revision 1.43 2003/06/30 15:39:48 gouriano* added encoding (utf-8 or iso-8859-1)** Revision 1.42 2003/06/24 20:57:36 gouriano* corrected code generation and serialization of non-empty unnamed containers (XML)** Revision 1.41 2003/05/22 20:10:02 gouriano* added UTF8 strings** Revision 1.40 2003/05/16 18:02:18 gouriano* revised exception error messages** Revision 1.39 2003/05/05 20:09:10 gouriano* fixed "skipping" an object** Revision 1.38 2003/03/26 16:14:23 vasilche* Removed TAB symbols. Some formatting.** Revision 1.37 2003/02/07 16:09:22 gouriano* correction of GetContainerElementTypeFamily for the case of copying objects** Revision 1.36 2003/02/05 17:08:01 gouriano* added possibility to read/write objects generated from an ASN.1 spec as "standard" XML - without scope prefixes** Revision 1.35 2003/01/21 19:32:27 gouriano* corrected reading containers of primitive types** Revision 1.34 2002/12/26 19:32:33 gouriano* changed XML I/O streams to properly handle object copying** Revision 1.33 2002/12/17 19:04:32 gouriano* corrected reading/writing of character references** Revision 1.32 2002/12/13 21:50:42 gouriano* corrected reading of choices** Revision 1.31 2002/12/12 21:08:07 gouriano* implemented handling of complex XML containers** Revision 1.30 2002/11/26 22:09:02 gouriano* added HasMoreElements method,* added unnamed lists of sequences (choices) as container elements** Revision 1.29 2002/11/20 21:22:51 gouriano* corrected processing of unnamed sequences as choice variants** Revision 1.28 2002/11/19 19:48:52 gouriano* added support of XML attributes of choice variants** Revision 1.27 2002/11/15 20:33:12 gouriano* support of XML attributes of empty elements** Revision 1.26 2002/11/14 20:58:54 gouriano* added support of XML attribute lists** Revision 1.25 2002/10/25 14:49:27 vasilche* NCBI C Toolkit compatibility code extracted to libxcser library.* Serial streams flags names were renamed to fXxx.** Names of flags** Revision 1.24 2002/10/15 13:47:59 gouriano* modified to handle "standard" (generated from DTD) XML i/o** Revision 1.23 2002/09/26 18:11:01 gouriano* added more checks for MemberId** Revision 1.22 2002/09/25 19:37:36 gouriano* added the possibility of having no tag prefix in XML I/O streams** Revision 1.21 2001/11/13 20:53:36 grichenk* Fixed comments reading** Revision 1.20 2001/10/17 20:41:24 grichenk* Added CObjectOStream::CharBlock class** Revision 1.19 2001/08/08 18:35:09 grichenk* ReadTagData() -- added memory pre-allocation for long strings** Revision 1.18 2001/05/17 15:07:08 lavr* Typos corrected** Revision 1.17 2000/12/26 22:24:12 vasilche* Fixed errors of compilation on Mac.** Revision 1.16 2000/12/15 15:38:44 vasilche* Added support of Int8 and long double.* Enum values now have type Int4 instead of long.** Revision 1.15 2000/11/07 17:25:40 vasilche* Fixed encoding of XML:* removed unnecessary apostrophes in OCTET STRING* removed unnecessary content in NULL* Added module names to CTypeInfo and CEnumeratedTypeValues** Revision 1.14 2000/10/20 15:51:41 vasilche* Fixed data error processing.* Added interface for constructing container objects directly into output stream.* object.hpp, object.inl and object.cpp were split to* objectinfo.*, objecttype.*, objectiter.* and objectio.*.** Revision 1.13 2000/10/13 20:59:21 vasilche* Avoid using of ssize_t absent on some compilers.** Revision 1.12 2000/10/13 20:22:55 vasilche* Fixed warnings on 64 bit compilers.* Fixed missing typename in templates.** Revision 1.11 2000/10/03 17:22:44 vasilche* Reduced header dependency.* Reduced size of debug libraries on WorkShop by 3 times.* Fixed tag allocation for parent classes.* Fixed CObject allocation/deallocation in streams.* Moved instantiation of several templates in separate source file.** Revision 1.10 2000/09/29 16:18:23 vasilche* Fixed binary format encoding/decoding on 64 bit compulers.* Implemented CWeakMap<> for automatic cleaning map entries.* Added cleaning local hooks via CWeakMap<>.* Renamed ReadTypeName -> ReadFileHeader, ENoTypeName -> ENoFileHeader.* Added some user interface methods to CObjectIStream, CObjectOStream and* CObjectStreamCopier.** Revision 1.9 2000/09/18 20:00:24 vasilche* Separated CVariantInfo and CMemberInfo.* Implemented copy hooks.* All hooks now are stored in CTypeInfo/CMemberInfo/CVariantInfo.* Most type specific functions now are implemented via function pointers instead of virtual functions.** Revision 1.8 2000/09/01 13:16:18 vasilche* Implemented class/container/choice iterators.* Implemented CObjectStreamCopier for copying data without loading into memory.** Revision 1.7 2000/08/15 19:44:49 vasilche* Added Read/Write hooks:* CReadObjectHook/CWriteObjectHook for objects of specified type.* CReadClassMemberHook/CWriteClassMemberHook for specified members.* CReadChoiceVariantHook/CWriteChoiceVariant for specified choice variants.* CReadContainerElementHook/CWriteContainerElementsHook for containers.** Revision 1.6 2000/07/03 20:47:23 vasilche* Removed unused variables/functions.** Revision 1.5 2000/07/03 18:42:45 vasilche* Added interface to typeinfo via CObjectInfo and CConstObjectInfo.* Reduced header dependency.** Revision 1.4 2000/06/16 19:24:22 vasilche* Updated MSVC project.* Fixed error on MSVC with static const class member.** Revision 1.3 2000/06/16 16:31:20 vasilche* Changed implementation of choices and classes info to allow use of the same classes in generated and user written classes.** Revision 1.2 2000/06/07 19:45:59 vasilche* Some code cleaning.* Macros renaming in more clear way.* BEGIN_NAMED_*_INFO, ADD_*_MEMBER, ADD_NAMED_*_MEMBER.** Revision 1.1 2000/06/01 19:07:04 vasilche* Added parsing of XML data.** ===========================================================================*/#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <serial/objistrxml.hpp>#include <serial/enumvalues.hpp>#include <serial/objhook.hpp>#include <serial/classinfo.hpp>#include <serial/choice.hpp>#include <serial/ptrinfo.hpp>#include <serial/continfo.hpp>#include <serial/memberlist.hpp>#include <serial/memberid.hpp>BEGIN_NCBI_SCOPECObjectIStream* CObjectIStream::CreateObjectIStreamXml(){ return new CObjectIStreamXml();}CObjectIStreamXml::CObjectIStreamXml(void) : CObjectIStream(eSerial_Xml), m_TagState(eTagOutside), m_Attlist(false), m_StdXml(false), m_EnforcedStdXml(false), m_Encoding( eEncoding_Unknown ){}CObjectIStreamXml::~CObjectIStreamXml(void){}CObjectIStreamXml::EEncoding CObjectIStreamXml::GetEncoding(void) const{ return m_Encoding;}string CObjectIStreamXml::GetPosition(void) const{ return "line "+NStr::UIntToString(m_Input.GetLine());}void CObjectIStreamXml::SetEnforcedStdXml(bool set){ m_EnforcedStdXml = set; if (m_EnforcedStdXml) { m_StdXml = false; }}static inlinebool IsBaseChar(char c){ return c >= 'A' && c <='Z' || c >= 'a' && c <= 'z' || c >= '\xC0' && c <= '\xD6' || c >= '\xD8' && c <= '\xF6' || c >= '\xF8' && c <= '\xFF';}static inlinebool IsDigit(char c){ return c >= '0' && c <= '9';}static inlinebool IsIdeographic(char /*c*/){ return false;}static inlinebool IsLetter(char c){ return IsBaseChar(c) || IsIdeographic(c);}static inlinebool IsFirstNameChar(char c){ return IsLetter(c) || c == '_' || c == ':';}static inlinebool IsCombiningChar(char /*c*/){ return false;}static inlinebool IsExtender(char c){ return c == '\xB7';}static inlinebool IsNameChar(char c){ return IsFirstNameChar(c) || IsDigit(c) || c == '.' || c == '-' || IsCombiningChar(c) || IsExtender(c);}static inlinebool IsWhiteSpace(char c){ return c == ' ' || c == '\t' || c == '\n' || c == '\r';}static inlinebool IsEndOfTagChar(char c){ return c == '>' || c == '/';}char CObjectIStreamXml::SkipWS(void){ _ASSERT(InsideTag()); for ( ;; ) { char c = m_Input.SkipSpaces(); switch ( c ) { case '\t': m_Input.SkipChar(); continue; case '\r': case '\n': m_Input.SkipChar(); m_Input.SkipEndOfLine(c); continue; default: return c; } }}char CObjectIStreamXml::SkipWSAndComments(void){ _ASSERT(OutsideTag()); for ( ;; ) { char c = m_Input.SkipSpaces(); switch ( c ) { case '\t': m_Input.SkipChar(); continue; case '\r': case '\n': m_Input.SkipChar(); m_Input.SkipEndOfLine(c); continue; case '<': if ( m_Input.PeekChar(1) == '!' && m_Input.PeekChar(2) == '-' && m_Input.PeekChar(3) == '-' && m_Input.PeekChar(4) != '-' ) { // start of comment m_Input.SkipChars(4); for ( ;; ) { m_Input.FindChar('-'); if ( m_Input.PeekChar(1) == '-' ) { // -- if ( m_Input.PeekChar(2) == '>' ) { // --> m_Input.SkipChars(3); break; } else { // --[^>] ThrowError(fFormatError, "double dash '--' is not allowed in XML comments"); } } else { // -[^-] m_Input.SkipChars(2); } } continue; // skip the next WS or comment }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -