SHOGUN
v1.1.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2011 Shashwat Lal Das 00008 * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society 00009 */ 00010 #ifndef __STREAMING_FILE_H__ 00011 #define __STREAMING_FILE_H__ 00012 00013 #include <shogun/lib/config.h> 00014 #include <shogun/base/DynArray.h> 00015 #include <shogun/lib/common.h> 00016 #include <shogun/io/File.h> 00017 #include <shogun/io/SGIO.h> 00018 #include <shogun/lib/DataType.h> 00019 #include <shogun/io/IOBuffer.h> 00020 #include <shogun/classifier/vw/vw_common.h> 00021 00022 #include <ctype.h> 00023 #include <fcntl.h> 00024 #include <unistd.h> 00025 00026 namespace shogun 00027 { 00038 class CStreamingFile: public CSGObject 00039 { 00040 public: 00042 CStreamingFile(); 00043 00049 CStreamingFile(char* fname, char rw='r'); 00050 00052 virtual ~CStreamingFile(); 00053 00057 void close() 00058 { 00059 buf->close_file(); 00060 } 00061 00067 inline virtual bool is_seekable() { return false; } 00068 00072 virtual void reset_stream() { SG_ERROR("Unable to reset the input stream!\n"); } 00073 00083 virtual void get_vector(bool*& vector, int32_t& len); 00084 virtual void get_vector(uint8_t*& vector, int32_t& len); 00085 virtual void get_vector(char*& vector, int32_t& len); 00086 virtual void get_vector(int32_t*& vector, int32_t& len); 00087 virtual void get_vector(float32_t*& vector, int32_t& len); 00088 virtual void get_vector(float64_t*& vector, int32_t& len); 00089 virtual void get_vector(int16_t*& vector, int32_t& len); 00090 virtual void get_vector(uint16_t*& vector, int32_t& len); 00091 virtual void get_vector(int8_t*& vector, int32_t& len); 00092 virtual void get_vector(uint32_t*& vector, int32_t& len); 00093 virtual void get_vector(int64_t*& vector, int32_t& len); 00094 virtual void get_vector(uint64_t*& vector, int32_t& len); 00095 virtual void get_vector(floatmax_t*& vector, int32_t& len); 00097 00107 virtual void get_vector_and_label 00108 (bool*& vector, int32_t& len, float64_t& label); 00109 virtual void get_vector_and_label 00110 (uint8_t*& vector, int32_t& len, float64_t& label); 00111 virtual void get_vector_and_label 00112 (char*& vector, int32_t& len, float64_t& label); 00113 virtual void get_vector_and_label 00114 (int32_t*& vector, int32_t& len, float64_t& label); 00115 virtual void get_vector_and_label 00116 (float32_t*& vector, int32_t& len, float64_t& label); 00117 virtual void get_vector_and_label 00118 (float64_t*& vector, int32_t& len, float64_t& label); 00119 virtual void get_vector_and_label 00120 (int16_t*& vector, int32_t& len, float64_t& label); 00121 virtual void get_vector_and_label 00122 (uint16_t*& vector, int32_t& len, float64_t& label); 00123 virtual void get_vector_and_label 00124 (int8_t*& vector, int32_t& len, float64_t& label); 00125 virtual void get_vector_and_label 00126 (uint32_t*& vector, int32_t& len, float64_t& label); 00127 virtual void get_vector_and_label 00128 (int64_t*& vector, int32_t& len, float64_t& label); 00129 virtual void get_vector_and_label 00130 (uint64_t*& vector, int32_t& len, float64_t& label); 00131 virtual void get_vector_and_label 00132 (floatmax_t*& vector, int32_t& len, float64_t& label); 00134 00144 virtual void get_string(bool*& vector, int32_t& len); 00145 virtual void get_string(uint8_t*& vector, int32_t& len); 00146 virtual void get_string(char*& vector, int32_t& len); 00147 virtual void get_string(int32_t*& vector, int32_t& len); 00148 virtual void get_string(float32_t*& vector, int32_t& len); 00149 virtual void get_string(float64_t*& vector, int32_t& len); 00150 virtual void get_string(int16_t*& vector, int32_t& len); 00151 virtual void get_string(uint16_t*& vector, int32_t& len); 00152 virtual void get_string(int8_t*& vector, int32_t& len); 00153 virtual void get_string(uint32_t*& vector, int32_t& len); 00154 virtual void get_string(int64_t*& vector, int32_t& len); 00155 virtual void get_string(uint64_t*& vector, int32_t& len); 00156 virtual void get_string(floatmax_t*& vector, int32_t& len); 00158 00168 virtual void get_string_and_label 00169 (bool*& vector, int32_t& len, float64_t& label); 00170 virtual void get_string_and_label 00171 (uint8_t*& vector, int32_t& len, float64_t& label); 00172 virtual void get_string_and_label 00173 (char*& vector, int32_t& len, float64_t& label); 00174 virtual void get_string_and_label 00175 (int32_t*& vector, int32_t& len, float64_t& label); 00176 virtual void get_string_and_label 00177 (float32_t*& vector, int32_t& len, float64_t& label); 00178 virtual void get_string_and_label 00179 (float64_t*& vector, int32_t& len, float64_t& label); 00180 virtual void get_string_and_label 00181 (int16_t*& vector, int32_t& len, float64_t& label); 00182 virtual void get_string_and_label 00183 (uint16_t*& vector, int32_t& len, float64_t& label); 00184 virtual void get_string_and_label 00185 (int8_t*& vector, int32_t& len, float64_t& label); 00186 virtual void get_string_and_label 00187 (uint32_t*& vector, int32_t& len, float64_t& label); 00188 virtual void get_string_and_label 00189 (int64_t*& vector, int32_t& len, float64_t& label); 00190 virtual void get_string_and_label 00191 (uint64_t*& vector, int32_t& len, float64_t& label); 00192 virtual void get_string_and_label 00193 (floatmax_t*& vector, int32_t& len, float64_t& label); 00195 00205 virtual void get_sparse_vector 00206 (SGSparseVectorEntry<bool>*& vector, int32_t& len); 00207 virtual void get_sparse_vector 00208 (SGSparseVectorEntry<uint8_t>*& vector, int32_t& len); 00209 virtual void get_sparse_vector 00210 (SGSparseVectorEntry<char>*& vector, int32_t& len); 00211 virtual void get_sparse_vector 00212 (SGSparseVectorEntry<int32_t>*& vector, int32_t& len); 00213 virtual void get_sparse_vector 00214 (SGSparseVectorEntry<float32_t>*& vector, int32_t& len); 00215 virtual void get_sparse_vector 00216 (SGSparseVectorEntry<float64_t>*& vector, int32_t& len); 00217 virtual void get_sparse_vector 00218 (SGSparseVectorEntry<int16_t>*& vector, int32_t& len); 00219 virtual void get_sparse_vector 00220 (SGSparseVectorEntry<uint16_t>*& vector, int32_t& len); 00221 virtual void get_sparse_vector 00222 (SGSparseVectorEntry<int8_t>*& vector, int32_t& len); 00223 virtual void get_sparse_vector 00224 (SGSparseVectorEntry<uint32_t>*& vector, int32_t& len); 00225 virtual void get_sparse_vector 00226 (SGSparseVectorEntry<int64_t>*& vector, int32_t& len); 00227 virtual void get_sparse_vector 00228 (SGSparseVectorEntry<uint64_t>*& vector, int32_t& len); 00229 virtual void get_sparse_vector 00230 (SGSparseVectorEntry<floatmax_t>*& vector, int32_t& len); 00232 00242 virtual void get_sparse_vector_and_label 00243 (SGSparseVectorEntry<bool>*& vector, int32_t& len, float64_t& label); 00244 virtual void get_sparse_vector_and_label 00245 (SGSparseVectorEntry<uint8_t>*& vector, int32_t& len, float64_t& label); 00246 virtual void get_sparse_vector_and_label 00247 (SGSparseVectorEntry<char>*& vector, int32_t& len, float64_t& label); 00248 virtual void get_sparse_vector_and_label 00249 (SGSparseVectorEntry<int32_t>*& vector, int32_t& len, float64_t& label); 00250 virtual void get_sparse_vector_and_label 00251 (SGSparseVectorEntry<float32_t>*& vector, int32_t& len, float64_t& label); 00252 virtual void get_sparse_vector_and_label 00253 (SGSparseVectorEntry<float64_t>*& vector, int32_t& len, float64_t& label); 00254 virtual void get_sparse_vector_and_label 00255 (SGSparseVectorEntry<int16_t>*& vector, int32_t& len, float64_t& label); 00256 virtual void get_sparse_vector_and_label 00257 (SGSparseVectorEntry<uint16_t>*& vector, int32_t& len, float64_t& label); 00258 virtual void get_sparse_vector_and_label 00259 (SGSparseVectorEntry<int8_t>*& vector, int32_t& len, float64_t& label); 00260 virtual void get_sparse_vector_and_label 00261 (SGSparseVectorEntry<uint32_t>*& vector, int32_t& len, float64_t& label); 00262 virtual void get_sparse_vector_and_label 00263 (SGSparseVectorEntry<int64_t>*& vector, int32_t& len, float64_t& label); 00264 virtual void get_sparse_vector_and_label 00265 (SGSparseVectorEntry<uint64_t>*& vector, int32_t& len, float64_t& label); 00266 virtual void get_sparse_vector_and_label 00267 (SGSparseVectorEntry<floatmax_t>*& vector, int32_t& len, float64_t& label); 00268 00270 00277 virtual void get_vector(VwExample*& ex, int32_t& len); 00278 00286 virtual void get_vector_and_label(VwExample*& ex, int32_t& len, float64_t& label); 00287 00289 inline virtual const char* get_name() const { return "StreamingFile"; } 00290 00291 protected: 00292 00294 CIOBuffer* buf; 00296 char task; 00298 char* filename; 00299 00300 }; 00301 } 00302 #endif //__STREAMING_FILE_H__