SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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__ */
An I/O buffer class.
Definition: IOBuffer.h:41
int working_file
file descriptor
Definition: IOBuffer.h:192
ssize_t read_line(char *&pointer)
Definition: IOBuffer.h:153
virtual void use_file(int fd)
Definition: IOBuffer.cpp:50
virtual void reset_file()
Definition: IOBuffer.cpp:75
virtual bool close_file()
Definition: IOBuffer.cpp:126
ssize_t readto(char *&pointer, char terminal)
Definition: IOBuffer.cpp:139
v_array< char > space
buffer space
Definition: IOBuffer.h:184
virtual ssize_t write_file(const void *buf, size_t nbytes)
Definition: IOBuffer.cpp:110
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
virtual void flush()
Definition: IOBuffer.cpp:115
virtual int open_file(const char *name, char flag='r')
Definition: IOBuffer.cpp:55
char * endloaded
end of loaded values
Definition: IOBuffer.h:189
virtual ssize_t read_file(void *buf, size_t nbytes)
Definition: IOBuffer.cpp:87
unsigned int buf_read(char *&pointer, int n)
Definition: IOBuffer.cpp:190
void buf_write(char *&pointer, int n)
Definition: IOBuffer.cpp:170
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
void set(char *p)
Definition: IOBuffer.cpp:82
virtual const char * get_name() const
Definition: IOBuffer.h:176

SHOGUN Machine Learning Toolbox - Documentation