libsequence  1.9.5
AlignStream.hpp
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2003-2009 Kevin Thornton, krthornt[]@[]uci.edu
4 
5 Remove the brackets to email me.
6 
7 This file is part of libsequence.
8 
9 libsequence is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 libsequence is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 long with libsequence. If not, see <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #ifndef __ALIGNSTREAM_H__
25 #define __ALIGNSTREAM_H__
26 
27 #include <Sequence/Alignment.hpp>
28 #include <Sequence/Seq.hpp>
29 #include <type_traits>
30 #include <utility>
31 #include <string>
32 #include <stdexcept>
33 
58 namespace Sequence
59  {
60  template < typename T >
62  {
63  private:
64  //only compile these templates with types in the class hierarchy of Sequence::Seq. Allow pair<string,string>, too
65  static_assert( std::is_same< std::pair<std::string,std::string >, T>::value ||
66  std::is_base_of< Sequence::Seq, T>::value ,
67  "T must be std::pair<std::string,std::string> or derived from Sequence::Seq");
68 
73  std::vector < T >data;
74  public:
75  AlignStream(const std::vector<T> & _data);
76  AlignStream( std::vector<T> && _data);
77  AlignStream(const AlignStream<T> &a);
79  AlignStream(void){}
80  virtual ~ AlignStream (void);
81  typedef typename std::vector<T>::size_type size_type;
82  typedef typename std::vector<T>::reference reference;
83  typedef typename std::vector<T>::const_reference const_reference;
84 
85  bool empty() const
89  {
90  return data.empty();
91  }
92 
93  size_type size(void) const
97  {
98  return data.size();
99  }
100 
101  reference operator[](const size_type & i)
102 
106  {
107  return data[i];
108  }
109  const_reference operator[](const size_type & i) const
114  {
115  return data[i];
116  }
120  typedef typename std::vector<T>::iterator iterator;
124  typedef typename std::vector<T>::const_iterator const_iterator;
125  iterator begin();
126  iterator end();
127  const_iterator begin() const;
128  const_iterator end() const;
129  bool IsAlignment (void);
130  bool Gapped (void);
131  unsigned UnGappedLength (void);
132  void RemoveGaps (void);
133  void RemoveTerminalGaps (void);
134  std::vector < T >Trim ( std::vector < int >sites);
135  std::vector < T >TrimComplement ( std::vector < int >sites);
136  const std::vector< T > Data(void);
140  virtual std::istream & read (std::istream & s) = 0;
144  virtual std::ostream & print (std::ostream & s) const = 0;
145 
155  void assign(const_iterator beg,const_iterator end);
162  void assign( std::vector<T> && _data);
163  };
164 
165 
166  template < typename T >
167  std::istream & operator>> (std::istream & s, AlignStream < T > &c)
174  {
175  return c.read (s);
176  }
177 
178  template < typename T >
179  std::ostream & operator<< (std::ostream & s,const AlignStream < T > &c)
186  {
187  return c.print (s);
188  }
189 
190 }
191 #include <Sequence/bits/AlignStream.tcc>
192 #endif
class Sequence::Seq, an abstract base class for Sequences
std::vector< T >::const_iterator const_iterator
virtual std::istream & read(std::istream &s)=0
Virtual interface to alignment streams.
Definition: AlignStream.hpp:61
The namespace in which this library resides.
Declaration of namespace Sequence::Alignment.
virtual std::ostream & print(std::ostream &s) const =0
size_type size(void) const
Definition: AlignStream.hpp:93
std::istream & operator>>(std::istream &s, AlignStream< T > &c)
const_reference operator[](const size_type &i) const
reference operator[](const size_type &i)
void assign(const_iterator beg, const_iterator end)
std::vector< T >::iterator iterator