string CException::ReportThis(TDiagPostFlags flags) const { CNcbiOstrstream os, osex; ReportStd(os, flags); ReportExtra(osex); if ( !IsOssEmpty(osex) ) { os << " (" << (string)CNcbiOstrstreamToString(osex) << ')'; } return CNcbiOstrstreamToString(os); }
CInvalidChoiceSelection::CInvalidChoiceSelection( const CDiagCompileInfo& diag_info, const CSerialObject* object, size_t currentIndex, size_t mustBeIndex, const char* const names[], size_t namesCount, EDiagSev severity) : CSerialException(diag_info, 0, (CSerialException::EErrCode) CException::eInvalid,"") { CNcbiOstrstream msg; const CChoiceTypeInfo* type = 0; if ( object ) { type = dynamic_cast<const CChoiceTypeInfo*>(object->GetThisTypeInfo()); } const char* cur_name = GetName(currentIndex, names, namesCount); const char* req_name = GetName(mustBeIndex, names, namesCount); if ( type ) { msg << "C" << SPrintIdentifier(type->GetAccessName()) << "::Get" << SPrintIdentifier(req_name) << "()"; msg << ": Invalid choice selection: " << type->GetAccessModuleName() <<"::"<< type->GetAccessName() << '.' << cur_name; } else { msg << "Invalid choice selection: " << cur_name << ". Expected: " << req_name; } x_Init(diag_info, CNcbiOstrstreamToString(msg), 0, severity); x_InitErrCode((CException::EErrCode)(CInvalidChoiceSelection::eFail)); }
void CAsnSizer::CloseDataStream(void) { m_OStream.reset(); string s = CNcbiOstrstreamToString(*m_MStream); m_AsnData.assign(s.data(), s.data() + s.size()); m_MStream.reset(); }
string CJsonNode::Repr(TReprFlags flags) const { CNcbiOstrstream oss; switch (GetNodeType()) { case CJsonNode::eObject: if (flags & fOmitOutermostBrackets) s_Repr_Object(oss, *this); else { oss << '{'; s_Repr_Object(oss, *this); oss << '}'; } break; case CJsonNode::eArray: if (flags & fOmitOutermostBrackets) s_Repr_Array(oss, *this); else { oss << '['; s_Repr_Array(oss, *this); oss << ']'; } break; case CJsonNode::eString: if (flags & fVerbatimIfString) return (static_cast<const SJsonStringNodeImpl*>( m_Impl.GetPointerOrNull())->m_String); /* FALL THROUGH */ default: s_Repr_Value(oss, *this); } return CNcbiOstrstreamToString(oss); }
void CDBL_Connection::x_SetExtraMsg(const I_BlobDescriptor& descr, size_t data_size) { CNcbiOstrstream oss; oss << "Data size: " << data_size; if (descr.DescriptorType() == CDBL_BLOB_DESCRIPTOR_TYPE_MAGNUM) { const CDBL_BlobDescriptor& dbldescr = static_cast<const CDBL_BlobDescriptor&>(descr); oss << " Destination: " << dbldescr.m_ObjName << " WHERE TEXTPTR(...) = 0x"; if ( !dbldescr.m_TxtPtr_is_NULL ) { char buffer[DBTXPLEN * 2]; size_t n = impl::binary_to_hex_string (buffer, sizeof(buffer), dbldescr.m_TxtPtr, DBTXPLEN, impl::fB2H_NoFinalNul | impl::fB2H_NoPrefix); oss << CTempString(buffer, n); } } else { const CDB_BlobDescriptor* dbdescr = dynamic_cast<const CDB_BlobDescriptor*>(&descr); if (dbdescr != NULL) { oss << " Destination: " << dbdescr->TableName() << '.' << dbdescr->ColumnName() << " WHERE " << dbdescr->SearchConditions(); } } string extra_msg = CNcbiOstrstreamToString(oss); SetExtraMsg(extra_msg); }
void CEmblFormatter::FormatLocus (const CLocusItem& locus, IFlatTextOStream& text_os) { static string embl_mol [14] = { "xxx", "DNA", "RNA", "RNA", "RNA", "RNA", "RNA", "RNA", "AA ", "DNA", "DNA", "RNA", "RNA", "RNA" }; const CBioseqContext& ctx = *locus.GetContext(); list<string> l; CNcbiOstrstream id_line; string hup = ctx.IsHup() ? " confidential" : " standard"; string topology = (locus.GetTopology() == CSeq_inst::eTopology_circular) ? "circular" : kEmptyStr; const string& mol = ctx.Config().UseEmblMolType() ? s_EmblMol[locus.GetBiomol()] : s_GenbankMol[locus.GetBiomol()]; id_line.setf(IOS_BASE::left, IOS_BASE::adjustfield); id_line << setw(9) << locus.GetName() << hup << "; " << topology << mol << "; " << locus.GetDivision() << "; " << locus.GetLength() << " BP."; Wrap(l, GetWidth(), "ID", CNcbiOstrstreamToString(id_line)); text_os.AddParagraph(l); }
blast::SDataLoaderConfig InitializeQueryDataLoaderConfiguration(bool query_is_protein, CRef<blast::CLocalDbAdapter> db_adapter) { SDataLoaderConfig retval(query_is_protein); retval.OptimizeForWholeLargeSequenceRetrieval(); /* Load the BLAST database into the data loader configuration for the query * so that if the query sequence(s) are specified as seq-ids, these can be * fetched from the BLAST database being searched */ if (db_adapter->IsBlastDb() && /* this is a BLAST database search */ retval.m_UseBlastDbs && /* the BLAST database data loader is requested */ (query_is_protein == db_adapter->IsProtein())) { /* the same database type is used for both queries and subjects */ // Make sure we don't add the same database more than once vector<string> default_dbs; NStr::Tokenize(retval.m_BlastDbName, " ", default_dbs); if (default_dbs.size() && (find(default_dbs.begin(), default_dbs.end(), db_adapter->GetDatabaseName()) == default_dbs.end())) { CNcbiOstrstream oss; oss << db_adapter->GetDatabaseName() << " " << retval.m_BlastDbName; retval.m_BlastDbName = CNcbiOstrstreamToString(oss); } } if (retval.m_UseBlastDbs) { _TRACE("Initializing query data loader to '" << retval.m_BlastDbName << "' (" << (query_is_protein ? "protein" : "nucleotide") << " BLAST database)"); } if (retval.m_UseGenbank) { _TRACE("Initializing query data loader to use GenBank data loader"); } return retval; }
void CTest::x_TestString(const char* str, int expects[]) { NcbiCout << "Testing string \"" << str << "\" CDiagFilter:\n"; CDiagFilter tester; tester.Fill(str); tester.Print(NcbiCout); NcbiCout << "-------\n"; for (unsigned int i = 0; i < m_Diags.size(); ++i ) { CNcbiOstrstream out; out << *m_Diags[i]; NcbiCout << setw(45) << (string) CNcbiOstrstreamToString(out) << " " << ( expects[i] ? "accept" : "reject" ) << " expected - "; if ( (tester.Check(*m_Diags[i], eDiag_Fatal) == eDiagFilter_Accept) == (expects[i] != 0)) { NcbiCout << "PASS"; } else { NcbiCout << "FAIL"; m_Result = 2; } NcbiCout << NcbiEndl; } NcbiCout << "--------------------------\n"; }
string CException::ReportAll(TDiagPostFlags flags) const { // invert the order stack<const CException*> pile; const CException* pex; for (pex = this; pex; pex = pex->GetPredecessor()) { pile.push(pex); } CNcbiOstrstream os; os << "NCBI C++ Exception:" << '\n'; for (; !pile.empty(); pile.pop()) { //indentation os << " "; os << pile.top()->ReportThis(flags) << '\n'; } if (sm_BkgrEnabled && !m_InReporter) { m_InReporter = true; CExceptionReporter::ReportDefault(CDiagCompileInfo(0, 0, NCBI_CURRENT_FUNCTION), "(background reporting)", *this, eDPF_Trace); m_InReporter = false; } return CNcbiOstrstreamToString(os); }
EMPTY_TEMPLATE inline string CDataValueTmpl<double>::GetXmlString(void) const { CNcbiOstrstream buffer; PrintASN( buffer, 0); return CNcbiOstrstreamToString(buffer); }
string CCompoundID::Dump() { CNcbiOstrstream sstr; s_DumpCompoundID(sstr, m_Impl, 0, " "); sstr << '\n' << NcbiEnds; return CNcbiOstrstreamToString(sstr); }
inline string ToString(CTestRangeMap::TRange range) { CNcbiOstrstream b; b << range; return CNcbiOstrstreamToString(b); }
/// SeqDb sequence source constructor /// @param retval BlastSeqSrc structure (already allocated) to populate [in] /// @param args Pointer to internal CSeqDbSrcNewArgs structure (@sa /// CSeqDbSrcNewArgs) [in] /// @return Updated seq_src structure (with all function pointers initialized static BlastSeqSrc* s_SeqDbSrcNew(BlastSeqSrc* retval, void* args) { _ASSERT(retval); _ASSERT(args); CSeqDbSrcNewArgs* seqdb_args = (CSeqDbSrcNewArgs*) args; _ASSERT(seqdb_args); TSeqDBData * datap = new TSeqDBData; try { bool is_protein = (seqdb_args->GetDbType() == 'p'); datap->seqdb.Reset(new CSeqDBExpert(seqdb_args->GetDbName(), (is_protein ? CSeqDB::eProtein : CSeqDB::eNucleotide))); datap->seqdb->SetIterationRange(seqdb_args->GetFirstOid(), seqdb_args->GetFinalOid()); datap->mask_algo_id = seqdb_args->GetMaskAlgoId(); datap->mask_type = seqdb_args->GetMaskType(); // Validate that the masking algorithm is supported if (datap->mask_algo_id > 0) { vector<int> supported_algorithms; datap->seqdb->GetAvailableMaskAlgorithms(supported_algorithms); if (find(supported_algorithms.begin(), supported_algorithms.end(), datap->mask_algo_id) == supported_algorithms.end()) { CNcbiOstrstream oss; oss << "Masking algorithm ID " << datap->mask_algo_id << " is " << "not supported in " << (is_protein ? "protein" : "nucleotide") << " '" << seqdb_args->GetDbName() << "' BLAST database"; string msg = CNcbiOstrstreamToString(oss); throw runtime_error(msg); } } } catch (const ncbi::CException& e) { _BlastSeqSrcImpl_SetInitErrorStr(retval, strdup(e.ReportThis(eDPF_ErrCodeExplanation).c_str())); } catch (const std::exception& e) { _BlastSeqSrcImpl_SetInitErrorStr(retval, strdup(e.what())); } catch (...) { _BlastSeqSrcImpl_SetInitErrorStr(retval, strdup("Caught unknown exception from CSeqDB constructor")); } /* Initialize the BlastSeqSrc structure fields with user-defined function * pointers and seqdb */ s_InitNewSeqDbSrc(retval, datap); return retval; }
ShowHideDomain(const Molecule *m, int d, int labelNum) : molecule(m), domainID(d) { CNcbiOstrstream oss; oss << indent << indent << m->identifier->pdbID; if (m->identifier->pdbChain != ' ') oss << '_' << (char) m->identifier->pdbChain; oss << " d" << labelNum; label = (string) CNcbiOstrstreamToString(oss); }
static string ToString (const objects::CSeq_id_Handle& id) { CNcbiOstrstream os_str; { auto_ptr<CObjectOStream> os(CObjectOStream::Open(eSerial_AsnText,os_str)); *os << *id.GetSeqId(); } return CNcbiOstrstreamToString(os_str); }
const string& CRequestContext::SetSessionID(void) { CNcbiOstrstream oss; CDiagContext& ctx = GetDiagContext(); oss << ctx.GetStringUID(ctx.UpdateUID()) << '_' << setw(4) << setfill('0') << GetRequestID() << "SID"; SetSessionID(CNcbiOstrstreamToString(oss)); return m_SessionID.GetOriginalString(); }
string s_AsString(const vector<E>& ids) { CNcbiOstrstream out; out << '{'; for ( auto& e : ids ) { out << ' ' << e; } out << " }"; return CNcbiOstrstreamToString(out); }
// A helper function to save the stream content into a file void saveStreamToFile( CNcbiOstrstream & stream, const std::string & fileName ) { std::ofstream f( fileName.c_str() ); f << string(CNcbiOstrstreamToString(stream)); f.close(); return; }
/// Verify the algorithm exists. If not, raise an exception void x_VerifyAlgorithmId(int algo_id) const { if (algo_id < 0 || algo_id >= (int)m_MaskNames.size()) { CNcbiOstrstream oss; oss << "Filtering algorithm ID " << algo_id << " does not exist." << endl; oss << GetAvailableAlgorithmNames(); NCBI_THROW(CSeqDBException, eArgErr, CNcbiOstrstreamToString(oss)); } }
void CNWAligner::SetSequences(const char* seq1, size_t len1, const char* seq2, size_t len2, bool verify) { if(!seq1 || !seq2) { NCBI_THROW(CAlgoAlignException, eBadParameter, g_msg_NullParameter); } if(verify) { size_t iErrPos1 = x_CheckSequence(seq1, len1); if(iErrPos1 < len1) { CNcbiOstrstream oss; oss << "The first sequence is inconsistent with the current " << "scoring matrix type. " << "Position = " << iErrPos1 << " Symbol = '" << seq1[iErrPos1] << "'"; string message = CNcbiOstrstreamToString(oss); NCBI_THROW(CAlgoAlignException, eInvalidCharacter, message); } size_t iErrPos2 = x_CheckSequence(seq2, len2); if(iErrPos2 < len2) { CNcbiOstrstream oss; oss << "The second sequence is inconsistent with the current " << "scoring matrix type. " << "Position = " << iErrPos2 << " Symbol = '" << seq2[iErrPos2] << "'"; string message = CNcbiOstrstreamToString(oss); NCBI_THROW(CAlgoAlignException, eInvalidCharacter, message); } } m_Seq1Vec.assign(&seq1[0], &seq1[0]+len1); m_Seq2Vec.assign(&seq2[0], &seq2[0]+len2); m_Seq1 = &m_Seq1Vec[0]; m_SeqLen1 = len1; m_Seq2 = &m_Seq2Vec[0]; m_SeqLen2 = len2; m_Transcript.clear(); }
// A helper function which compares a content of a stream in memory // with a file content on a disk bool compareStreamAndFile( CNcbiOstrstream & stream, const std::string & fileName ) { ifstream ifs( fileName.c_str() ); string fileContent; NcbiStreamToString(&fileContent, ifs); ifs.close(); return string(CNcbiOstrstreamToString(stream)) == fileContent; }
string CTypeStrings::NewInstance(const string& init, const string& place) const { CNcbiOstrstream s; s << "new"; if ( GetKind() == eKindObject ) { s << place; } s << ' ' << GetCType(CNamespace::KEmptyNamespace) << '(' << init << ')'; return CNcbiOstrstreamToString(s); }
/// Get the mask algorithsm id for a string id /// @param algo_name The algorithm string [in] /// @return the algorithm id corresponding to the string int GetAlgorithmId(const string & algo_name) const { for (unsigned int i=0; i<m_MaskNames.size(); ++i) { if (m_MaskNames[i] == algo_name) return i; } CNcbiOstrstream oss; oss << "Filtering algorithm " << algo_name << " does not exist." << endl; oss << GetAvailableAlgorithmNames(); NCBI_THROW(CSeqDBException, eArgErr, CNcbiOstrstreamToString(oss)); }
void CVDBMgr::x_Init(void) { if ( rc_t rc = VDBManagerMakeRead(x_InitPtr(), 0) ) { *x_InitPtr() = 0; NCBI_THROW2(CSraException, eInitFailed, "Cannot open VDBManager", rc); } uint32_t sdk_ver; if ( rc_t rc = VDBManagerVersion(*this, &sdk_ver) ) { NCBI_THROW2(CSraException, eInitFailed, "Cannot get VDBManager version", rc); } CKNSManager kns_mgr(CVFSManager(*this)); CNcbiOstrstream str; CNcbiApplication* app = CNcbiApplication::Instance(); if ( app ) { str << app->GetAppName() << ": " << app->GetVersion().Print() << "; "; } #if NCBI_PACKAGE str << "Package: " << NCBI_PACKAGE_NAME << ' ' << NCBI_PACKAGE_VERSION << "; "; #endif str << "C++ "; #ifdef NCBI_PRODUCTION_VER str << NCBI_PRODUCTION_VER << "/"; #endif #ifdef NCBI_DEVELOPMENT_VER str << NCBI_DEVELOPMENT_VER; #endif string prefix = CNcbiOstrstreamToString(str); KNSManagerSetUserAgent(kns_mgr, "%s; SRA Toolkit %V", prefix.c_str(), sdk_ver); // redirect VDB log to C++ Toolkit if ( s_GetDiagHandler() ) { KLogInit(); KLogLevelSet(klogDebug); KLogLibHandlerSet(VDBLogWriter, 0); } if ( app ) { string host = app->GetConfig().GetString("CONN", "HTTP_PROXY_HOST", kEmptyStr); int port = app->GetConfig().GetInt("CONN", "HTTP_PROXY_PORT", 0); if ( !host.empty() && port != 0 ) { if ( rc_t rc = KNSManagerSetHTTPProxyPath(kns_mgr, "%s:%d", host.c_str(), port) ) { NCBI_THROW2(CSraException, eInitFailed, "Cannot set KNSManager proxy parameters", rc); } KNSManagerSetHTTPProxyEnabled(kns_mgr, true); } } }
//------------------------------------------------------------------------------ void CSeqMaskerOstat::setUnitCount( Uint4 unit, Uint4 count ) { if( state != ulen && state != udata ) { CNcbiOstrstream ostr; ostr << "can not set unit count data in state " << state; string s = CNcbiOstrstreamToString(ostr); NCBI_THROW( CSeqMaskerOstatException, eBadState, s ); } doSetUnitCount( unit, count ); state = udata; }
/// Get the names of available mask algorithms as string string GetAvailableAlgorithmNames() const { CNcbiOstrstream retval; retval << endl << "Available filtering algorithm(s):" << endl << endl; retval << setw(14) << left << "Algorithm ID" << setw(40) << left << "Algorithm name" << endl; for (unsigned int id=0; id < m_MaskNames.size(); ++id) { retval << " " << setw(10) << left << id << setw(40) << left << m_MaskNames[id] << endl; } return CNcbiOstrstreamToString(retval); }
//------------------------------------------------------------------------------ void CSeqMaskerOstat::finalize() { if( state != udata && state != thres ) { CNcbiOstrstream ostr; ostr << "can not finalize data structure in state " << state; string s = CNcbiOstrstreamToString(ostr); NCBI_THROW( CSeqMaskerOstatException, eBadState, s ); } state = final; doFinalize(); }
//------------------------------------------------------------------------------ void CSeqMaskerOstat::setUnitSize( Uint1 us ) { if( state != start ) { CNcbiOstrstream ostr; ostr << "can not set unit size in state " << state; string s = CNcbiOstrstreamToString(ostr); NCBI_THROW( CSeqMaskerOstatException, eBadState, s ); } doSetUnitSize( us ); state = ulen; }
//------------------------------------------------------------------------------ void CSeqMaskerOstat::setParam( const string & name, Uint4 value ) { if( state != udata && state != thres ) { CNcbiOstrstream ostr; ostr << "can not set masking parameters in state " << state; string s = CNcbiOstrstreamToString(ostr); NCBI_THROW( CSeqMaskerOstatException, eBadState, s ); } doSetParam( name, value ); state = thres; }
string CSeq_id_Handle::AsString() const { CNcbiOstrstream os; if ( IsGi() ) { os << "gi|" << m_Packed; } else if ( m_Info ) { GetSeqId()->WriteAsFasta(os); } else { os << "unknown"; } return CNcbiOstrstreamToString(os); }