SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IOBuffer.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2009 Yahoo! Inc. All rights reserved. The copyrights
3  embodied in the content of this file are licensed under the BSD
4  (revised) open source license.
5 
6  Copyright (c) 2011 Berlin Institute of Technology and Max-Planck-Society.
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  Shogun adjustments (w) 2011 Shashwat Lal Das
14 */
15 
16 #ifndef IOBUFFER_H__
17 #define IOBUFFER_H__
18 
19 #include <shogun/lib/v_array.h>
20 #include <shogun/lib/common.h>
21 #include <shogun/io/SGIO.h>
22 #include <shogun/lib/DataType.h>
23 #include <shogun/base/SGObject.h>
24 
25 #include <stdio.h>
26 #include <fcntl.h>
27 
28 #ifndef O_LARGEFILE //for OSX
29 #define O_LARGEFILE 0
30 #endif
31 
32 namespace shogun
33 {
44  class CIOBuffer : public CSGObject
45  {
46 
47  public:
48 
52  CIOBuffer();
53 
59  CIOBuffer(int fd);
60 
64  ~CIOBuffer();
65 
69  void init();
70 
76  virtual void use_file(int fd);
77 
86  virtual int open_file(const char* name, char flag='r');
87 
91  virtual void reset_file();
92 
98  void set(char *p);
99 
108  virtual ssize_t read_file(void* buf, size_t nbytes);
109 
115  size_t fill();
116 
125  virtual ssize_t write_file(const void* buf, size_t nbytes);
126 
130  virtual void flush();
131 
137  virtual bool close_file();
138 
147  ssize_t readto(char* &pointer, char terminal);
148 
156  inline ssize_t read_line(char* &pointer)
157  {
158  return readto(pointer, '\n');
159  }
160 
167  void buf_write(char* &pointer, int n);
168 
177  unsigned int buf_read(char* &pointer, int n);
178 
179  virtual const char* get_name() const
180  {
181  return "IOBuffer";
182  }
183 
184 public:
185 
188  /* space.begin = beginning of loaded values
189  * space.end = end of read or written values */
190 
192  char* endloaded;
193 
196 };
197 }
198 #endif /* IOBUFFER_H__ */

SHOGUN Machine Learning Toolbox - Documentation