SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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>
19 #include <shogun/io/IOBuffer.h>
21 
22 #include <ctype.h>
23 #include <fcntl.h>
24 #include <unistd.h>
25 
26 namespace shogun
27 {
38  class CStreamingFile: public CSGObject
39  {
40  public:
43 
49  CStreamingFile(char* fname, char rw='r');
50 
52  virtual ~CStreamingFile();
53 
57  void close()
58  {
59  buf->close_file();
60  }
61 
67  inline virtual bool is_seekable() { return false; }
68 
72  virtual void reset_stream() { SG_ERROR("Unable to reset the input stream!\n"); }
73 
83  virtual void get_vector(bool*& vector, int32_t& len);
84  virtual void get_vector(uint8_t*& vector, int32_t& len);
85  virtual void get_vector(char*& vector, int32_t& len);
86  virtual void get_vector(int32_t*& vector, int32_t& len);
87  virtual void get_vector(float32_t*& vector, int32_t& len);
88  virtual void get_vector(float64_t*& vector, int32_t& len);
89  virtual void get_vector(int16_t*& vector, int32_t& len);
90  virtual void get_vector(uint16_t*& vector, int32_t& len);
91  virtual void get_vector(int8_t*& vector, int32_t& len);
92  virtual void get_vector(uint32_t*& vector, int32_t& len);
93  virtual void get_vector(int64_t*& vector, int32_t& len);
94  virtual void get_vector(uint64_t*& vector, int32_t& len);
95  virtual void get_vector(floatmax_t*& vector, int32_t& len);
97 
107  virtual void get_vector_and_label
108  (bool*& vector, int32_t& len, float64_t& label);
109  virtual void get_vector_and_label
110  (uint8_t*& vector, int32_t& len, float64_t& label);
111  virtual void get_vector_and_label
112  (char*& vector, int32_t& len, float64_t& label);
113  virtual void get_vector_and_label
114  (int32_t*& vector, int32_t& len, float64_t& label);
115  virtual void get_vector_and_label
116  (float32_t*& vector, int32_t& len, float64_t& label);
117  virtual void get_vector_and_label
118  (float64_t*& vector, int32_t& len, float64_t& label);
119  virtual void get_vector_and_label
120  (int16_t*& vector, int32_t& len, float64_t& label);
121  virtual void get_vector_and_label
122  (uint16_t*& vector, int32_t& len, float64_t& label);
123  virtual void get_vector_and_label
124  (int8_t*& vector, int32_t& len, float64_t& label);
125  virtual void get_vector_and_label
126  (uint32_t*& vector, int32_t& len, float64_t& label);
127  virtual void get_vector_and_label
128  (int64_t*& vector, int32_t& len, float64_t& label);
129  virtual void get_vector_and_label
130  (uint64_t*& vector, int32_t& len, float64_t& label);
131  virtual void get_vector_and_label
132  (floatmax_t*& vector, int32_t& len, float64_t& label);
134 
144  virtual void get_string(bool*& vector, int32_t& len);
145  virtual void get_string(uint8_t*& vector, int32_t& len);
146  virtual void get_string(char*& vector, int32_t& len);
147  virtual void get_string(int32_t*& vector, int32_t& len);
148  virtual void get_string(float32_t*& vector, int32_t& len);
149  virtual void get_string(float64_t*& vector, int32_t& len);
150  virtual void get_string(int16_t*& vector, int32_t& len);
151  virtual void get_string(uint16_t*& vector, int32_t& len);
152  virtual void get_string(int8_t*& vector, int32_t& len);
153  virtual void get_string(uint32_t*& vector, int32_t& len);
154  virtual void get_string(int64_t*& vector, int32_t& len);
155  virtual void get_string(uint64_t*& vector, int32_t& len);
156  virtual void get_string(floatmax_t*& vector, int32_t& len);
158 
168  virtual void get_string_and_label
169  (bool*& vector, int32_t& len, float64_t& label);
170  virtual void get_string_and_label
171  (uint8_t*& vector, int32_t& len, float64_t& label);
172  virtual void get_string_and_label
173  (char*& vector, int32_t& len, float64_t& label);
174  virtual void get_string_and_label
175  (int32_t*& vector, int32_t& len, float64_t& label);
176  virtual void get_string_and_label
177  (float32_t*& vector, int32_t& len, float64_t& label);
178  virtual void get_string_and_label
179  (float64_t*& vector, int32_t& len, float64_t& label);
180  virtual void get_string_and_label
181  (int16_t*& vector, int32_t& len, float64_t& label);
182  virtual void get_string_and_label
183  (uint16_t*& vector, int32_t& len, float64_t& label);
184  virtual void get_string_and_label
185  (int8_t*& vector, int32_t& len, float64_t& label);
186  virtual void get_string_and_label
187  (uint32_t*& vector, int32_t& len, float64_t& label);
188  virtual void get_string_and_label
189  (int64_t*& vector, int32_t& len, float64_t& label);
190  virtual void get_string_and_label
191  (uint64_t*& vector, int32_t& len, float64_t& label);
192  virtual void get_string_and_label
193  (floatmax_t*& vector, int32_t& len, float64_t& label);
195 
205  virtual void get_sparse_vector
206  (SGSparseVectorEntry<bool>*& vector, int32_t& len);
207  virtual void get_sparse_vector
208  (SGSparseVectorEntry<uint8_t>*& vector, int32_t& len);
209  virtual void get_sparse_vector
210  (SGSparseVectorEntry<char>*& vector, int32_t& len);
211  virtual void get_sparse_vector
212  (SGSparseVectorEntry<int32_t>*& vector, int32_t& len);
213  virtual void get_sparse_vector
214  (SGSparseVectorEntry<float32_t>*& vector, int32_t& len);
215  virtual void get_sparse_vector
216  (SGSparseVectorEntry<float64_t>*& vector, int32_t& len);
217  virtual void get_sparse_vector
218  (SGSparseVectorEntry<int16_t>*& vector, int32_t& len);
219  virtual void get_sparse_vector
220  (SGSparseVectorEntry<uint16_t>*& vector, int32_t& len);
221  virtual void get_sparse_vector
222  (SGSparseVectorEntry<int8_t>*& vector, int32_t& len);
223  virtual void get_sparse_vector
224  (SGSparseVectorEntry<uint32_t>*& vector, int32_t& len);
225  virtual void get_sparse_vector
226  (SGSparseVectorEntry<int64_t>*& vector, int32_t& len);
227  virtual void get_sparse_vector
228  (SGSparseVectorEntry<uint64_t>*& vector, int32_t& len);
229  virtual void get_sparse_vector
230  (SGSparseVectorEntry<floatmax_t>*& vector, int32_t& len);
232 
242  virtual void get_sparse_vector_and_label
243  (SGSparseVectorEntry<bool>*& vector, int32_t& len, float64_t& label);
244  virtual void get_sparse_vector_and_label
245  (SGSparseVectorEntry<uint8_t>*& vector, int32_t& len, float64_t& label);
246  virtual void get_sparse_vector_and_label
247  (SGSparseVectorEntry<char>*& vector, int32_t& len, float64_t& label);
248  virtual void get_sparse_vector_and_label
249  (SGSparseVectorEntry<int32_t>*& vector, int32_t& len, float64_t& label);
250  virtual void get_sparse_vector_and_label
251  (SGSparseVectorEntry<float32_t>*& vector, int32_t& len, float64_t& label);
252  virtual void get_sparse_vector_and_label
253  (SGSparseVectorEntry<float64_t>*& vector, int32_t& len, float64_t& label);
254  virtual void get_sparse_vector_and_label
255  (SGSparseVectorEntry<int16_t>*& vector, int32_t& len, float64_t& label);
256  virtual void get_sparse_vector_and_label
257  (SGSparseVectorEntry<uint16_t>*& vector, int32_t& len, float64_t& label);
258  virtual void get_sparse_vector_and_label
259  (SGSparseVectorEntry<int8_t>*& vector, int32_t& len, float64_t& label);
260  virtual void get_sparse_vector_and_label
261  (SGSparseVectorEntry<uint32_t>*& vector, int32_t& len, float64_t& label);
262  virtual void get_sparse_vector_and_label
263  (SGSparseVectorEntry<int64_t>*& vector, int32_t& len, float64_t& label);
264  virtual void get_sparse_vector_and_label
265  (SGSparseVectorEntry<uint64_t>*& vector, int32_t& len, float64_t& label);
266  virtual void get_sparse_vector_and_label
267  (SGSparseVectorEntry<floatmax_t>*& vector, int32_t& len, float64_t& label);
268 
270 
277  virtual void get_vector(VwExample*& ex, int32_t& len);
278 
286  virtual void get_vector_and_label(VwExample*& ex, int32_t& len, float64_t& label);
287 
289  inline virtual const char* get_name() const { return "StreamingFile"; }
290 
291  protected:
292 
296  char task;
298  char* filename;
299 
300  };
301 }
302 #endif //__STREAMING_FILE_H__

SHOGUN Machine Learning Toolbox - Documentation