~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/linebuffer.cc

  • Committer: Robert Klahn
  • Date: 2009-07-20 00:15:20 UTC
  • mto: (1093.1.23 captain)
  • mto: This revision was merged to the branch mainline in revision 1099.
  • Revision ID: rklahn@quad-20090720001520-n4ry8q2hffvl3ifh
changes from code review feedback

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include <mysys/my_sys.h>
20
20
#include "client/linebuffer.h"
21
21
 
22
 
#include <stdexcept>
 
22
#include <vector>
23
23
 
24
24
using namespace std;
25
25
 
26
26
LineBuffer::LineBuffer(uint32_t my_max_size,FILE *my_file)
27
 
{
28
 
  file= my_file;
29
 
  max_size= my_max_size;
30
 
  line= new char[max_size];
31
 
  eof= false;
32
 
}
33
 
 
34
 
LineBuffer::~LineBuffer()
35
 
{
36
 
  delete line;
37
 
}
38
 
 
39
 
void LineBuffer::add_string(const char *str)
 
27
  :
 
28
    file(my_file),
 
29
    line(),
 
30
    max_size(my_max_size),
 
31
    eof(false)
 
32
{
 
33
  line.reserve(max_size);
 
34
}
 
35
 
 
36
void LineBuffer::addString(const string &str)
40
37
{
41
38
  buffer << str << endl;
42
39
}
47
44
 
48
45
  if (file && !eof)
49
46
  {
50
 
    if ((read_count=my_read(fileno(file),(unsigned char *) line,max_size-1,MYF(MY_WME))))
 
47
    if ((read_count=my_read(fileno(file),
 
48
                            (unsigned char *) (&line[0]),
 
49
                            max_size-1,MYF(MY_WME))))
51
50
    {
52
 
      line[read_count+1]= 0;
53
 
      buffer << line;
 
51
      line[read_count+1]= '\0';
 
52
      buffer << &line[0];
54
53
    }
55
54
    else
56
55
      eof= true;
57
56
  }
58
57
 
59
 
  buffer.getline(line,max_size);
 
58
  buffer.getline(&line[0],max_size);
60
59
 
61
60
  if (buffer.eof())
62
61
    return 0;
63
62
  else
64
 
    return line;
 
63
    return &line[0];
65
64
}
66
65