SHOGUN
v3.2.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_ASCIIFILE_H__ 00011 #define __STREAMING_ASCIIFILE_H__ 00012 00013 #include <shogun/io/CSVFile.h> 00014 #include <shogun/io/streaming/StreamingFile.h> 00015 #include <shogun/features/SparseFeatures.h> 00016 00017 namespace shogun 00018 { 00023 class CStreamingAsciiFile: public CStreamingFile 00024 { 00025 public: 00030 CStreamingAsciiFile(); 00031 00038 CStreamingAsciiFile(const char* fname, char rw='r'); 00039 00043 virtual ~CStreamingAsciiFile(); 00044 00049 void set_delimiter(char delimiter); 00050 00058 inline bool str_to_bool(char *str) 00059 { 00060 return (atoi(str)!=0); 00061 } 00062 00063 #define GET_VECTOR_DECL(sg_type) \ 00064 virtual void get_vector \ 00065 (sg_type*& vector, int32_t& len); \ 00066 \ 00067 virtual void get_vector_and_label \ 00068 (sg_type*& vector, int32_t& len, float64_t& label); \ 00069 \ 00070 virtual void get_string \ 00071 (sg_type*& vector, int32_t& len); \ 00072 \ 00073 virtual void get_string_and_label \ 00074 (sg_type*& vector, int32_t& len, float64_t& label); \ 00075 \ 00076 virtual void get_sparse_vector \ 00077 (SGSparseVectorEntry<sg_type>*& vector, int32_t& len); \ 00078 \ 00079 virtual void get_sparse_vector_and_label \ 00080 (SGSparseVectorEntry<sg_type>*& vector, int32_t& len, float64_t& label); 00081 00082 GET_VECTOR_DECL(bool) 00083 GET_VECTOR_DECL(uint8_t) 00084 GET_VECTOR_DECL(char) 00085 GET_VECTOR_DECL(int32_t) 00086 GET_VECTOR_DECL(float32_t) 00087 GET_VECTOR_DECL(float64_t) 00088 GET_VECTOR_DECL(int16_t) 00089 GET_VECTOR_DECL(uint16_t) 00090 GET_VECTOR_DECL(int8_t) 00091 GET_VECTOR_DECL(uint32_t) 00092 GET_VECTOR_DECL(int64_t) 00093 GET_VECTOR_DECL(uint64_t) 00094 GET_VECTOR_DECL(floatmax_t) 00095 #undef GET_VECTOR_DECL 00096 00098 virtual const char* get_name() const 00099 { 00100 return "StreamingAsciiFile"; 00101 00102 } 00103 00104 private: 00111 template <class T> void append_item(DynArray<T>* items, char* ptr_data, char* ptr_item); 00112 00114 v_array<substring> words; 00115 00117 char m_delimiter; 00118 }; 00119 } 00120 #endif //__STREAMING_ASCIIFILE_H__