SHOGUN  3.2.1
 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/lib/config.h>
14 
16 #include <shogun/lib/v_array.h>
17 
18 namespace shogun
19 {
20 
21 struct substring;
22 template <class ST> struct SGSparseVectorEntry;
23 template <class T> class DynArray;
24 
30 {
31 
32 public:
38 
45  CStreamingAsciiFile(const char* fname, char rw='r');
46 
50  virtual ~CStreamingAsciiFile();
51 
56  void set_delimiter(char delimiter);
57 
58 #ifndef SWIG // SWIG should skip this
59 
66  inline bool str_to_bool(char *str)
67  {
68  return (atoi(str)!=0);
69  }
70 
71 #define GET_VECTOR_DECL(sg_type) \
72  virtual void get_vector \
73  (sg_type*& vector, int32_t& len); \
74  \
75  virtual void get_vector_and_label \
76  (sg_type*& vector, int32_t& len, float64_t& label); \
77  \
78  virtual void get_string \
79  (sg_type*& vector, int32_t& len); \
80  \
81  virtual void get_string_and_label \
82  (sg_type*& vector, int32_t& len, float64_t& label); \
83  \
84  virtual void get_sparse_vector \
85  (SGSparseVectorEntry<sg_type>*& vector, int32_t& len); \
86  \
87  virtual void get_sparse_vector_and_label \
88  (SGSparseVectorEntry<sg_type>*& vector, int32_t& len, float64_t& label);
89 
90  GET_VECTOR_DECL(bool)
91  GET_VECTOR_DECL(uint8_t)
92  GET_VECTOR_DECL(char)
93  GET_VECTOR_DECL(int32_t)
96  GET_VECTOR_DECL(int16_t)
97  GET_VECTOR_DECL(uint16_t)
98  GET_VECTOR_DECL(int8_t)
99  GET_VECTOR_DECL(uint32_t)
100  GET_VECTOR_DECL(int64_t)
101  GET_VECTOR_DECL(uint64_t)
103 #undef GET_VECTOR_DECL
104 
105 #endif // #ifndef SWIG // SWIG should skip this
106 
108  virtual const char* get_name() const
109  {
110  return "StreamingAsciiFile";
111 
112  }
113 
114 private:
121  template <class T> void append_item(DynArray<T>* items, char* ptr_data, char* ptr_item);
122 
131  void tokenize(char delim, substring s, v_array<substring> &ret);
132 
133 private:
135  v_array<substring> words;
136 
138  char m_delimiter;
139 };
140 }
141 #endif //__STREAMING_ASCIIFILE_H__

SHOGUN Machine Learning Toolbox - Documentation