Drizzled Public API Documentation

linebuffer.cc
1 /* Copyright (C) 2000 MySQL AB
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 /* readline for batch mode */
17 
18 #include <config.h>
19 #include <drizzled/internal/my_sys.h>
20 #include <client/linebuffer.h>
21 #include <boost/version.hpp>
22 
23 #include <vector>
24 
25 using namespace std;
26 using namespace drizzled;
27 
28 LineBuffer::LineBuffer(uint32_t my_max_size,FILE *my_file)
29  :
30  file(my_file),
31  max_size(my_max_size)
32 {
33  if (my_file)
34 
35  /*
36  if here beacuse the old way of using file_descriptor is deprecated in boost
37  1.44. There is a #define to re-enable the function but this is broken in
38  Fedora 14. See https://bugzilla.redhat.com/show_bug.cgi?id=654480
39  */
40 #if BOOST_VERSION < 104400
41  file_stream = new boost::iostreams::stream<boost::iostreams::file_descriptor>(fileno(my_file), true);
42 #else
43  file_stream = new boost::iostreams::stream<boost::iostreams::file_descriptor>(fileno(my_file), boost::iostreams::never_close_handle);
44 #endif
45  else
46  file_stream = new std::stringstream;
47  line.reserve(max_size);
48 }
49 
50 void LineBuffer::addString(const string &str)
51 {
52  (*file_stream) << str << endl;
53 }
54 
55 char *LineBuffer::readline()
56 {
57  file_stream->getline(&line[0], max_size);
58 
59  if (file_stream->fail())
60  return 0;
61  else
62  return &line[0];
63 }
64