ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/PrimerMatch/char_io.h
Revision: 1.1.1.1 (vendor branch)
Committed: Wed Dec 22 21:37:17 2004 UTC (11 years, 11 months ago) by nje01
Branch: MAIN
CVS Tags: HEAD, RELEASE-20041222, HEAD
Changes since 1.1: +0 -0 lines
Log Message:
Initial primer_match import

Line File contents
1 /**************************************************************************
2 * This code is part of the supporting infrastructure for ATA Mapper.
3 * Copyright (C) 2002,2003,2004 Applera Corporation. All rights reserved.
4 * Author: Nathan Edwards
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received (LICENSE.txt) a copy of the GNU General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *************************************************************************/
20
21
22 #ifndef _IBPEP_CHAR_IO_H_
23 #define _IBPEP_CHAR_IO_H_
24
25 #include "mapFile.h"
26 #include "bufferedFile.h"
27 #include "fileStar.h"
28 #include "util.h"
29
30 #if !defined(NO_STD_NAMESPACE)
31 using namespace std;
32 #endif
33
34 class CharacterProducer {
35 public:
36 CharacterProducer() {};
37 virtual ~CharacterProducer() {};
38 virtual char getch()=0;
39 virtual unsigned char getnch()=0;
40 virtual char ch(unsigned char)=0;
41 virtual int nch(char)=0;
42 virtual unsigned int size() const =0;
43 virtual bool eof() const =0;
44 virtual FILE_POSITION_TYPE pos() const =0;
45 virtual void pos(FILE_POSITION_TYPE p) =0;
46 virtual void reset()=0;
47 virtual float progress() const =0;
48 };
49
50 class IStreamChars : public CharacterProducer {
51 private:
52 bool delstream;
53 std::istream & is_;
54 unsigned char cached_char;
55 public:
56 IStreamChars(const std::string & filename) : is_(*(new std::ifstream(filename.c_str()))) {
57 delstream = true;
58 cached_char = is_.get();
59 }
60 IStreamChars(std::istream & is) : is_(is) {
61 delstream = false;
62 cached_char = is_.get();
63 }
64 ~IStreamChars() {
65 if (delstream) {
66 delete (&is_);
67 }
68 }
69 char getch() { char tmp(cached_char); cached_char = is_.get(); return tmp; }
70 unsigned char getnch() { return (unsigned char) getch(); }
71 inline char ch(unsigned char nch) { return nch; }
72 inline int nch(char ch) { return ch; }
73 inline unsigned int size() const { return 256; }
74 bool eof() const { return is_.eof(); }
75 FILE_POSITION_TYPE pos() const { return ((FILE_POSITION_TYPE)(is_.tellg())-1); }
76 void pos(FILE_POSITION_TYPE p) { is_.clear(); is_.seekg(p); cached_char = is_.get();}
77 void reset() { is_.clear(); is_.seekg(0); }
78 float progress() const { return 0.0; }
79 };
80
81 class CharStarChars : public CharacterProducer {
82 const char *ptr_;
83 const char *p_;
84 public:
85 CharStarChars(const char *chars) : ptr_(chars), p_(chars) {}
86 ~CharStarChars() {}
87 inline char getch() { return *p_++; }
88 inline unsigned char getnch() { return *p_++; }
89 inline char ch(unsigned char nch) { return nch; }
90 inline int nch(char ch) { return ch; }
91 inline unsigned int size() const { return 256; }
92 inline bool eof() const { return (*p_=='\0'); }
93 FILE_POSITION_TYPE pos() const { return (p_-ptr_); }
94 void pos(FILE_POSITION_TYPE p) { p_ = ptr_+p; }
95 void reset() { p_ = ptr_; }
96 float progress() const {
97 return 0;
98 }
99 };
100
101 class MapFileChars : public MapFile, public CharacterProducer {
102 public:
103 MapFileChars(const char *filename) : MapFile(filename) {}
104 ~MapFileChars() {}
105 inline char getch() { return (char) MapFile::getCharacter(); }
106 inline unsigned char getnch() { return MapFile::getCharacter(); }
107 inline char ch(unsigned char nch) { return nch; }
108 inline int nch(char ch) { return ch; }
109 inline unsigned int size() const { return 256; }
110 inline bool eof() const { return MapFile::endOfFile(); }
111 FILE_POSITION_TYPE pos() const { return MapFile::getPos(); }
112 void pos(FILE_POSITION_TYPE p) { MapFile::setPos(p); }
113 void reset() { MapFile::reset(); }
114 float progress() const {
115 return ((float)MapFile::getPos())/MapFile::map_size();
116 }
117 };
118
119 class BufferedFileChars : public BufferedFile, public CharacterProducer {
120 public:
121 BufferedFileChars(std::string const & filename) : BufferedFile(filename) {}
122 ~BufferedFileChars() {}
123 inline char getch() { return (char) BufferedFile::getCharacter(); }
124 inline unsigned char getnch() { return BufferedFile::getCharacter(); }
125 inline char ch(unsigned char nch) { return nch; }
126 inline int nch(char ch) { return ch; }
127 inline unsigned int size() const { return 256; }
128 inline bool eof() const { return BufferedFile::isEndOfFile(); }
129 FILE_POSITION_TYPE pos() const { return BufferedFile::getPos(); }
130 void pos(FILE_POSITION_TYPE p) { BufferedFile::setPos(p); }
131 void reset() { BufferedFile::reset(); }
132 float progress() const {
133 return ((float)BufferedFile::getPos())/BufferedFile::getSize();
134 }
135 };
136
137 class FileStarChars : public FileStarFile, public CharacterProducer {
138 public:
139 FileStarChars(std::string const & filename) : FileStarFile(filename) {}
140 ~FileStarChars() {}
141 inline char getch() { return (char) FileStarFile::getCharacter(); }
142 inline unsigned char getnch() { return FileStarFile::getCharacter(); }
143 inline char ch(unsigned char nch) { return nch; }
144 inline int nch(char ch) { return ch; }
145 inline unsigned int size() const { return 256; }
146 inline bool eof() const { return FileStarFile::isEndOfFile(); }
147 FILE_POSITION_TYPE pos() const { return FileStarFile::getPos(); }
148 void pos(FILE_POSITION_TYPE p) { FileStarFile::setPos(p); }
149 void reset() { FileStarFile::reset(); }
150 float progress() const {
151 return ((float)FileStarFile::getPos())/FileStarFile::getSize();
152 }
153
154 };
155
156 class CompressedCharUtil {
157 public:
158 static unsigned int lcm(unsigned int, unsigned int);
159 };
160
161 // #include "char_io.t"
162
163 #endif