SHOGUN  3.2.1
 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/config.h>
20 
21 #include <shogun/lib/v_array.h>
22 #include <shogun/lib/common.h>
23 #include <shogun/base/SGObject.h>
24 
25 #ifndef O_LARGEFILE //for OSX
26 #define O_LARGEFILE 0
27 #endif
28 
29 namespace shogun
30 {
41  class CIOBuffer : public CSGObject
42  {
43 
44  public:
45 
49  CIOBuffer();
50 
56  CIOBuffer(int fd);
57 
61  ~CIOBuffer();
62 
66  void init();
67 
73  virtual void use_file(int fd);
74 
83  virtual int open_file(const char* name, char flag='r');
84 
88  virtual void reset_file();
89 
95  void set(char *p);
96 
105  virtual ssize_t read_file(void* buf, size_t nbytes);
106 
112  size_t fill();
113 
122  virtual ssize_t write_file(const void* buf, size_t nbytes);
123 
127  virtual void flush();
128 
134  virtual bool close_file();
135 
144  ssize_t readto(char* &pointer, char terminal);
145 
153  inline ssize_t read_line(char* &pointer)
154  {
155  return readto(pointer, '\n');
156  }
157 
164  void buf_write(char* &pointer, int n);
165 
174  unsigned int buf_read(char* &pointer, int n);
175 
176  virtual const char* get_name() const
177  {
178  return "IOBuffer";
179  }
180 
181 public:
182 
185  /* space.begin = beginning of loaded values
186  * space.end = end of read or written values */
187 
189  char* endloaded;
190 
193 };
194 }
195 #endif /* IOBUFFER_H__ */

SHOGUN Machine Learning Toolbox - Documentation