1 #ifndef OLIGOFAR_CSEQBUFFER__HPP
2 #define OLIGOFAR_CSEQBUFFER__HPP
3 
4 #include "defs.hpp"
5 #include "cseqcoding.hpp"
6 
7 #include <objmgr/seq_vector.hpp>
8 
9 BEGIN_OLIGOFAR_SCOPES
10 
11 class CSeqBuffer
12 {
13 public:
GetBeginPtr() const14     const char * GetBeginPtr() const { return m_begin; }
GetEndPtr() const15     const char * GetEndPtr() const { return m_end; }
16 
GetLength() const17     int GetLength() const { return m_end - m_begin; }
GetBeginPos() const18     int GetBeginPos() const { return m_bufferOffset; }
GetEndPos() const19     int GetEndPos() const { return m_bufferOffset + GetLength(); }
20 
21     CSeqBuffer( const objects::CSeqVector& vect, CSeqCoding::ECoding );
~CSeqBuffer()22     ~CSeqBuffer() { if( m_bufferAllocated ) delete [] m_begin; }
23 
GetCoding() const24     CSeqCoding::ECoding GetCoding() const { return m_coding; }
25 
26 protected:
27     char * m_begin;
28     char * m_end;
29     int  m_bufferOffset;
30     bool m_bufferAllocated;
31     CSeqCoding::ECoding m_coding;
32 
33 private:
CSeqBuffer(const CSeqBuffer &)34     explicit CSeqBuffer( const CSeqBuffer& ) { THROW( logic_error, "CSeqBuffer copy constructor is prohibited!" ); }
35     CSeqBuffer& operator = ( const CSeqBuffer& );
36 };
37 
38 ////////////////////////////////////////////////////////////////////////
39 // implementation
40 
CSeqBuffer(const objects::CSeqVector & vect,CSeqCoding::ECoding tgtCoding)41 inline CSeqBuffer::CSeqBuffer( const objects::CSeqVector& vect, CSeqCoding::ECoding tgtCoding )
42     : m_begin( new char[vect.size() + 1] ),
43       m_end( m_begin + vect.size() ),
44       m_bufferOffset( 0 ),
45       m_bufferAllocated( true ),
46       m_coding( tgtCoding )
47 {
48     string s;
49     vect.GetSeqData( 0, vect.size(), s );
50     const char * a = s.c_str();
51     char * b = m_begin;
52     switch( tgtCoding ) {
53     case CSeqCoding::eCoding_colorsp:
54     case CSeqCoding::eCoding_ncbi8na: while( b != m_end ) *b++ = CNcbi8naBase( CIupacnaBase( *a++ ) ); break;
55                                           /*
56     case CSeqCoding::eCoding_colorsp:
57         do {
58             CNcbi8naBase prev('\x0');
59             while( b != m_end ) {
60                 CNcbi8naBase n( CIupacnaBase( *a++ ) );
61                 *b++ = CColorTwoBase( prev, n );
62                 prev = n;
63             }
64         } while(0);
65         break;
66         */
67     default: THROW( logic_error, "CSeqBuffer supports only NCBI8na and Colorspace target encodings" );
68     }
69 }
70 
71 END_OLIGOFAR_SCOPES
72 
73 #endif
74