SHOGUN  v2.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/AsciiFile.h>
16 
17 namespace shogun
18 {
24 {
25 public:
31 
38  CStreamingAsciiFile(const char* fname, char rw='r');
39 
43  virtual ~CStreamingAsciiFile();
44 
52  inline bool str_to_bool(char *str)
53  {
54  return (atoi(str)!=0);
55  }
56 
57 #define GET_VECTOR_DECL(sg_type) \
58  virtual void get_vector \
59  (sg_type*& vector, int32_t& len); \
60  \
61  virtual void get_vector_and_label \
62  (sg_type*& vector, int32_t& len, float64_t& label); \
63  \
64  virtual void get_string \
65  (sg_type*& vector, int32_t& len); \
66  \
67  virtual void get_string_and_label \
68  (sg_type*& vector, int32_t& len, float64_t& label); \
69  \
70  virtual void get_sparse_vector \
71  (SGSparseVectorEntry<sg_type>*& vector, int32_t& len); \
72  \
73  virtual void get_sparse_vector_and_label \
74  (SGSparseVectorEntry<sg_type>*& vector, int32_t& len, float64_t& label);
75 
76  GET_VECTOR_DECL(bool)
77  GET_VECTOR_DECL(uint8_t)
78  GET_VECTOR_DECL(char)
79  GET_VECTOR_DECL(int32_t)
82  GET_VECTOR_DECL(int16_t)
83  GET_VECTOR_DECL(uint16_t)
84  GET_VECTOR_DECL(int8_t)
85  GET_VECTOR_DECL(uint32_t)
86  GET_VECTOR_DECL(int64_t)
87  GET_VECTOR_DECL(uint64_t)
89 #undef GET_VECTOR_DECL
90 
92  inline virtual const char* get_name() const
93  {
94  return "StreamingAsciiFile";
95 
96  }
97 
98 private:
105  template <class T> void append_item(DynArray<T>* items, char* ptr_data, char* ptr_item);
106 
108  v_array<substring> words;
109 };
110 }
111 #endif //__STREAMING_ASCIIFILE_H__

SHOGUN Machine Learning Toolbox - Documentation