00001 /* 00002 Copyright (c) 2009 Yahoo! Inc. All rights reserved. The copyrights 00003 embodied in the content of this file are licensed under the BSD 00004 (revised) open source license. 00005 00006 Copyright (c) 2011 Berlin Institute of Technology and Max-Planck-Society. 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 Shogun adjustments (w) 2011 Shashwat Lal Das 00014 */ 00015 00016 #ifndef IOBUFFER_H__ 00017 #define IOBUFFER_H__ 00018 00019 #include <shogun/lib/v_array.h> 00020 #include <shogun/lib/common.h> 00021 #include <shogun/io/SGIO.h> 00022 #include <shogun/lib/DataType.h> 00023 #include <shogun/base/SGObject.h> 00024 00025 #include <stdio.h> 00026 #include <fcntl.h> 00027 00028 #ifndef O_LARGEFILE //for OSX 00029 #define O_LARGEFILE 0 00030 #endif 00031 00032 namespace shogun 00033 { 00044 class CIOBuffer : public CSGObject 00045 { 00046 00047 public: 00048 00052 CIOBuffer(); 00053 00059 CIOBuffer(int fd); 00060 00064 ~CIOBuffer(); 00065 00069 void init(); 00070 00076 virtual void use_file(int fd); 00077 00086 virtual int open_file(const char* name, char flag='r'); 00087 00091 virtual void reset_file(); 00092 00098 void set(char *p); 00099 00108 virtual ssize_t read_file(void* buf, size_t nbytes); 00109 00115 size_t fill(); 00116 00125 virtual ssize_t write_file(const void* buf, size_t nbytes); 00126 00130 virtual void flush(); 00131 00137 virtual bool close_file(); 00138 00147 ssize_t readto(char* &pointer, char terminal); 00148 00156 inline ssize_t read_line(char* &pointer) 00157 { 00158 return readto(pointer, '\n'); 00159 } 00160 00167 void buf_write(char* &pointer, int n); 00168 00177 unsigned int buf_read(char* &pointer, int n); 00178 00179 virtual const char* get_name() const 00180 { 00181 return "IOBuffer"; 00182 } 00183 00184 public: 00185 00187 v_array<char> space; 00188 /* space.begin = beginning of loaded values 00189 * space.end = end of read or written values */ 00190 00192 char* endloaded; 00193 00195 int working_file; 00196 }; 00197 } 00198 #endif /* IOBUFFER_H__ */