/usr/include/shogun/io/IOBuffer.h is in libshogun-dev 3.2.0-7.3build4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | /*
Copyright (c) 2009 Yahoo! Inc. All rights reserved. The copyrights
embodied in the content of this file are licensed under the BSD
(revised) open source license.
Copyright (c) 2011 Berlin Institute of Technology and Max-Planck-Society.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Shogun adjustments (w) 2011 Shashwat Lal Das
*/
#ifndef IOBUFFER_H__
#define IOBUFFER_H__
#include <shogun/lib/v_array.h>
#include <shogun/lib/common.h>
#include <shogun/io/SGIO.h>
#include <shogun/lib/DataType.h>
#include <shogun/base/SGObject.h>
#include <stdio.h>
#include <fcntl.h>
#ifndef O_LARGEFILE //for OSX
#define O_LARGEFILE 0
#endif
namespace shogun
{
/** @brief An I/O buffer class.
*
* A file is read into buffer space, which is accessed through
* extents; 'space.begin' is the start of the buffer, 'space.end' is the
* address of the last read character.
*
* The buffer grows in size if required, the default size being 64KB.
*
*/
class CIOBuffer : public CSGObject
{
public:
/**
* Constructor.
*/
CIOBuffer();
/**
* Constructor taking file descriptor as parameter
*
* @param fd file descriptor to use
*/
CIOBuffer(int fd);
/**
* Destructor.
*/
~CIOBuffer();
/**
* Initialize the buffer, reserve 64K memory by default.
*/
void init();
/**
* Uses the passed file descriptor
*
* @param fd file descriptor to use
*/
virtual void use_file(int fd);
/**
* Open a file, in read or write mode.
*
* @param name File name.
* @param flag 'r' or 'w'
*
* @return 1 on success, 0 on error.
*/
virtual int open_file(const char* name, char flag='r');
/**
* Seek back to zero, reset the buffer markers.
*/
virtual void reset_file();
/**
* Set the buffer marker to a position.
*
* @param p Character pointer to which the end of buffer space is assigned.
*/
void set(char *p);
/**
* Read some bytes from the file into memory.
*
* @param buf void* buffer into which to read.
* @param nbytes number of bytes to read
*
* @return Number of bytes read successfully.
*/
virtual ssize_t read_file(void* buf, size_t nbytes);
/**
* Fill the buffer by reading as many bytes from the file as required.
*
* @return Number of bytes read.
*/
size_t fill();
/**
* Write to the file from memory.
*
* @param buf void* buffer from which to write.
* @param nbytes Number of bytes to write.
*
* @return Number of bytes successfully written.
*/
virtual ssize_t write_file(const void* buf, size_t nbytes);
/**
* Flush the stream; commit all operations to file.
*/
virtual void flush();
/**
* Close the file.
*
* @return true on success, false otherwise.
*/
virtual bool close_file();
/**
* Reads upto a terminal character from the buffer.
*
* @param pointer Start of the string in the buffer, set by reference.
* @param terminal Terminal character upto which to read.
*
* @return Number of characters read.
*/
ssize_t readto(char* &pointer, char terminal);
/**
* Reads upto a newline character from the buffer.
*
* @param pointer Start of the string, set by reference
*
* @return Number of characters read.
*/
inline ssize_t read_line(char* &pointer)
{
return readto(pointer, '\n');
}
/**
* Return a pointer to the next n bytes to write into
*
* @param pointer returned pointer
* @param n number of bytes to write
*/
void buf_write(char* &pointer, int n);
/**
* Return a pointer to position in buffer after reading n bytes
*
* @param pointer returned pointer
* @param n bytes to read
*
* @return bytes read
*/
unsigned int buf_read(char* &pointer, int n);
virtual const char* get_name() const
{
return "IOBuffer";
}
public:
/// buffer space
v_array<char> space;
/* space.begin = beginning of loaded values
* space.end = end of read or written values */
/// end of loaded values
char* endloaded;
/// file descriptor
int working_file;
};
}
#endif /* IOBUFFER_H__ */
|