Drizzled Public API Documentation

linebuffer.cc
00001 /* Copyright (C) 2000 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 /* readline for batch mode */
00017 
00018 #include <config.h>
00019 #include <drizzled/internal/my_sys.h>
00020 #include <client/linebuffer.h>
00021 #include <boost/version.hpp>
00022 
00023 #include <vector>
00024 
00025 using namespace std;
00026 using namespace drizzled;
00027 
00028 LineBuffer::LineBuffer(uint32_t my_max_size,FILE *my_file)
00029   :
00030     file(my_file),
00031     max_size(my_max_size)
00032 {
00033   if (my_file)
00034 
00035   /*
00036     if here beacuse the old way of using file_descriptor is deprecated in boost
00037     1.44.  There is a #define to re-enable the function but this is broken in
00038     Fedora 14. See https://bugzilla.redhat.com/show_bug.cgi?id=654480
00039   */
00040 #if BOOST_VERSION < 104400
00041     file_stream = new boost::iostreams::stream<boost::iostreams::file_descriptor>(fileno(my_file), true);
00042 #else
00043     file_stream = new boost::iostreams::stream<boost::iostreams::file_descriptor>(fileno(my_file), boost::iostreams::never_close_handle);
00044 #endif
00045   else
00046     file_stream = new std::stringstream;
00047   line.reserve(max_size);
00048 }
00049 
00050 void LineBuffer::addString(const string &str)
00051 {
00052   (*file_stream) << str << endl;
00053 }
00054 
00055 char *LineBuffer::readline()
00056 {
00057   file_stream->getline(&line[0], max_size);
00058 
00059   if (file_stream->fail())
00060     return 0;
00061   else
00062     return &line[0];
00063 }
00064