1 // -*-mode:c++; c-style:k&r; c-basic-offset:4;-*-
2 //
3 // Copyright 2010-2016, Julian Catchen <jcatchen@illinois.edu>
4 //
5 // This file is part of Stacks.
6 //
7 // Stacks is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Stacks is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with Stacks.  If not, see <http://www.gnu.org/licenses/>.
19 //
20 
21 #ifndef __INPUT_H__
22 #define __INPUT_H__
23 
24 #include <cerrno>
25 #include <zlib.h>
26 #include <cstdlib>
27 #include <cstring>
28 #include <string>
29 #include <vector>
30 #include <iostream>
31 #include <fstream>
32 
33 #include "constants.h"
34 #include "stacks.h"
35 
36 //
37 // The base class for all of our Input classes, such as Tsv, Fastq, Fasta, etc.
38 //
39 class Input {
40  public:
41     string   path;
42     ifstream fh;
43     char     line[max_len];
44 
45     Input();
46     Input(const char *path);
47     virtual ~Input();
48     virtual Seq *next_seq() = 0;
49     virtual int  next_seq(Seq &) = 0;
50 };
51 
52 int   parse_tsv(const char *, vector<string> &);
53 int   parse_ssv(const char *, vector<string> &);
54 int   read_line(ifstream &, char **, int *);
55 int   read_gzip_line(gzFile &, char **, int *);
56 bool  is_comment(const char *);
57 
58 inline
strip_whitespace(std::string & s)59 void strip_whitespace(std::string& s) {
60     auto right = s.end();
61     while (right != s.begin()) {
62         --right;
63         if (!std::isspace(*right)) {
64             ++right;
65             break;
66         }
67     }
68     s.erase(right, s.end());
69 
70     auto left = s.begin();
71     while (left != s.end() && std::isspace(*left))
72         ++left;
73     s.erase(s.begin(), left);
74 }
75 
76 #endif // __INPUT_H__
77