SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StreamingAsciiFile.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_ASCIIFILE_H__
11 #define __STREAMING_ASCIIFILE_H__
12 
13 #include <shogun/io/CSVFile.h>
16 
17 namespace shogun
18 {
24 {
25 public:
31 
38  CStreamingAsciiFile(const char* fname, char rw='r');
39 
43  virtual ~CStreamingAsciiFile();
44 
49  void set_delimiter(char delimiter);
50 
58  inline bool str_to_bool(char *str)
59  {
60  return (atoi(str)!=0);
61  }
62 
63 #define GET_VECTOR_DECL(sg_type) \
64  virtual void get_vector \
65  (sg_type*& vector, int32_t& len); \
66  \
67  virtual void get_vector_and_label \
68  (sg_type*& vector, int32_t& len, float64_t& label); \
69  \
70  virtual void get_string \
71  (sg_type*& vector, int32_t& len); \
72  \
73  virtual void get_string_and_label \
74  (sg_type*& vector, int32_t& len, float64_t& label); \
75  \
76  virtual void get_sparse_vector \
77  (SGSparseVectorEntry<sg_type>*& vector, int32_t& len); \
78  \
79  virtual void get_sparse_vector_and_label \
80  (SGSparseVectorEntry<sg_type>*& vector, int32_t& len, float64_t& label);
81 
82  GET_VECTOR_DECL(bool)
83  GET_VECTOR_DECL(uint8_t)
84  GET_VECTOR_DECL(char)
85  GET_VECTOR_DECL(int32_t)
88  GET_VECTOR_DECL(int16_t)
89  GET_VECTOR_DECL(uint16_t)
90  GET_VECTOR_DECL(int8_t)
91  GET_VECTOR_DECL(uint32_t)
92  GET_VECTOR_DECL(int64_t)
93  GET_VECTOR_DECL(uint64_t)
95 #undef GET_VECTOR_DECL
96 
98  virtual const char* get_name() const
99  {
100  return "StreamingAsciiFile";
101 
102  }
103 
104 private:
111  template <class T> void append_item(DynArray<T>* items, char* ptr_data, char* ptr_item);
112 
114  v_array<substring> words;
115 
117  char m_delimiter;
118 };
119 }
120 #endif //__STREAMING_ASCIIFILE_H__

SHOGUN Machine Learning Toolbox - Documentation