📄 objistrasn.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: objistrasn.cpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 19:40:57 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.92 * PRODUCTION * =========================================================================== *//* $Id: objistrasn.cpp,v 1000.3 2004/06/01 19:40:57 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 !!!*/#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <corelib/ncbiutil.hpp>#include <serial/objistrasn.hpp>#include <serial/member.hpp>#include <serial/enumvalues.hpp>#include <serial/memberlist.hpp>#include <serial/objhook.hpp>#include <serial/classinfo.hpp>#include <serial/choice.hpp>#include <serial/continfo.hpp>#include <serial/objistrimpl.hpp>#include <math.h>#if !defined(DBL_MAX_10_EXP) || !defined(FLT_MAX)# include <float.h>#endifBEGIN_NCBI_SCOPECObjectIStream* CObjectIStream::CreateObjectIStreamAsn(void){ return new CObjectIStreamAsn();}CObjectIStreamAsn::CObjectIStreamAsn(EFixNonPrint how) : CObjectIStream(eSerial_AsnText), m_FixMethod(how){}CObjectIStreamAsn::CObjectIStreamAsn(CNcbiIstream& in, EFixNonPrint how) : CObjectIStream(eSerial_AsnText), m_FixMethod(how){ Open(in);}CObjectIStreamAsn::CObjectIStreamAsn(CNcbiIstream& in, bool deleteIn, EFixNonPrint how) : CObjectIStream(eSerial_AsnText), m_FixMethod(how){ Open(in, deleteIn);}string CObjectIStreamAsn::GetPosition(void) const{ return "line "+NStr::UIntToString(m_Input.GetLine());}inlinebool CObjectIStreamAsn::FirstIdChar(char c){ return isalpha(c) || c == '_';}inlinebool CObjectIStreamAsn::IdChar(char c){ return isalnum(c) || c == '_' || c == '.';}inlinechar CObjectIStreamAsn::GetChar(void){ return m_Input.GetChar();}inlinechar CObjectIStreamAsn::PeekChar(void){ return m_Input.PeekChar();}inlinevoid CObjectIStreamAsn::SkipEndOfLine(char c){ m_Input.SkipEndOfLine(c);}inlinechar CObjectIStreamAsn::SkipWhiteSpaceAndGetChar(void){ char c = SkipWhiteSpace(); m_Input.SkipChar(); return c;}inlinechar CObjectIStreamAsn::GetChar(bool skipWhiteSpace){ return skipWhiteSpace? SkipWhiteSpaceAndGetChar(): m_Input.GetChar();}inlinechar CObjectIStreamAsn::PeekChar(bool skipWhiteSpace){ return skipWhiteSpace? SkipWhiteSpace(): m_Input.PeekChar();}inlinebool CObjectIStreamAsn::GetChar(char expect, bool skipWhiteSpace){ if ( PeekChar(skipWhiteSpace) != expect ) { return false; } m_Input.SkipChar(); return true;}void CObjectIStreamAsn::Expect(char expect, bool skipWhiteSpace){ if ( !GetChar(expect, skipWhiteSpace) ) { string msg("\'"); msg += expect; msg += "' expected"; ThrowError(fFormatError, msg); }}bool CObjectIStreamAsn::Expect(char choiceTrue, char choiceFalse, bool skipWhiteSpace){ char c = GetChar(skipWhiteSpace); if ( c == choiceTrue ) { return true; } else if ( c == choiceFalse ) { return false; } m_Input.UngetChar(c); string msg("\'"); msg += choiceTrue; msg += "' or '"; msg += choiceFalse; msg += "' expected"; ThrowError(fFormatError, msg); return false;}char CObjectIStreamAsn::SkipWhiteSpace(void){ try { // catch CEofException for ( ;; ) { char c = m_Input.SkipSpaces(); switch ( c ) { case '\t': m_Input.SkipChar(); continue; case '\r': case '\n': m_Input.SkipChar(); SkipEndOfLine(c); continue; case '-': // check for comments if ( m_Input.PeekChar(1) != '-' ) { return '-'; } m_Input.SkipChars(2); // skip comments SkipComments(); continue; default: return c; } } } catch (CEofException& e) { // There should be no eof here, report as an error if (GetStackDepth() < 2) { throw; } else { ThrowError(fEOF, e.what()); } } return '\0';}void CObjectIStreamAsn::SkipComments(void){ try { for ( ;; ) { char c = GetChar(); switch ( c ) { case '\r': case '\n': SkipEndOfLine(c); return; case '-': c = GetChar(); switch ( c ) { case '\r': case '\n': SkipEndOfLine(c); return; case '-': return; } continue; default: continue; } } } catch ( CEofException& /* ignored */ ) { return; }}CLightString CObjectIStreamAsn::ScanEndOfId(bool isId){ if ( isId ) { for ( size_t i = 1; ; ++i ) { char c = m_Input.PeekCharNoEOF(i); if ( !IdChar(c) && (c != '-' || !IdChar(m_Input.PeekChar(i + 1))) ) { const char* ptr = m_Input.GetCurrentPos(); m_Input.SkipChars(i); return CLightString(ptr, i); } } } return CLightString();}CLightString CObjectIStreamAsn::ReadTypeId(char c){ if ( c == '[' ) { for ( size_t i = 1; ; ++i ) { switch ( m_Input.PeekChar(i) ) { case '\r': case '\n': ThrowError(fFormatError, "end of line: expected ']'"); break; case ']': { const char* ptr = m_Input.GetCurrentPos(); m_Input.SkipChars(i); return CLightString(ptr + 1, i - 2); } } } } else { return ScanEndOfId(FirstIdChar(c)); }}CLightString CObjectIStreamAsn::ReadNumber(void){ char c = SkipWhiteSpace(); if ( c != '-' && c != '+' && !isdigit(c) ) ThrowError(fFormatError, "invalid number"); for ( size_t i = 1; ; ++i ) { c = m_Input.PeekChar(i); if ( !isdigit(c) ) { const char* ptr = m_Input.GetCurrentPos(); m_Input.SkipChars(i); return CLightString(ptr, i); } }}inlineCLightString CObjectIStreamAsn::ReadUCaseId(char c){ return ScanEndOfId(isupper(c) != 0);}inlineCLightString CObjectIStreamAsn::ReadLCaseId(char c){ return ScanEndOfId(islower(c) != 0);}inlineCLightString CObjectIStreamAsn::ReadMemberId(char c){ if ( c == '[' ) { for ( size_t i = 1; ; ++i ) { switch ( m_Input.PeekChar(i) ) { case '\r': case '\n': ThrowError(fFormatError, "end of line: expected ']'"); break; case ']': { const char* ptr = m_Input.GetCurrentPos(); m_Input.SkipChars(++i); return CLightString(ptr + 1, i - 2); } } } } else { return ScanEndOfId(islower(c) != 0); }}TMemberIndex CObjectIStreamAsn::GetMemberIndex (const CClassTypeInfo* classType, const CLightString& id){ TMemberIndex idx; if (id.GetLength() > 0 && isdigit(id.GetString()[0])) { idx = classType->GetMembers().Find (CMemberId::TTag(NStr::StringToInt(id))); } else { idx = classType->GetMembers().Find(id); } return idx;}TMemberIndex CObjectIStreamAsn::GetMemberIndex (const CClassTypeInfo* classType, const CLightString& id, const TMemberIndex pos){ TMemberIndex idx; if (id.GetLength() > 0 && isdigit(id.GetString()[0])) { idx = classType->GetMembers().Find (CMemberId::TTag(NStr::StringToInt(id)), pos); } else { idx = classType->GetMembers().Find(id, pos); } return idx;}TMemberIndex CObjectIStreamAsn::GetChoiceIndex (const CChoiceTypeInfo* choiceType, const CLightString& id){ TMemberIndex idx; if (id.GetLength() > 0 && isdigit(id.GetString()[0])) { idx = choiceType->GetVariants().Find (CMemberId::TTag(NStr::StringToInt(id))); } else { idx = choiceType->GetVariants().Find(id); } return idx;}void CObjectIStreamAsn::ReadNull(void){ if ( SkipWhiteSpace() == 'N' && m_Input.PeekCharNoEOF(1) == 'U' && m_Input.PeekCharNoEOF(2) == 'L' && m_Input.PeekCharNoEOF(3) == 'L' && !IdChar(m_Input.PeekCharNoEOF(4)) ) { m_Input.SkipChars(4); } else ThrowError(fFormatError, "'NULL' expected");}void CObjectIStreamAsn::ReadAnyContent(string& value){ char to = GetChar(true); value += to; if (to == '{') { to = '}'; } else if (to == '\"') { } else { to = '\0'; } bool space = false; for (char c = m_Input.PeekChar(); ; c = m_Input.PeekChar()) { if (to != '\"') { if (isspace(c)) { if (space) { m_Input.SkipChar(); continue; } c = ' '; space = true; } else { space = false;; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -