NCBI C++ ToolKit
sequence_istream.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: sequence_istream.hpp 84663 2018-11-27 18:22:00Z ucko $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Aleksandr Morgulis
27  *
28  * File Description:
29  * Header file for CSequenceIStream class.
30  *
31  */
32 
33 #ifndef C_SEQUENCE_I_STREAM_HPP
34 #define C_SEQUENCE_I_STREAM_HPP
35 
36 #include <memory>
37 #include <vector>
38 
39 #include <corelib/ncbiobj.hpp>
43 
45 BEGIN_SCOPE( blastdbindex )
46 
47 /** Class used to abstract reading nucleotide sequences from
48  various sources.
49 */
51 {
52  protected:
53 
54  /** Type containing the sequence itself along with the
55  masking information.
56  */
57  struct CSeqData : public CObject
58  {
59  /** Type representing masked portions of a sequence. */
60  typedef std::vector< CConstRef< objects::CSeq_loc > > TMask;
61 
62  CRef< objects::CSeq_entry > seq_entry_; /**< Sequence data. */
63  mutable TMask mask_locs_; /**< Masked portion of the sequence. */
64 
65  /** Object constructor. */
67  : seq_entry_( null )
68  {}
69 
70  /** Conversion to bool.
71  @return true if the object contains a valid sequence;
72  false otherwise
73  */
74  operator bool() const { return seq_entry_.GetPointerOrNull() != 0; }
75  };
76 
77  public:
78 
79  /** Class representing error conditions in the sequence stream. */
81  {
82  public:
83 
84  /** Numerical error codes. */
85  enum EErrCode
86  {
87  eOpNotSupported, /**< The requested operation is not implemented
88  by this kind of sequence stream (e.g. the
89  stream can not rewind). */
90  eIO, /**< System io error. */
91  eParam /**< Parameter error. */
92  };
93 
94  /** Get the exception description string.
95  @return the exception description text
96  */
97  virtual const char * GetErrCodeString() const override
98  {
99  switch( GetErrCode() ) {
100  case eOpNotSupported:
101  return "stream operation is not supported";
102  case eIO:
103  return "I/O error";
104  case eParam:
105  return "database parameter error";
106  default: return CException::GetErrCodeString();
107  }
108  }
109 
111  };
112 
113  typedef CSeqData TSeqData; /**< Public alias for sequence info data type. */
114  typedef TSeqData::TMask TMask; /**< Public alias for type containing masking info. */
115  typedef Uint4 TStreamPos; /**< Type used to represent positions within a sequence stream. */
116 
117  /** Object destructor. */
118  virtual ~CSequenceIStream() {}
119 
120  /** Extract the next sequence from the stream.
121  (To be implemented by derived classes.)
122  @return Smart pointer to the sequence data. The contents
123  of the value is convertible to false if no more
124  sequences are available.
125  */
126  virtual CRef< TSeqData > next() = 0;
127 
128  /** Roll back to the start of the previousely read sequence.
129  (To be implemented by derived classes.).
130  If a derived class does not support this operation it
131  should throw CSequenceIStream_Exception with error code
132  eOpNotSupported.
133  */
134  virtual void putback() = 0;
135 };
136 
137 END_SCOPE( blastdbindex )
139 
140 #endif
141 
Defines to provide correct exporting from BLAST DLL in Windows.
#define NCBI_XBLAST_EXPORT
NULL operations for other cases.
Definition: blast_export.h:65
CObject –.
Definition: ncbiobj.hpp:180
Class representing error conditions in the sequence stream.
virtual const char * GetErrCodeString() const override
Get the exception description string.
NCBI_EXCEPTION_DEFAULT(CSequenceIStream_Exception, CException)
Class used to abstract reading nucleotide sequences from various sources.
Uint4 TStreamPos
Type used to represent positions within a sequence stream.
virtual CRef< TSeqData > next()=0
Extract the next sequence from the stream.
virtual void putback()=0
Roll back to the start of the previousely read sequence.
TSeqData::TMask TMask
Public alias for type containing masking info.
CSeqData TSeqData
Public alias for sequence info data type.
virtual ~CSequenceIStream()
Object destructor.
#define bool
Definition: bool.h:34
@ null
Definition: ncbimisc.hpp:646
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
Definition: ncbiexpt.cpp:444
TObjectType * GetPointerOrNull(void) THROWS_NONE
Get pointer value.
Definition: ncbiobj.hpp:986
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Type containing the sequence itself along with the masking information.
CRef< objects::CSeq_entry > seq_entry_
Sequence data.
CSeqData()
Object constructor.
TMask mask_locs_
Masked portion of the sequence.
std::vector< CConstRef< objects::CSeq_loc > > TMask
Type representing masked portions of a sequence.
Modified on Fri Sep 20 14:58:14 2024 by modify_doxy.py rev. 669887