Vowpal Wabbit
Functions
io_buf.cc File Reference
#include "io_buf.h"
#include <cstdio>

Go to the source code of this file.

Functions

bool isbinary (io_buf &i)
 
size_t readto (io_buf &i, char *&pointer, char terminal)
 

Function Documentation

◆ isbinary()

bool isbinary ( io_buf i)

Definition at line 45 of file io_buf.cc.

References io_buf::current, v_array< T >::end(), io_buf::files, io_buf::fill(), io_buf::head, and io_buf::space.

Referenced by io_buf::bin_write_fixed(), enable_sources(), and reset_source().

46 {
47  if (i.space.end() == i.head)
48  if (i.fill(i.files[i.current]) <= 0)
49  return false;
50 
51  bool ret = (*i.head == 0);
52  if (ret)
53  i.head++;
54 
55  return ret;
56 }
size_t current
Definition: io_buf.h:66
char * head
Definition: io_buf.h:67
ssize_t fill(int f)
Definition: io_buf.h:171
v_array< int > files
Definition: io_buf.h:64
v_array< char > space
Definition: io_buf.h:62
T *& end()
Definition: v_array.h:43

◆ readto()

size_t readto ( io_buf i,
char *&  pointer,
char  terminal 
)

Definition at line 58 of file io_buf.cc.

References v_array< T >::begin(), io_buf::current, v_array< T >::end(), v_array< T >::end_array, io_buf::files, io_buf::fill(), io_buf::head, readto(), v_array< T >::size(), and io_buf::space.

Referenced by io_buf::bin_write_fixed(), read_features(), and readto().

59 {
60  // Return a pointer to the bytes before the terminal. Must be less than the buffer size.
61  pointer = i.head;
62  while (pointer < i.space.end() && *pointer != terminal) pointer++;
63  if (pointer != i.space.end())
64  {
65  size_t n = pointer - i.head;
66  i.head = pointer + 1;
67  pointer -= n;
68  return n + 1;
69  }
70  else
71  {
72  if (i.space.end() == i.space.end_array)
73  {
74  size_t left = i.space.end() - i.head;
75  memmove(i.space.begin(), i.head, left);
76  i.head = i.space.begin();
77  i.space.end() = i.space.begin() + left;
78  pointer = i.space.end();
79  }
80  if (i.current < i.files.size() && i.fill(i.files[i.current]) > 0) // more bytes are read.
81  return readto(i, pointer, terminal);
82  else if (++i.current < i.files.size()) // no more bytes, so go to next file.
83  return readto(i, pointer, terminal);
84  else // no more bytes to read, return everything we have.
85  {
86  size_t n = pointer - i.head;
87  i.head = pointer;
88  pointer -= n;
89  return n;
90  }
91  }
92 }
size_t current
Definition: io_buf.h:66
T *& begin()
Definition: v_array.h:42
size_t size() const
Definition: v_array.h:68
char * head
Definition: io_buf.h:67
ssize_t fill(int f)
Definition: io_buf.h:171
size_t readto(io_buf &i, char *&pointer, char terminal)
Definition: io_buf.cc:58
v_array< int > files
Definition: io_buf.h:64
v_array< char > space
Definition: io_buf.h:62
T *& end()
Definition: v_array.h:43
T * end_array
Definition: v_array.h:38