SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StreamingFile.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2011 Shashwat Lal Das
8  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
9  */
10 #ifndef __STREAMING_FILE_H__
11 #define __STREAMING_FILE_H__
12 
13 #include <shogun/lib/config.h>
14 #include <shogun/base/DynArray.h>
15 #include <shogun/lib/common.h>
16 #include <shogun/io/File.h>
17 #include <shogun/io/SGIO.h>
18 #include <shogun/lib/DataType.h>
20 #include <shogun/io/IOBuffer.h>
22 
23 #include <ctype.h>
24 #include <fcntl.h>
25 #include <unistd.h>
26 
27 namespace shogun
28 {
39  class CStreamingFile: public CSGObject
40  {
41  public:
44 
50  CStreamingFile(const char* fname, char rw='r');
51 
53  virtual ~CStreamingFile();
54 
58  void close()
59  {
60  buf->close_file();
61  }
62 
68  inline virtual bool is_seekable() { return false; }
69 
73  virtual void reset_stream() { SG_ERROR("Unable to reset the input stream!\n"); }
74 
84  virtual void get_vector(bool*& vector, int32_t& len);
85  virtual void get_vector(uint8_t*& vector, int32_t& len);
86  virtual void get_vector(char*& vector, int32_t& len);
87  virtual void get_vector(int32_t*& vector, int32_t& len);
88  virtual void get_vector(float32_t*& vector, int32_t& len);
89  virtual void get_vector(float64_t*& vector, int32_t& len);
90  virtual void get_vector(int16_t*& vector, int32_t& len);
91  virtual void get_vector(uint16_t*& vector, int32_t& len);
92  virtual void get_vector(int8_t*& vector, int32_t& len);
93  virtual void get_vector(uint32_t*& vector, int32_t& len);
94  virtual void get_vector(int64_t*& vector, int32_t& len);
95  virtual void get_vector(uint64_t*& vector, int32_t& len);
96  virtual void get_vector(floatmax_t*& vector, int32_t& len);
98 
108  virtual void get_vector_and_label
109  (bool*& vector, int32_t& len, float64_t& label);
110  virtual void get_vector_and_label
111  (uint8_t*& vector, int32_t& len, float64_t& label);
112  virtual void get_vector_and_label
113  (char*& vector, int32_t& len, float64_t& label);
114  virtual void get_vector_and_label
115  (int32_t*& vector, int32_t& len, float64_t& label);
116  virtual void get_vector_and_label
117  (float32_t*& vector, int32_t& len, float64_t& label);
118  virtual void get_vector_and_label
119  (float64_t*& vector, int32_t& len, float64_t& label);
120  virtual void get_vector_and_label
121  (int16_t*& vector, int32_t& len, float64_t& label);
122  virtual void get_vector_and_label
123  (uint16_t*& vector, int32_t& len, float64_t& label);
124  virtual void get_vector_and_label
125  (int8_t*& vector, int32_t& len, float64_t& label);
126  virtual void get_vector_and_label
127  (uint32_t*& vector, int32_t& len, float64_t& label);
128  virtual void get_vector_and_label
129  (int64_t*& vector, int32_t& len, float64_t& label);
130  virtual void get_vector_and_label
131  (uint64_t*& vector, int32_t& len, float64_t& label);
132  virtual void get_vector_and_label
133  (floatmax_t*& vector, int32_t& len, float64_t& label);
135 
145  virtual void get_string(bool*& vector, int32_t& len);
146  virtual void get_string(uint8_t*& vector, int32_t& len);
147  virtual void get_string(char*& vector, int32_t& len);
148  virtual void get_string(int32_t*& vector, int32_t& len);
149  virtual void get_string(float32_t*& vector, int32_t& len);
150  virtual void get_string(float64_t*& vector, int32_t& len);
151  virtual void get_string(int16_t*& vector, int32_t& len);
152  virtual void get_string(uint16_t*& vector, int32_t& len);
153  virtual void get_string(int8_t*& vector, int32_t& len);
154  virtual void get_string(uint32_t*& vector, int32_t& len);
155  virtual void get_string(int64_t*& vector, int32_t& len);
156  virtual void get_string(uint64_t*& vector, int32_t& len);
157  virtual void get_string(floatmax_t*& vector, int32_t& len);
159 
169  virtual void get_string_and_label
170  (bool*& vector, int32_t& len, float64_t& label);
171  virtual void get_string_and_label
172  (uint8_t*& vector, int32_t& len, float64_t& label);
173  virtual void get_string_and_label
174  (char*& vector, int32_t& len, float64_t& label);
175  virtual void get_string_and_label
176  (int32_t*& vector, int32_t& len, float64_t& label);
177  virtual void get_string_and_label
178  (float32_t*& vector, int32_t& len, float64_t& label);
179  virtual void get_string_and_label
180  (float64_t*& vector, int32_t& len, float64_t& label);
181  virtual void get_string_and_label
182  (int16_t*& vector, int32_t& len, float64_t& label);
183  virtual void get_string_and_label
184  (uint16_t*& vector, int32_t& len, float64_t& label);
185  virtual void get_string_and_label
186  (int8_t*& vector, int32_t& len, float64_t& label);
187  virtual void get_string_and_label
188  (uint32_t*& vector, int32_t& len, float64_t& label);
189  virtual void get_string_and_label
190  (int64_t*& vector, int32_t& len, float64_t& label);
191  virtual void get_string_and_label
192  (uint64_t*& vector, int32_t& len, float64_t& label);
193  virtual void get_string_and_label
194  (floatmax_t*& vector, int32_t& len, float64_t& label);
196 
206  virtual void get_sparse_vector
207  (SGSparseVectorEntry<bool>*& vector, int32_t& len);
208  virtual void get_sparse_vector
209  (SGSparseVectorEntry<uint8_t>*& vector, int32_t& len);
210  virtual void get_sparse_vector
211  (SGSparseVectorEntry<char>*& vector, int32_t& len);
212  virtual void get_sparse_vector
213  (SGSparseVectorEntry<int32_t>*& vector, int32_t& len);
214  virtual void get_sparse_vector
215  (SGSparseVectorEntry<float32_t>*& vector, int32_t& len);
216  virtual void get_sparse_vector
217  (SGSparseVectorEntry<float64_t>*& vector, int32_t& len);
218  virtual void get_sparse_vector
219  (SGSparseVectorEntry<int16_t>*& vector, int32_t& len);
220  virtual void get_sparse_vector
221  (SGSparseVectorEntry<uint16_t>*& vector, int32_t& len);
222  virtual void get_sparse_vector
223  (SGSparseVectorEntry<int8_t>*& vector, int32_t& len);
224  virtual void get_sparse_vector
225  (SGSparseVectorEntry<uint32_t>*& vector, int32_t& len);
226  virtual void get_sparse_vector
227  (SGSparseVectorEntry<int64_t>*& vector, int32_t& len);
228  virtual void get_sparse_vector
229  (SGSparseVectorEntry<uint64_t>*& vector, int32_t& len);
230  virtual void get_sparse_vector
231  (SGSparseVectorEntry<floatmax_t>*& vector, int32_t& len);
233 
243  virtual void get_sparse_vector_and_label
244  (SGSparseVectorEntry<bool>*& vector, int32_t& len, float64_t& label);
245  virtual void get_sparse_vector_and_label
246  (SGSparseVectorEntry<uint8_t>*& vector, int32_t& len, float64_t& label);
247  virtual void get_sparse_vector_and_label
248  (SGSparseVectorEntry<char>*& vector, int32_t& len, float64_t& label);
249  virtual void get_sparse_vector_and_label
250  (SGSparseVectorEntry<int32_t>*& vector, int32_t& len, float64_t& label);
251  virtual void get_sparse_vector_and_label
252  (SGSparseVectorEntry<float32_t>*& vector, int32_t& len, float64_t& label);
253  virtual void get_sparse_vector_and_label
254  (SGSparseVectorEntry<float64_t>*& vector, int32_t& len, float64_t& label);
255  virtual void get_sparse_vector_and_label
256  (SGSparseVectorEntry<int16_t>*& vector, int32_t& len, float64_t& label);
257  virtual void get_sparse_vector_and_label
258  (SGSparseVectorEntry<uint16_t>*& vector, int32_t& len, float64_t& label);
259  virtual void get_sparse_vector_and_label
260  (SGSparseVectorEntry<int8_t>*& vector, int32_t& len, float64_t& label);
261  virtual void get_sparse_vector_and_label
262  (SGSparseVectorEntry<uint32_t>*& vector, int32_t& len, float64_t& label);
263  virtual void get_sparse_vector_and_label
264  (SGSparseVectorEntry<int64_t>*& vector, int32_t& len, float64_t& label);
265  virtual void get_sparse_vector_and_label
266  (SGSparseVectorEntry<uint64_t>*& vector, int32_t& len, float64_t& label);
267  virtual void get_sparse_vector_and_label
268  (SGSparseVectorEntry<floatmax_t>*& vector, int32_t& len, float64_t& label);
269 
271 
278  virtual void get_vector(VwExample*& ex, int32_t& len);
279 
287  virtual void get_vector_and_label(VwExample*& ex, int32_t& len, float64_t& label);
288 
290  inline virtual const char* get_name() const { return "StreamingFile"; }
291 
292  protected:
293 
297  char task;
299  char* filename;
300 
301  };
302 }
303 #endif //__STREAMING_FILE_H__

SHOGUN Machine Learning Toolbox - Documentation