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 
65  inline bool str_to_bool(char *str)
66  {
67  return (atoi(str)!=0);
68  }
69 
70 #define GET_VECTOR_DECL(sg_type) \
71  virtual void get_vector \
72  (sg_type*& vector, int32_t& len); \
73  \
74  virtual void get_vector_and_label \
75  (sg_type*& vector, int32_t& len, float64_t& label); \
76  \
77  virtual void get_string \
78  (sg_type*& vector, int32_t& len); \
79  \
80  virtual void get_string_and_label \
81  (sg_type*& vector, int32_t& len, float64_t& label); \
82  \
83  virtual void get_sparse_vector \
84  (SGSparseVectorEntry<sg_type>*& vector, int32_t& len); \
85  \
86  virtual void get_sparse_vector_and_label \
87  (SGSparseVectorEntry<sg_type>*& vector, int32_t& len, float64_t& label);
88 
89  GET_VECTOR_DECL(bool)
90  GET_VECTOR_DECL(uint8_t)
91  GET_VECTOR_DECL(char)
92  GET_VECTOR_DECL(int32_t)
95  GET_VECTOR_DECL(int16_t)
96  GET_VECTOR_DECL(uint16_t)
97  GET_VECTOR_DECL(int8_t)
98  GET_VECTOR_DECL(uint32_t)
99  GET_VECTOR_DECL(int64_t)
100  GET_VECTOR_DECL(uint64_t)
102 #undef GET_VECTOR_DECL
103 
105  virtual const char* get_name() const
106  {
107  return "StreamingAsciiFile";
108 
109  }
110 
111 private:
118  template <class T> void append_item(DynArray<T>* items, char* ptr_data, char* ptr_item);
119 
121  v_array<substring> words;
122 
124  char m_delimiter;
125 };
126 }
127 #endif //__STREAMING_ASCIIFILE_H__

SHOGUN Machine Learning Toolbox - Documentation